diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-12 17:48:01 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-12 18:24:55 +0100 |
| commit | b84cfa301e2fb131275711c67a2e91e3cda65c4e (patch) | |
| tree | d060791ca783f6b9c4da5959535ec0eb85dd73cf /loader/filesystem.cpp | |
| parent | eea6fad65d5c9fecfb47c4a1c516c253cee85fd2 (diff) | |
loader: fix static initializer mess
Diffstat (limited to 'loader/filesystem.cpp')
| -rw-r--r-- | loader/filesystem.cpp | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/loader/filesystem.cpp b/loader/filesystem.cpp index 4fbeb98a..850ec84f 100644 --- a/loader/filesystem.cpp +++ b/loader/filesystem.cpp @@ -1,9 +1,11 @@ #include "impl.hpp" #include "compat/assert.hpp" #include <cerrno> -#include <Corrade/Containers/StringView.h> +#include <Corrade/Containers/Pair.h> +#include <Corrade/Containers/String.h> #include <Corrade/Utility/Debug.h> #include <Corrade/Utility/Implementation/ErrorString.h> +#include <Corrade/Utility/Path.h> #ifdef _WIN32 #include <Corrade/Containers/Array.h> #include <Corrade/Utility/Unicode.h> @@ -18,21 +20,51 @@ namespace floormat::loader_detail { namespace Unicode = Corrade::Utility::Unicode; #endif -bool chdir(StringView pathname) +bool loader_impl::chdir(StringView pathname) { + fm_assert(pathname.flags() & StringViewFlag::NullTerminated); int ret; #ifdef _WIN32 - ret = _wchdir(Unicode::widen(pathname)); + ret = ::_wchdir(Unicode::widen(pathname)); #else ret = ::chdir(pathname.data()); #endif if (ret) { Error err; - err << "chdir: can't change directory to" << pathname << Error::nospace << ':'; + err << "chdir: can't change directory to" << pathname << Error::nospace << ": "; Corrade::Utility::Implementation::printErrnoErrorString(err, errno); } return !ret; } +void loader_impl::set_application_working_directory() +{ + static bool once = false; + if (once) + return; + once = true; + if (const auto loc = Path::executableLocation()) + { + String path; +#ifdef _WIN32 + path = "\\\\?\\"_s + *loc; +#else + path = *loc; +#endif + StringView p = path; + p = Path::split(p).first(); + p = Path::split(p).first(); + path = p; +#ifdef _WIN32 + for (char& c : path) + if (c == '/') + c = '\\'; +#endif + chdir(path); + } + else + fm_warn("can't find install prefix!"); +} + } // namespace floormat::loader_detail |
