mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 22:14:32 +00:00
Try to avoid loading a corrupted configuration file. Also log errors encountered while saving/loading the configuration. Closes #3503.
This commit is contained in:
parent
0b2b07e98e
commit
8bde7d45b8
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
#include "qinisettings.h"
|
#include "qinisettings.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
@ -68,12 +69,12 @@ Preferences::Preferences()
|
|||||||
QStringList keys = settings_new->allKeys();
|
QStringList keys = settings_new->allKeys();
|
||||||
bool use_new = false;
|
bool use_new = false;
|
||||||
|
|
||||||
|
|
||||||
// This means that the PC closed either due to power outage
|
// This means that the PC closed either due to power outage
|
||||||
// or because the disk was full. In any case the settings weren't transfered
|
// or because the disk was full. In any case the settings weren't transfered
|
||||||
// in their final position. So assume that qbittorrent_new.ini/qbittorrent_new.conf
|
// in their final position. So assume that qbittorrent_new.ini/qbittorrent_new.conf
|
||||||
// contains the most recent settings.
|
// contains the most recent settings.
|
||||||
if (!keys.isEmpty()) {
|
if (!keys.isEmpty()) {
|
||||||
|
Logger::instance()->addMessage(tr("Detected unclean program exit. Using fallback file to restore settings."), Log::WARNING);
|
||||||
use_new = true;
|
use_new = true;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
@ -101,7 +102,9 @@ Preferences::Preferences()
|
|||||||
//Ensures sync to disk before we attempt to manipulate the files from save().
|
//Ensures sync to disk before we attempt to manipulate the files from save().
|
||||||
delete settings;
|
delete settings;
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
|
QString new_path = settings_new->fileName();
|
||||||
delete settings_new;
|
delete settings_new;
|
||||||
|
Utils::Fs::forceRemove(new_path);
|
||||||
|
|
||||||
if (use_new)
|
if (use_new)
|
||||||
save();
|
save();
|
||||||
@ -138,7 +141,7 @@ void Preferences::freeInstance()
|
|||||||
|
|
||||||
bool Preferences::save()
|
bool Preferences::save()
|
||||||
{
|
{
|
||||||
QReadLocker locker(&lock);
|
QWriteLocker locker(&lock);
|
||||||
|
|
||||||
if (!dirty) return false;
|
if (!dirty) return false;
|
||||||
|
|
||||||
@ -161,11 +164,19 @@ bool Preferences::save()
|
|||||||
|
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
settings->sync(); // Important to get error status
|
settings->sync(); // Important to get error status
|
||||||
if (settings->status() == QSettings::AccessError) {
|
QString new_path = settings->fileName();
|
||||||
|
QSettings::Status status = settings->status();
|
||||||
|
|
||||||
|
if (status != QSettings::NoError) {
|
||||||
|
if (status == QSettings::AccessError)
|
||||||
|
Logger::instance()->addMessage(tr("An access error occurred while trying to write the configuration file."), Log::CRITICAL);
|
||||||
|
else
|
||||||
|
Logger::instance()->addMessage(tr("A format error occurred while trying to write the configuration file."), Log::CRITICAL);
|
||||||
|
|
||||||
delete settings;
|
delete settings;
|
||||||
|
Utils::Fs::forceRemove(new_path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QString new_path = settings->fileName();
|
|
||||||
delete settings;
|
delete settings;
|
||||||
QString final_path = new_path;
|
QString final_path = new_path;
|
||||||
int index = final_path.lastIndexOf("_new", -1, Qt::CaseInsensitive);
|
int index = final_path.lastIndexOf("_new", -1, Qt::CaseInsensitive);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user