From 7d271380868f96a7a2e1f36ee03b97ad9db7c52e Mon Sep 17 00:00:00 2001 From: Tannin Date: Wed, 10 Sep 2014 20:43:33 +0200 Subject: when MO fails to overwrite its ini file it tries another method using qt functions --- src/mainwindow.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 984d8cfd..ae5c1e48 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2166,6 +2166,15 @@ void MainWindow::readSettings() } +bool renameFile(const QString &oldName, const QString &newName, bool overwrite = true) +{ + if (overwrite && QFile::exists(newName)) { + QFile::remove(newName); + } + return QFile::rename(oldName, newName); +} + + void MainWindow::storeSettings() { if (m_CurrentProfile == NULL) { @@ -2235,8 +2244,12 @@ void MainWindow::storeSettings() } if (result == QSettings::NoError) { if (!shellRename(iniFile + ".new", iniFile, true, this)) { - QMessageBox::critical(this, tr("Failed to write settings"), - tr("An error occured trying to write back MO settings: %1").arg(windowsErrorString(::GetLastError()))); + DWORD err = ::GetLastError(); + // make a second attempt using qt functions but if that fails print the error from the first attempt + if (!renameFile(iniFile + ".new", iniFile)) { + QMessageBox::critical(this, tr("Failed to write settings"), + tr("An error occured trying to write back MO settings: %1").arg(windowsErrorString(err))); + } } } else { QString reason = result == QSettings::AccessError ? tr("File is write protected") -- cgit v1.3.1