mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-10-22 10:46:04 +03: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
80de35c5ee
commit
6b4aad8a83
1 changed files with 15 additions and 4 deletions
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "preferences.h"
|
||||
#include "qinisettings.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QPair>
|
||||
|
@ -67,12 +68,12 @@ Preferences::Preferences()
|
|||
QStringList keys = settings_new->allKeys();
|
||||
bool use_new = false;
|
||||
|
||||
|
||||
// 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
|
||||
// in their final position. So assume that qbittorrent_new.ini/qbittorrent_new.conf
|
||||
// contains the most recent settings.
|
||||
if (!keys.isEmpty()) {
|
||||
Logger::instance()->addMessage(tr("Detected unclean program exit. Using fallback file to restore settings."), Log::WARNING);
|
||||
use_new = true;
|
||||
dirty = true;
|
||||
}
|
||||
|
@ -100,7 +101,9 @@ Preferences::Preferences()
|
|||
//Ensures sync to disk before we attempt to manipulate the files from save().
|
||||
delete settings;
|
||||
#ifndef Q_OS_MAC
|
||||
QString new_path = settings_new->fileName();
|
||||
delete settings_new;
|
||||
fsutils::forceRemove(new_path);
|
||||
|
||||
if (use_new)
|
||||
save();
|
||||
|
@ -134,7 +137,7 @@ void Preferences::drop()
|
|||
|
||||
void Preferences::save()
|
||||
{
|
||||
QReadLocker locker(&lock);
|
||||
QWriteLocker locker(&lock);
|
||||
|
||||
if (!dirty)
|
||||
return;
|
||||
|
@ -158,11 +161,19 @@ void Preferences::save()
|
|||
|
||||
#ifndef Q_OS_MAC
|
||||
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;
|
||||
fsutils::forceRemove(new_path);
|
||||
return;
|
||||
}
|
||||
QString new_path = settings->fileName();
|
||||
delete settings;
|
||||
QString final_path = new_path;
|
||||
int index = final_path.lastIndexOf("_new", -1, Qt::CaseInsensitive);
|
||||
|
|
Loading…
Reference in a new issue