diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-12 22:43:32 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-12 22:43:32 +0100 |
commit | 3e94ecb3dac5003a3d58210ed1a4d1f1cb2083d1 (patch) | |
tree | 67c3e1c122652ae09e58e7de49db668e252c4730 /src/crepe/Asset.cpp | |
parent | f2509e89c02894ebd3ad992324eb300103621d26 (diff) |
add script unit tests + major refactoring
Diffstat (limited to 'src/crepe/Asset.cpp')
-rw-r--r-- | src/crepe/Asset.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/crepe/Asset.cpp b/src/crepe/Asset.cpp index 8a2a11c..3d4df53 100644 --- a/src/crepe/Asset.cpp +++ b/src/crepe/Asset.cpp @@ -1,16 +1,20 @@ #include <filesystem> #include "Asset.h" +#include "Exception.h" using namespace crepe; +using namespace std; -Asset::Asset(const std::string & src) { - // FIXME: restore this - // this->src = std::filesystem::canonical(src); - this->src = src; - this->file = std::ifstream(this->src, std::ios::in | std::ios::binary); +Asset::Asset(const string & src) : src(src) { + try { + this->src = filesystem::canonical(src); + } catch (filesystem::filesystem_error & e) { + throw Exception("Asset error: %s", e.what()); + } + this->file = ifstream(this->src, ios::in | ios::binary); } -const std::istream & Asset::read() { return this->file; } +const istream & Asset::read() { return this->file; } -const char * Asset::canonical() { return this->src.c_str(); } +const char * Asset::canonical() const { return this->src.c_str(); } |