diff --git a/src/app/main.cpp b/src/app/main.cpp index b07a5dfc3..0ace32ef3 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -138,7 +138,7 @@ int main(int argc, char *argv[]) #ifdef Q_OS_MAC // On macOS 10.12 Sierra, Apple changed the behaviour of CFPreferencesSetValue() https://bugreports.qt.io/browse/QTBUG-56344 // Due to this, we have to move from native plist to IniFormat - macSalvagePlists(); + macMigratePlists(); #endif // Create Application diff --git a/src/app/upgrade.h b/src/app/upgrade.h index 4f8ec45d0..ba776fceb 100644 --- a/src/app/upgrade.h +++ b/src/app/upgrade.h @@ -230,25 +230,30 @@ bool upgrade(bool ask = true) #ifdef Q_OS_MAC -bool copyPlistToIni(const char *application) +void migratePlistToIni(const QString &application) { - QSettings iniFile(QSettings::IniFormat, QSettings::UserScope, "qBittorrent", application); - if (QFile::exists(iniFile.fileName())) return false; // We copy the contents of plist, only if inifile does not exist. - QSettings plistFile("qBittorrent", application); - if (!QFile::exists(plistFile.fileName())) return false; - plistFile.setFallbacksEnabled(false); - const QStringList plist = plistFile.allKeys(); - foreach (const QString &key, plist) { - iniFile.setValue(key, plistFile.value(key)); + QIniSettings iniFile("qBittorrent", application); + if (iniFile.allKeys().isEmpty()) return; // We copy the contents of plist, only if inifile does not exist(is empty). + + QSettings *plistFile = new QSettings("qBittorrent", application); + plistFile->setFallbacksEnabled(false); + const QStringList plist = plistFile->allKeys(); + if (!plist.isEmpty()) { + foreach (const QString &key, plist) + iniFile.setValue(key, plistFile->value(key)); + plistFile->clear(); } - return true; + + QString plistPath = plistFile->fileName(); + delete plistFile; + Utils::Fs::forceRemove(plistPath); } -void macSalvagePlists() +void macMigratePlists() { - copyPlistToIni("qBittorrent-data"); - copyPlistToIni("qBittorrent-rss"); - copyPlistToIni("qBittorrent"); + migratePlistToIni("qBittorrent-data"); + migratePlistToIni("qBittorrent-rss"); + migratePlistToIni("qBittorrent"); } #endif // Q_OS_MAC diff --git a/src/base/settingsstorage.cpp b/src/base/settingsstorage.cpp index 30bf7a497..d2c6eeb52 100644 --- a/src/base/settingsstorage.cpp +++ b/src/base/settingsstorage.cpp @@ -38,11 +38,6 @@ #include "logger.h" #include "utils/fs.h" -#ifdef Q_OS_MAC -// now mac uses ini -//#define QSETTINGS_SYNC_IS_SAVE // whether QSettings::sync() is "atomic" -#endif - namespace { // Encapsulates serialization of settings in "atomic" way. @@ -267,9 +262,6 @@ void SettingsStorage::removeValue(const QString &key) QVariantHash TransactionalSettings::read() { QVariantHash res; -#ifdef QSETTINGS_SYNC_IS_SAVE - deserialize(m_name, res); -#else bool writeBackNeeded = false; QString newPath = deserialize(m_name + QLatin1String("_new"), res); if (!newPath.isEmpty()) { // "_new" file is NOT empty @@ -288,15 +280,12 @@ QVariantHash TransactionalSettings::read() if (writeBackNeeded) write(res); -#endif + return res; } bool TransactionalSettings::write(const QVariantHash &data) { -#ifdef QSETTINGS_SYNC_IS_SAVE - serialize(m_name, data); -#else // QSettings delete the file before writing it out. This can result in problems // if the disk is full or a power outage occurs. Those events might occur // between deleting the file and recreating it. This is a safety measure. @@ -313,7 +302,7 @@ bool TransactionalSettings::write(const QVariantHash &data) finalPath.remove(index, 4); Utils::Fs::forceRemove(finalPath); QFile::rename(newPath, finalPath); -#endif + return true; }