From ced93eb58aae66bd326fa28e0830fcd2d702a580 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 28 Feb 2024 12:24:54 +0200 Subject: [PATCH] Warn about overriding previous version. --- dist/win/inno/valentina.iss | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/dist/win/inno/valentina.iss b/dist/win/inno/valentina.iss index febe731aa..f0dcee6df 100644 --- a/dist/win/inno/valentina.iss +++ b/dist/win/inno/valentina.iss @@ -519,6 +519,15 @@ end; ///////////////////////////////////////////////////////////////////// // Version comparison on installation +function GetRegistryRootKey(): Integer; +begin + // Check if the installer is running in administrative install mode + if IsAdminInstallMode() then + Result := HKEY_LOCAL_MACHINE + else + Result := HKEY_CURRENT_USER; +end; + function VersionCompareAndUninstall(): Boolean; var oldVersion: String; @@ -528,10 +537,10 @@ var begin tmpId := '{#emit SetupSetting("AppId")}'; Delete(tmpId,1,1); - if RegKeyExists(HKEY_LOCAL_MACHINE, + if RegKeyExists(GetRegistryRootKey(), 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + tmpId + '_is1') then begin - RegQueryStringValue(HKEY_LOCAL_MACHINE, + RegQueryStringValue(GetRegistryRootKey(), 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + tmpId + '_is1', 'DisplayVersion', oldVersion); if (CompareVersion(oldVersion, '{#emit SetupSetting("AppVersion")}') < 0) then @@ -543,7 +552,7 @@ begin end else begin - RegQueryStringValue(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + tmpId + '_is1','UninstallString', uninstaller); + RegQueryStringValue(GetRegistryRootKey(),'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + tmpId + '_is1','UninstallString', uninstaller); If ShellExec('', uninstaller, '/SILENT', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode) then begin // handle success if necessary; ResultCode contains the exit code