diff options
author | crupest <crupest@outlook.com> | 2022-05-07 20:53:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-07 20:53:57 +0800 |
commit | ee5aa17e44cb36b386e89032cab96caf87b5b524 (patch) | |
tree | a7cef6c60f55e3870900016e0f1a4efe578efbf0 /src/common/io/Resource.cpp | |
parent | 5bc684dcc1d121bf6e02d0800174c7977c72d101 (diff) | |
parent | cb850a6d6d13fc5b2c0cdd8773e368e23252c459 (diff) | |
download | cru-ee5aa17e44cb36b386e89032cab96caf87b5b524.tar.gz cru-ee5aa17e44cb36b386e89032cab96caf87b5b524.tar.bz2 cru-ee5aa17e44cb36b386e89032cab96caf87b5b524.zip |
Merge pull request #54 from crupest/create-image
Diffstat (limited to 'src/common/io/Resource.cpp')
-rw-r--r-- | src/common/io/Resource.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/common/io/Resource.cpp b/src/common/io/Resource.cpp index 0ee7f753..b847e1cf 100644 --- a/src/common/io/Resource.cpp +++ b/src/common/io/Resource.cpp @@ -1,13 +1,19 @@ #include "cru/common/io/Resource.h" #include "cru/common/Exception.h" +#include "cru/common/log/Logger.h" #if defined(CRU_PLATFORM_OSX) #include <CoreFoundation/CoreFoundation.h> #elif defined(CRU_PLATFORM_WINDOWS) +#include <Windows.h> #endif +#include <filesystem> + namespace cru::io { std::filesystem::path GetResourceDir() { + constexpr auto kLogTag = u"GetResourceDir"; + #if defined(CRU_PLATFORM_OSX) CFBundleRef main_bundle = CFBundleGetMainBundle(); CFURLRef bundle_url = CFBundleCopyBundleURL(main_bundle); @@ -21,7 +27,20 @@ std::filesystem::path GetResourceDir() { return bundle_path / "Contents/Resources"; #elif defined(CRU_PLATFORM_WINDOWS) - throw Exception(u"Not implemented."); + wchar_t buffer[MAX_PATH]; + DWORD size = ::GetModuleFileNameW(nullptr, buffer, MAX_PATH); + std::filesystem::path module_path(buffer, buffer + size); + auto p = module_path; + while (p.has_parent_path()) { + p = p.parent_path(); + auto resource_dir_path = p / "assets"; + if (std::filesystem::exists(resource_dir_path) && + std::filesystem::is_directory(resource_dir_path)) { + return resource_dir_path; + } + } + + throw Exception(u"Failed to find resource directory."); #else throw Exception(u"Not implemented."); #endif |