fix: Move config files to XDG_CONFIG_HOME (#993)

This pull request changes Config Directories on Linux to only include
the XDG_CONFIG_HOME directory, as opposed to all directories in
XDG_DATA_DIRS before (introduced in
https://github.com/WerWolv/ImHex/pull/644/files#diff-c1a4d2b63fed168a9a3568944e9cadeae096f2ddcec3649e4a9b2d29fd104be0L162-L166).

Reasons:
- This changes the location of the config file to the standard directory
meant for configurations
- This prevents the config file from being read/written in system
locations, like /usr/share

This PR also includes a migration task that will run on Linux and move
config/GUI dimensions to the new directory

as a bonus, as discussed on discord, it writes the logs to a Data
directory instead of a Config directory
This commit is contained in:
Thomas
2023-03-26 11:02:23 +02:00
committed by GitHub
parent 5fa264ea18
commit 725e32250b
3 changed files with 47 additions and 13 deletions

View File

@@ -121,6 +121,44 @@ namespace hex::init {
return result;
}
bool migrateConfig(){
// check if there is a new config in folder
auto configPaths = hex::fs::getDefaultPaths(hex::fs::ImHexPath::Config, false);
// There should always be exactly one config path on Linux
std::fs::path newConfigPath = configPaths[0];
wolv::io::File newConfigFile(newConfigPath / "settings.json", wolv::io::File::Mode::Read);
if (!newConfigFile.isValid()) {
// find an old config
std::fs::path oldConfigPath;
for(auto dir : hex::fs::appendPath(hex::fs::getDataPaths(), "config")) {
wolv::io::File oldConfigFile(dir / "settings.json", wolv::io::File::Mode::Read);
if (oldConfigFile.isValid()) {
oldConfigPath = dir;
break;
}
}
if (!oldConfigPath.empty()) {
// move it to new location
auto configPaths = hex::fs::getDefaultPaths(hex::fs::ImHexPath::Config, false);
// There should always be exactly one config path on Linux
std::fs::path newConfigPath = configPaths[0];
log::info("Found config file in {} ! Migrating to {}", oldConfigPath.string(), newConfigPath.string());
std::fs::rename(oldConfigPath / "settings.json", newConfigPath / "settings.json");
wolv::io::File oldIniFile(oldConfigPath / "interface.ini", wolv::io::File::Mode::Read);
if (oldIniFile.isValid()) {
std::fs::rename(oldConfigPath / "interface.ini", newConfigPath / "interface.ini");
}
std::fs::remove(oldConfigPath);
}
}
return true;
}
static bool loadFontsImpl(bool loadUnicode) {
float fontSize = ImHexApi::System::getFontSize();
@@ -436,6 +474,9 @@ namespace hex::init {
return {
{ "Setting up environment", setupEnvironment, false },
{ "Creating directories", createDirectories, false },
#if defined(OS_LINUX)
{ "Migrate config to .config", migrateConfig, false },
#endif
{ "Loading settings", loadSettings, false },
{ "Loading plugins", loadPlugins, false },
{ "Checking for updates", checkForUpdates, true },