summaryrefslogtreecommitdiffhomepage
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/loader-impl.cpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/main/loader-impl.cpp b/main/loader-impl.cpp
index bbf077e1..aeefd081 100644
--- a/main/loader-impl.cpp
+++ b/main/loader-impl.cpp
@@ -18,19 +18,6 @@
namespace Magnum::Examples {
-static void set_application_working_directory()
-{
- static bool once = false;
- if (once)
- return;
- once = true;
- const auto location = *Utility::Path::executableLocation();
- if (const auto dir = Utility::Path::split(location).first(); !dir.isEmpty()) {
- const std::filesystem::path path(std::string{dir});
- std::filesystem::current_path(path/"..");
- }
-}
-
struct loader_impl final : loader_
{
std::optional<Utility::Resource> shader_res;
@@ -48,6 +35,8 @@ struct loader_impl final : loader_
Trade::ImageData2D tile_texture(Containers::StringView filename) override;
std::shared_ptr<struct tile_atlas> tile_atlas(Containers::StringView filename, Vector2ui size) override;
+ static void set_application_working_directory();
+
explicit loader_impl();
~loader_impl() override;
};
@@ -93,6 +82,25 @@ void loader_::destroy()
new (&loader) loader_impl();
}
+void loader_impl::set_application_working_directory()
+{
+ static bool once = false;
+ if (once)
+ return;
+ once = true;
+ const auto location = Utility::Path::executableLocation();
+ if (!location)
+ return;
+ std::filesystem::path path((std::string)*location);
+ path.replace_filename("..");
+ std::error_code error;
+ std::filesystem::current_path(path, error);
+ if (error.value()) {
+ WARN("failed to change working directory to '%s' (%s)",
+ path.string().data(), error.message().data());
+ }
+}
+
loader_impl::loader_impl()
{
set_application_working_directory();