windows: Added context menu entry option

Closes #333
This commit is contained in:
WerWolv
2021-10-31 16:28:10 +01:00
parent 1f250e87a3
commit c88053a575
7 changed files with 109 additions and 8 deletions

View File

@@ -17,6 +17,8 @@ namespace hex {
Constants
};
std::string getExecutablePath();
std::vector<std::string> getPath(ImHexPath path);
}

View File

@@ -16,11 +16,28 @@
namespace hex {
std::vector<std::string> getPath(ImHexPath path) {
std::string getExecutablePath() {
#if defined(OS_WINDOWS)
std::string exePath(MAX_PATH, '\0');
GetModuleFileName(nullptr, exePath.data(), exePath.length());
auto parentDir = std::filesystem::path(exePath).parent_path();
return exePath;
#elif defined(OS_LINUX)
std::string exePath(PATH_MAX, '\0');
readlink("/proc/self/exe", executablePath.data(), PATH_MAX);
return exePath;
#elif defined(OS_MACOS)
return getMacExecutableDirectoryPath();
#else
return "";
#endif
}
std::vector<std::string> getPath(ImHexPath path) {
#if defined(OS_WINDOWS)
const auto exePath = getExecutablePath();
const auto parentDir = std::filesystem::path(exePath).parent_path();
std::filesystem::path appDataDir;
{
@@ -84,10 +101,10 @@ namespace hex {
return results;
#elif defined(OS_MACOS)
// Get path to special directories
const std::filesystem::path exeDir(getMacExecutableDirectoryPath());
const auto exePath = getExecutablePath();
const std::filesystem::path applicationSupportDir(getMacApplicationSupportDirectoryPath());
std::vector<std::filesystem::path> paths = { exeDir, applicationSupportDir };
std::vector<std::filesystem::path> paths = { exePath, applicationSupportDir };
std::vector<std::string> results;
switch (path) {
@@ -126,8 +143,9 @@ namespace hex {
for (auto &dir : dataDirs)
dir = dir / "imhex";
std::array<char, PATH_MAX> executablePath = { 0 };
if (readlink("/proc/self/exe", executablePath.data(), PATH_MAX) != -1)
const auto exePath = getExecutablePath();
if (!exePath.empty())
dataDirs.emplace(dataDirs.begin(), std::filesystem::path(executablePath.data()).parent_path());
std::vector<std::string> result;