From f1c03f8b1d3bb07e3cc2e4031d3e929c040ae5b0 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 2 Mar 2021 10:20:29 +0100 Subject: [PATCH] sys: Place config files in AppData/Local/imhex folder on Windows Fixes #182 --- plugins/libimhex/source/helpers/utils.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/libimhex/source/helpers/utils.cpp b/plugins/libimhex/source/helpers/utils.cpp index c157dd05b..29cbbb049 100644 --- a/plugins/libimhex/source/helpers/utils.cpp +++ b/plugins/libimhex/source/helpers/utils.cpp @@ -7,6 +7,7 @@ #if defined(OS_WINDOWS) #include + #include #elif defined(OS_MACOS) #include #elif defined(OS_LINUX) @@ -184,6 +185,16 @@ namespace hex { GetModuleFileName(nullptr, exePath.data(), exePath.length()); auto parentDir = std::filesystem::path(exePath).parent_path(); + std::filesystem::path appDataDir; + { + LPWSTR wAppDataPath = nullptr; + if (!SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, nullptr, &wAppDataPath))) + throw std::runtime_error("Failed to get APPDATA folder path"); + + appDataDir = wAppDataPath; + CoTaskMemFree(wAppDataPath); + } + switch (path) { case ImHexPath::Patterns: return { (parentDir / "patterns").string() }; @@ -198,7 +209,7 @@ namespace hex { case ImHexPath::Yara: return { (parentDir / "yara").string() }; case ImHexPath::Config: - return { (parentDir / "config").string() }; + return { (appDataDir / "imhex" / "config").string() }; case ImHexPath::Resources: return { (parentDir / "resources").string() }; default: __builtin_unreachable();