mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 15:27:54 +00:00
Polish previous commit.
This commit is contained in:
parent
5a006d5980
commit
d88ec48468
@ -138,7 +138,7 @@ int main(int argc, char *argv[])
|
|||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
// On macOS 10.12 Sierra, Apple changed the behaviour of CFPreferencesSetValue() https://bugreports.qt.io/browse/QTBUG-56344
|
// 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
|
// Due to this, we have to move from native plist to IniFormat
|
||||||
macSalvagePlists();
|
macMigratePlists();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create Application
|
// Create Application
|
||||||
|
@ -230,25 +230,30 @@ bool upgrade(bool ask = true)
|
|||||||
|
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
bool copyPlistToIni(const char *application)
|
void migratePlistToIni(const QString &application)
|
||||||
{
|
{
|
||||||
QSettings iniFile(QSettings::IniFormat, QSettings::UserScope, "qBittorrent", application);
|
QIniSettings iniFile("qBittorrent", application);
|
||||||
if (QFile::exists(iniFile.fileName())) return false; // We copy the contents of plist, only if inifile does not exist.
|
if (iniFile.allKeys().isEmpty()) return; // We copy the contents of plist, only if inifile does not exist(is empty).
|
||||||
QSettings plistFile("qBittorrent", application);
|
|
||||||
if (!QFile::exists(plistFile.fileName())) return false;
|
QSettings *plistFile = new QSettings("qBittorrent", application);
|
||||||
plistFile.setFallbacksEnabled(false);
|
plistFile->setFallbacksEnabled(false);
|
||||||
const QStringList plist = plistFile.allKeys();
|
const QStringList plist = plistFile->allKeys();
|
||||||
foreach (const QString &key, plist) {
|
if (!plist.isEmpty()) {
|
||||||
iniFile.setValue(key, plistFile.value(key));
|
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");
|
migratePlistToIni("qBittorrent-data");
|
||||||
copyPlistToIni("qBittorrent-rss");
|
migratePlistToIni("qBittorrent-rss");
|
||||||
copyPlistToIni("qBittorrent");
|
migratePlistToIni("qBittorrent");
|
||||||
}
|
}
|
||||||
#endif // Q_OS_MAC
|
#endif // Q_OS_MAC
|
||||||
|
|
||||||
|
@ -38,11 +38,6 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "utils/fs.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
|
namespace
|
||||||
{
|
{
|
||||||
// Encapsulates serialization of settings in "atomic" way.
|
// Encapsulates serialization of settings in "atomic" way.
|
||||||
@ -267,9 +262,6 @@ void SettingsStorage::removeValue(const QString &key)
|
|||||||
QVariantHash TransactionalSettings::read()
|
QVariantHash TransactionalSettings::read()
|
||||||
{
|
{
|
||||||
QVariantHash res;
|
QVariantHash res;
|
||||||
#ifdef QSETTINGS_SYNC_IS_SAVE
|
|
||||||
deserialize(m_name, res);
|
|
||||||
#else
|
|
||||||
bool writeBackNeeded = false;
|
bool writeBackNeeded = false;
|
||||||
QString newPath = deserialize(m_name + QLatin1String("_new"), res);
|
QString newPath = deserialize(m_name + QLatin1String("_new"), res);
|
||||||
if (!newPath.isEmpty()) { // "_new" file is NOT empty
|
if (!newPath.isEmpty()) { // "_new" file is NOT empty
|
||||||
@ -288,15 +280,12 @@ QVariantHash TransactionalSettings::read()
|
|||||||
|
|
||||||
if (writeBackNeeded)
|
if (writeBackNeeded)
|
||||||
write(res);
|
write(res);
|
||||||
#endif
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TransactionalSettings::write(const QVariantHash &data)
|
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
|
// 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
|
// 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.
|
// 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);
|
finalPath.remove(index, 4);
|
||||||
Utils::Fs::forceRemove(finalPath);
|
Utils::Fs::forceRemove(finalPath);
|
||||||
QFile::rename(newPath, finalPath);
|
QFile::rename(newPath, finalPath);
|
||||||
#endif
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user