aboutsummaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/io/Resource.cpp22
-rw-r--r--src/base/platform/unix/EventLoop.cpp6
2 files changed, 19 insertions, 9 deletions
diff --git a/src/base/io/Resource.cpp b/src/base/io/Resource.cpp
index d369b5f5..e599f8a9 100644
--- a/src/base/io/Resource.cpp
+++ b/src/base/io/Resource.cpp
@@ -1,19 +1,20 @@
#include "cru/base/io/Resource.h"
+#include "cru/base/Base.h"
#include "cru/base/Exception.h"
-#include "cru/base/log/Logger.h"
#if defined(CRU_PLATFORM_OSX)
#include <CoreFoundation/CoreFoundation.h>
#elif defined(CRU_PLATFORM_WINDOWS)
#include <Windows.h>
+#elif defined(__linux)
+#include <fstream>
+#include <sstream>
#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);
@@ -26,10 +27,18 @@ std::filesystem::path GetResourceDir() {
CFRelease(cf_string_ref);
return bundle_path / "Contents/Resources";
-#elif defined(CRU_PLATFORM_WINDOWS)
+#elif defined(_WIN32) || defined(__linux)
+#if defined(_WIN32)
wchar_t buffer[MAX_PATH];
DWORD size = ::GetModuleFileNameW(nullptr, buffer, MAX_PATH);
std::filesystem::path module_path(buffer, buffer + size);
+#else // linux
+ std::ifstream file("/proc/self/cmdline");
+ std::stringstream buffer;
+ buffer << file.rdbuf();
+ auto str = buffer.str();
+ std::filesystem::path module_path(str.substr(0, str.find('\0')));
+#endif
auto p = module_path;
while (p.has_parent_path()) {
p = p.parent_path();
@@ -41,8 +50,9 @@ std::filesystem::path GetResourceDir() {
}
throw Exception(u"Failed to find resource directory.");
-#else
- throw Exception(u"Not implemented.");
+
#endif
+
+ NotImplemented();
}
} // namespace cru::io
diff --git a/src/base/platform/unix/EventLoop.cpp b/src/base/platform/unix/EventLoop.cpp
index 7c475697..6e8dc16e 100644
--- a/src/base/platform/unix/EventLoop.cpp
+++ b/src/base/platform/unix/EventLoop.cpp
@@ -34,15 +34,15 @@ int UnixEventLoop::Run() {
while (!exit_code_) {
int poll_timeout = -1;
- while (CheckPoll()) {
+ if (CheckPoll()) {
continue;
}
- while (CheckTimer()) {
+ if (CheckTimer()) {
continue;
}
- while (CheckActionPipe()) {
+ if (CheckActionPipe()) {
continue;
}