From 9c2a50721500cdff345d809938076cce0963d888 Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Mon, 28 Oct 2019 16:55:21 +0200 Subject: Add early prompt to run MaintenanceTool as admin when needed Currently IFW does not support manipulating Windows Access Control Lists for files. If a user does not have reading permissions to installer.dat it will throw error on QInstaller::openForRead() before the wizard GUI is shown. At very least, add a MessageBox to prompt the user to run the executable again as administrator in such a case. Task-number: QTIFW-1392 Change-Id: I9e20c34b215ee697118af9c15a7e344f9cfc3c3f Reviewed-by: Katja Marttila --- src/sdk/installerbase.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/sdk/installerbase.cpp b/src/sdk/installerbase.cpp index d7f21bbd0..247b4ab57 100644 --- a/src/sdk/installerbase.cpp +++ b/src/sdk/installerbase.cpp @@ -95,6 +95,22 @@ int InstallerBase::run() } } + QFile binary(binaryFile()); + +#ifdef Q_OS_WIN + // On some admin user installations it is possible that the installer.dat + // file is left without reading permissions for non-administrator users, + // we should check this and prompt the user to run the executable as admin if needed. + if (!binary.open(QIODevice::ReadOnly)) { + QFileInfo binaryInfo(binary.fileName()); + QInstaller::MessageBoxHandler::information(nullptr, QLatin1String("NoReadingPermissions"), + tr("Cannot open file \"%1\" for reading").arg(binaryInfo.fileName()), + tr("Please make sure that the current user has reading access " + "to file \"%1\" or try running %2 as an administrator.").arg(binaryInfo.fileName(), qAppName())); + return EXIT_FAILURE; + } + binary.close(); +#endif QString fileName = datFile(binaryFile()); quint64 cookie = QInstaller::BinaryContent::MagicCookieDat; if (fileName.isEmpty()) { @@ -102,7 +118,7 @@ int InstallerBase::run() cookie = QInstaller::BinaryContent::MagicCookie; } - QFile binary(fileName); + binary.setFileName(fileName); QInstaller::openForRead(&binary); qint64 magicMarker; -- cgit v1.2.3