UI: IniUser: Refactor saving initial ini

This commit is contained in:
Nodir Temirkhodjaev 2023-12-23 19:39:40 +03:00
parent 5850d4e58c
commit fe21129c4e
4 changed files with 15 additions and 8 deletions

View File

@ -105,7 +105,7 @@ void FortSettings::setupGlobal()
// Is portable?
g_isPortable = FileUtil::fileExists(appFileInfo.path() + "/README.portable");
// Use global settings from program's binary directory
// Global settings from program's binary directory
const QSettings settings(appFileInfo.filePath() + ".ini", QSettings::IniFormat);
// High-DPI scale factor rounding policy

View File

@ -2,12 +2,9 @@
IniUser::IniUser(Settings *settings) : MapSettings(settings) { }
void IniUser::setDefaultLanguage(const QString &v)
void IniUser::saveDefaultIni()
{
m_defaultLanguage = v;
setLanguage(defaultLanguage());
if (language().isEmpty()) {
setLanguage(defaultLanguage());
save();
}
save();
}

View File

@ -9,7 +9,7 @@ public:
explicit IniUser(Settings *settings = nullptr);
QString defaultLanguage() const { return m_defaultLanguage; }
void setDefaultLanguage(const QString &v);
void setDefaultLanguage(const QString &v) { m_defaultLanguage = v; }
QString language() const { return valueText("base/language"); }
void setLanguage(const QString &v) { setValue("base/language", v); }
@ -194,6 +194,9 @@ public:
bool statShowHostNames() const { return valueBool("statWindow/showHostNames"); }
void setStatShowHostNames(bool on) { setValue("statWindow/showHostNames", on); }
public:
void saveDefaultIni();
private:
QString m_defaultLanguage;
};

View File

@ -18,10 +18,17 @@ void UserSettings::setUp()
void UserSettings::migrateIniOnStartup()
{
if (!iniExists()) {
iniUser().saveDefaultIni();
return;
}
int version;
if (checkIniVersion(version))
return;
Settings::migrateIniOnStartup();
// COMPAT: v3.4.0: .ini ~> .user.ini
if (version < 0x030400) {
setCacheValue("statWindow/trafUnit", ini()->value("stat/trafUnit"));