From 4ae3c217d73fd81dfdb95fbffdb6ee82f9b8ce75 Mon Sep 17 00:00:00 2001 From: Bret Curtis Date: Sun, 30 Apr 2023 18:05:30 +0200 Subject: [PATCH] give this a try... --- apps/mwiniimporter/main.cpp | 4 ---- apps/mwiniimporter_tests/main.cpp | 31 ++++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 255f3e182f..d9691fcdcc 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -6,11 +6,8 @@ #include "CLI/CLI.hpp" -#include #include -namespace sfs = std::filesystem; - #ifndef _WIN32 int main(int argc, char* argv[]) { @@ -93,7 +90,6 @@ int wmain(int argc, wchar_t* wargv[]) "\n\twin1252 - Western European (Latin) alphabet, used by default" ) ->default_str("win1252")->check(CLI::IsMember({"win1250", "win1251", "win1252"}, CLI::ignore_case)); - ; bool verbose = false; app.add_flag("-v,--verbose", verbose, "verbose output"); diff --git a/apps/mwiniimporter_tests/main.cpp b/apps/mwiniimporter_tests/main.cpp index bd68c27306..f0819668b6 100644 --- a/apps/mwiniimporter_tests/main.cpp +++ b/apps/mwiniimporter_tests/main.cpp @@ -4,6 +4,35 @@ #include #include +#ifdef _WIN32 +#include +#elif defined(__APPLE__) +#include +#else +#include +#endif + +std::filesystem::path getExecutablePath() { +#ifdef _WIN32 + WCHAR buffer[MAX_PATH]; + GetModuleFileNameW(NULL, buffer, MAX_PATH); + std::wstring exe_path(buffer); + return std::filesystem::path(exe_path).parent_path(); +#elif defined(__APPLE__) + char buffer[PATH_MAX]; + uint32_t bufsize = sizeof(buffer); + _NSGetExecutablePath(buffer, &bufsize); + return std::filesystem::path(buffer).parent_path();; +#else + char buffer[PATH_MAX]; + ssize_t len = ::readlink("/proc/self/exe", buffer, sizeof(buffer) - 1); + if (len != -1) { + buffer[len] = '\0'; + std::string exe_path(buffer); + return std::filesystem::path(exe_path).parent_path(); +#endif +} + struct TestParam { std::string name; @@ -30,7 +59,7 @@ Archive 1=game2.bsa tempFile << iniData; tempFile.close(); std::filesystem::path tempCfgFile = std::filesystem::temp_directory_path() / (param.fileName + ".cfg"); - std::filesystem::path binaryPath = std::filesystem::current_path() / "openmw-iniimporter"; + std::filesystem::path binaryPath = getExecutablePath() / "openmw-iniimporter"; std::stringstream cmd; cmd << binaryPath << " -i " << tempIniFile << " -c " << tempCfgFile;