mirror of https://github.com/WerWolv/ImHex.git
sys: Prevent portable Windows version from writing to AppData
Fixes #627
This commit is contained in:
parent
899f2b3fbd
commit
b8c034f8c5
|
@ -100,6 +100,7 @@ jobs:
|
|||
..
|
||||
mingw32-make -j4 install
|
||||
cpack
|
||||
touch $PWD/install/PORTABLE
|
||||
|
||||
- name: ⬆️ Upload Portable ZIP
|
||||
uses: actions/upload-artifact@v3
|
||||
|
|
|
@ -165,6 +165,8 @@ namespace hex {
|
|||
void setFontSize(float size);
|
||||
|
||||
void setGPUVendor(const std::string &vendor);
|
||||
|
||||
void setPortableVersion(bool enabled);
|
||||
}
|
||||
|
||||
struct ProgramArguments {
|
||||
|
@ -208,6 +210,8 @@ namespace hex {
|
|||
void setAdditionalFolderPaths(const std::vector<std::fs::path> &paths);
|
||||
|
||||
const std::string &getGPUVendor();
|
||||
|
||||
bool isPortableVersion();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -354,6 +354,11 @@ namespace hex {
|
|||
s_gpuVendor = vendor;
|
||||
}
|
||||
|
||||
static bool s_portableVersion = false;
|
||||
void setPortableVersion(bool enabled) {
|
||||
s_portableVersion = enabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -451,6 +456,10 @@ namespace hex {
|
|||
const std::string &getGPUVendor() {
|
||||
return impl::s_gpuVendor;
|
||||
}
|
||||
|
||||
bool isPortableVersion() {
|
||||
return impl::s_portableVersion;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -111,18 +111,22 @@ namespace hex::fs {
|
|||
};
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
std::fs::path appDataDir;
|
||||
{
|
||||
PWSTR wAppDataPath = nullptr;
|
||||
if (!SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, nullptr, &wAppDataPath)))
|
||||
throw std::runtime_error("Failed to get APPDATA folder path");
|
||||
std::vector<std::fs::path> paths;
|
||||
|
||||
appDataDir = std::wstring(wAppDataPath);
|
||||
CoTaskMemFree(wAppDataPath);
|
||||
if (!ImHexApi::System::isPortableVersion()) {
|
||||
std::fs::path appDataDir;
|
||||
{
|
||||
PWSTR wAppDataPath = nullptr;
|
||||
if (!SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, nullptr, &wAppDataPath)))
|
||||
throw std::runtime_error("Failed to get APPDATA folder path");
|
||||
|
||||
appDataDir = std::wstring(wAppDataPath);
|
||||
CoTaskMemFree(wAppDataPath);
|
||||
}
|
||||
|
||||
paths.push_back(appDataDir / "imhex");
|
||||
}
|
||||
|
||||
std::vector<std::fs::path> paths = { appDataDir / "imhex" };
|
||||
|
||||
if (exePath)
|
||||
paths.push_back(exePath->parent_path());
|
||||
|
||||
|
|
|
@ -72,6 +72,17 @@ namespace hex::init {
|
|||
fs::ImHexPath::Logs
|
||||
};
|
||||
|
||||
// Check if ImHex is installed in portable mode
|
||||
{
|
||||
if (const auto executablePath = fs::getExecutablePath(); executablePath.has_value()) {
|
||||
const auto flagFile = executablePath.value() / "PORTABLE";
|
||||
|
||||
if (fs::exists(flagFile) && fs::isRegularFile(flagFile))
|
||||
ImHexApi::System::impl::setPortableVersion(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Create all folders
|
||||
for (auto path : paths) {
|
||||
for (auto &folder : fs::getDefaultPaths(path, true)) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue