Windows: improve error reporting if Conditional File Access is active

This commit is contained in:
Floris Bos 2023-09-23 19:46:13 +02:00
parent ce549cadb2
commit 2853fd2b87
3 changed files with 23 additions and 19 deletions

View file

@ -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 += "<br>"+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 += "<br>"+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();