From 23e68dc785d274327efeecb22cfc712c71cfbfc0 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 7 May 2022 18:08:43 +0800 Subject: ... --- src/common/io/Resource.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/common') 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 #elif defined(CRU_PLATFORM_WINDOWS) +#include #endif +#include + 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 -- cgit v1.2.3 From cb850a6d6d13fc5b2c0cdd8773e368e23252c459 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 7 May 2022 19:50:58 +0800 Subject: ... --- src/common/String.cpp | 7 ++++--- src/platform/Color.cpp | 3 ++- src/ui/render/ScrollBar.cpp | 1 - src/ui/style/StyleRuleSet.cpp | 1 - src/win/gui/TimerManager.cpp | 1 - 5 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/common') diff --git a/src/common/String.cpp b/src/common/String.cpp index bb31b987..cac807b0 100644 --- a/src/common/String.cpp +++ b/src/common/String.cpp @@ -1,14 +1,15 @@ #include "cru/common/String.h" -#include -#include + #include "cru/common/Exception.h" #include "cru/common/StringToNumberConverter.h" #include "cru/common/StringUtil.h" -#include +#include +#include #include #include +#include #include #include #include diff --git a/src/platform/Color.cpp b/src/platform/Color.cpp index dd1736ca..81709c6f 100644 --- a/src/platform/Color.cpp +++ b/src/platform/Color.cpp @@ -1,9 +1,10 @@ #include "cru/platform/Color.h" +#include + #include #include #include -#include #include #include #include diff --git a/src/ui/render/ScrollBar.cpp b/src/ui/render/ScrollBar.cpp index 710ca832..bcef74a2 100644 --- a/src/ui/render/ScrollBar.cpp +++ b/src/ui/render/ScrollBar.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ui/style/StyleRuleSet.cpp b/src/ui/style/StyleRuleSet.cpp index 74aba5b1..4deaaefa 100644 --- a/src/ui/style/StyleRuleSet.cpp +++ b/src/ui/style/StyleRuleSet.cpp @@ -2,7 +2,6 @@ #include "cru/common/Event.h" #include "cru/ui/controls/Control.h" #include "cru/ui/model/IListChangeNotify.h" -#include "gsl/gsl_assert" #include diff --git a/src/win/gui/TimerManager.cpp b/src/win/gui/TimerManager.cpp index ce8fead6..a09ee0bf 100644 --- a/src/win/gui/TimerManager.cpp +++ b/src/win/gui/TimerManager.cpp @@ -2,7 +2,6 @@ #include "cru/win/gui/Base.h" #include "cru/win/gui/Exception.h" -#include "gsl/gsl_util" #include #include -- cgit v1.2.3