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

@ -167,8 +167,7 @@ void DownloadExtractThread::extractImageRun()
{ {
if (!_cancelled) if (!_cancelled)
{ {
DownloadThread::cancelDownload(); _onWriteError();
emit error(tr("Error writing to storage"));
} }
archive_read_free(a); archive_read_free(a);
return; return;

View file

@ -444,23 +444,7 @@ void DownloadThread::run()
break; break;
case CURLE_WRITE_ERROR: case CURLE_WRITE_ERROR:
deleteDownloadedFile(); deleteDownloadedFile();
_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"));
break; break;
case CURLE_ABORTED_BY_CALLBACK: case CURLE_ABORTED_BY_CALLBACK:
deleteDownloadedFile(); deleteDownloadedFile();
@ -671,6 +655,26 @@ void DownloadThread::_onDownloadError(const QString &msg)
emit error(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() void DownloadThread::_closeFiles()
{ {
_file.close(); _file.close();

View file

@ -141,6 +141,7 @@ protected:
virtual void run(); virtual void run();
virtual void _onDownloadSuccess(); virtual void _onDownloadSuccess();
virtual void _onDownloadError(const QString &msg); virtual void _onDownloadError(const QString &msg);
virtual void _onWriteError();
void _hashData(const char *buf, size_t len); void _hashData(const char *buf, size_t len);
void _writeComplete(); void _writeComplete();