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

sys: Fixed build errors and warnings on Unix

This commit is contained in:
WerWolv 2022-03-22 09:34:26 +01:00
parent 98dfc2e286
commit c2803fe1e2
3 changed files with 19 additions and 12 deletions

View File

@ -1,5 +1,6 @@
#pragma once
#include <optional>
#include <string>
#include <vector>
#include <filesystem>
@ -77,7 +78,7 @@ namespace hex::fs {
Logs
};
std::string getExecutablePath();
std::optional<std::fs::path> getExecutablePath();
std::vector<std::fs::path> getDefaultPaths(ImHexPath path, bool listNonExisting = false);

View File

@ -4,7 +4,7 @@
namespace hex {
[[noreturn]] void unreachable() {
[[noreturn]] inline void unreachable() {
__builtin_unreachable();
}

View File

@ -20,21 +20,23 @@
namespace hex::fs {
std::string getExecutablePath() {
std::optional<std::fs::path> getExecutablePath() {
#if defined(OS_WINDOWS)
std::string exePath(MAX_PATH, '\0');
GetModuleFileName(nullptr, exePath.data(), exePath.length());
if (GetModuleFileName(nullptr, exePath.data(), exePath.length()) == 0)
return std::nullopt;
return exePath;
#elif defined(OS_LINUX)
std::string exePath(PATH_MAX, '\0');
readlink("/proc/self/exe", exePath.data(), PATH_MAX);
if (readlink("/proc/self/exe", exePath.data(), PATH_MAX) < 0)
return std::nullopt;
return exePath;
#elif defined(OS_MACOS)
return getMacExecutableDirectoryPath();
#else
return "";
return std::nullopt;
#endif
}
@ -100,8 +102,6 @@ namespace hex::fs {
};
#if defined(OS_WINDOWS)
const auto parentDir = std::fs::path(exePath).parent_path();
std::fs::path appDataDir;
{
LPWSTR wAppDataPath = nullptr;
@ -112,7 +112,10 @@ namespace hex::fs {
CoTaskMemFree(wAppDataPath);
}
std::vector<std::fs::path> paths = { appDataDir / "imhex", parentDir };
std::vector<std::fs::path> paths = { appDataDir / "imhex" };
if (exePath)
paths.push_back(exePath->parent_path());
switch (path) {
case ImHexPath::Patterns:
@ -181,7 +184,10 @@ namespace hex::fs {
// Get path to special directories
const std::fs::path applicationSupportDir(getMacApplicationSupportDirectoryPath());
std::vector<std::fs::path> paths = { applicationSupportDir, exePath };
std::vector<std::fs::path> paths = { applicationSupportDir };
if (exePath)
paths.push_back(exePath->parent_path());
switch (path) {
case ImHexPath::Patterns:
@ -232,8 +238,8 @@ namespace hex::fs {
for (auto &dir : dataDirs)
dir = dir / "imhex";
if (!exePath.empty())
dataDirs.emplace(dataDirs.begin(), std::fs::path(exePath.data()).parent_path());
if (exePath && !exePath->empty())
dataDirs.push_back(exePath->parent_path());
switch (path) {
case ImHexPath::Patterns: