diff --git a/src/downloadextractthread.cpp b/src/downloadextractthread.cpp index dadde56..ac61df6 100644 --- a/src/downloadextractthread.cpp +++ b/src/downloadextractthread.cpp @@ -167,8 +167,7 @@ void DownloadExtractThread::extractImageRun() { if (!_cancelled) { - DownloadThread::cancelDownload(); - emit error(tr("Error writing to storage")); + _onWriteError(); } archive_read_free(a); return; diff --git a/src/downloadthread.cpp b/src/downloadthread.cpp index c603d0e..e3fe5fa 100644 --- a/src/downloadthread.cpp +++ b/src/downloadthread.cpp @@ -444,23 +444,7 @@ void DownloadThread::run() break; case CURLE_WRITE_ERROR: deleteDownloadedFile(); - -#ifdef Q_OS_WIN - if (_file.errorCode() == ERROR_ACCESS_DENIED) - { - QString msg = tr("Access denied error while writing file to disk."); - QSettings registry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Defender\\Windows Defender Exploit Guard\\Controlled Folder Access", - QSettings::Registry64Format); - if (registry.value("EnableControlledFolderAccess").toInt() == 1) - { - msg += "
"+tr("Controlled Folder Access seems to be enabled. Please add both rpi-imager.exe and fat32format.exe to the list of allowed apps and try again."); - } - _onDownloadError(msg); - } - else -#endif - if (!_cancelled) - _onDownloadError(tr("Error writing file to disk")); + _onWriteError(); break; case CURLE_ABORTED_BY_CALLBACK: deleteDownloadedFile(); @@ -671,6 +655,26 @@ void DownloadThread::_onDownloadError(const QString &msg) emit error(msg); } +void DownloadThread::_onWriteError() +{ +#ifdef Q_OS_WIN + if (_file.errorCode() == ERROR_ACCESS_DENIED) + { + QString msg = tr("Access denied error while writing file to disk."); + QSettings registry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Defender\\Windows Defender Exploit Guard\\Controlled Folder Access", + QSettings::Registry64Format); + if (registry.value("EnableControlledFolderAccess").toInt() == 1) + { + msg += "
"+tr("Controlled Folder Access seems to be enabled. Please add both rpi-imager.exe and fat32format.exe to the list of allowed apps and try again."); + } + _onDownloadError(msg); + } + else +#endif + if (!_cancelled) + _onDownloadError(tr("Error writing file to disk")); +} + void DownloadThread::_closeFiles() { _file.close(); diff --git a/src/downloadthread.h b/src/downloadthread.h index 40134f3..3fb9542 100644 --- a/src/downloadthread.h +++ b/src/downloadthread.h @@ -141,6 +141,7 @@ protected: virtual void run(); virtual void _onDownloadSuccess(); virtual void _onDownloadError(const QString &msg); + virtual void _onWriteError(); void _hashData(const char *buf, size_t len); void _writeComplete();