1
0
mirror of synced 2024-11-28 01:20:51 +01:00

fix: Portable version detection not working correctly

This commit is contained in:
WerWolv 2022-08-01 23:25:13 +02:00
parent a4c377dc08
commit 59449bbe47
3 changed files with 18 additions and 9 deletions

View File

@ -274,20 +274,22 @@ namespace hex {
return result;
}
inline void trimLeft(std::string &s) {
template<typename T>
inline void trimLeft(std::basic_string<T> &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
return !std::isspace(ch) && ch >= 0x20;
}));
}
inline void trimRight(std::string &s) {
template<typename T>
inline void trimRight(std::basic_string<T> &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
return !std::isspace(ch) && ch >= 0x20;
}).base(),
s.end());
}).base(), s.end());
}
inline void trim(std::string &s) {
template<typename T>
inline void trim(std::basic_string<T> &s) {
trimLeft(s);
trimRight(s);
}

View File

@ -5,6 +5,7 @@
#include <hex/helpers/file.hpp>
#include <hex/helpers/intrinsics.hpp>
#include <hex/helpers/net.hpp>
#include <hex/helpers/utils.hpp>
#include <xdg.hpp>
@ -27,23 +28,29 @@ namespace hex::fs {
if (GetModuleFileNameW(nullptr, exePath.data(), exePath.length()) == 0)
return std::nullopt;
hex::trim(exePath);
return exePath;
#elif defined(OS_LINUX)
std::string exePath(PATH_MAX, '\0');
if (readlink("/proc/self/exe", exePath.data(), PATH_MAX) < 0)
return std::nullopt;
hex::trim(exePath);
return exePath;
#elif defined(OS_MACOS)
std::string result;
std::string exePath;
{
auto string = getMacExecutableDirectoryPath();
result = string;
exePath = string;
macFree(string);
}
return result;
hex::trim(exePath);
return exePath;
#else
return std::nullopt;
#endif

View File

@ -75,7 +75,7 @@ namespace hex::init {
// Check if ImHex is installed in portable mode
{
if (const auto executablePath = fs::getExecutablePath(); executablePath.has_value()) {
const auto flagFile = executablePath.value() / "PORTABLE";
const auto flagFile = executablePath->parent_path() / "PORTABLE";
if (fs::exists(flagFile) && fs::isRegularFile(flagFile))
ImHexApi::System::impl::setPortableVersion(true);