mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-23 09:35:45 +00:00
fix: use platform specific calls to get executable dir
This commit is contained in:
parent
199446b09f
commit
fb20cbf81c
@ -5,6 +5,7 @@
|
||||
#include "ObjWriting.h"
|
||||
#include "Utils/Arguments/UsageInformation.h"
|
||||
#include "Utils/FileUtils.h"
|
||||
#include "Utils/PathUtils.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
@ -152,9 +153,9 @@ void LinkerArgs::PrintVersion()
|
||||
std::cout << std::format("OpenAssetTools Linker {}\n", GIT_VERSION);
|
||||
}
|
||||
|
||||
void LinkerArgs::SetBinFolder(const char* argv0)
|
||||
void LinkerArgs::SetBinFolder()
|
||||
{
|
||||
const fs::path path(argv0);
|
||||
const fs::path path(utils::GetExecutablePath());
|
||||
m_bin_folder = path.parent_path().string();
|
||||
}
|
||||
|
||||
@ -190,7 +191,7 @@ bool LinkerArgs::ParseArgs(const int argc, const char** argv, bool& shouldContin
|
||||
return true;
|
||||
}
|
||||
|
||||
SetBinFolder(argv[0]);
|
||||
SetBinFolder();
|
||||
|
||||
m_project_specifiers_to_build = m_argument_parser.GetArguments();
|
||||
if (m_project_specifiers_to_build.empty())
|
||||
|
@ -37,7 +37,7 @@ private:
|
||||
void PrintUsage() const;
|
||||
static void PrintVersion();
|
||||
|
||||
void SetBinFolder(const char* argv0);
|
||||
void SetBinFolder();
|
||||
void SetVerbose(bool isVerbose);
|
||||
|
||||
ArgumentParser m_argument_parser;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
27
src/Utils/Utils/PathUtils.cpp
Normal file
27
src/Utils/Utils/PathUtils.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "PathUtils.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#elif defined(__linux__)
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace utils
|
||||
{
|
||||
std::string GetExecutablePath()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char result[MAX_PATH];
|
||||
return std::string(result, GetModuleFileNameA(NULL, result, MAX_PATH));
|
||||
#elif defined(__linux__)
|
||||
char result[PATH_MAX];
|
||||
const auto count = readlink("/proc/self/exe", result, PATH_MAX);
|
||||
return std::string(result, (count > 0) ? count : 0);
|
||||
#else
|
||||
throw std::runtime_error("Unknown platform for executable path");
|
||||
#endif
|
||||
}
|
||||
} // namespace utils
|
8
src/Utils/Utils/PathUtils.h
Normal file
8
src/Utils/Utils/PathUtils.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
std::string GetExecutablePath();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user