@@ -91,44 +91,76 @@ WizardSmallImageFile=bf_installer_small.bmp
9191WizardStyle = modern
9292
9393[Code]
94+ function GetOldNsisUninstallerPath (): String;
95+ var
96+ RegKey: String;
97+ begin
98+ Result := ' ' ;
99+ // Look into the different registry entries: win32, win64 and without user rights
100+ if not RegQueryStringValue(HKLM, ' SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Betaflight Configurator' , ' UninstallString' , Result) then
101+ begin
102+ if not RegQueryStringValue(HKLM, ' SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Betaflight Configurator' , ' UninstallString' , Result) then
103+ begin
104+ RegQueryStringValue(HKCU, ' SOFTWARE\Betaflight\Betaflight Configurator' , ' UninstallString' , Result)
105+ end ;
106+ end ;
107+ end ;
108+
109+ function GetQuietUninstallerPath (): String;
110+ var
111+ RegKey: String;
112+ begin
113+ Result := ' ' ;
114+ RegKey := Format(' %s\%s_is1' , [' Software\Microsoft\Windows\CurrentVersion\Uninstall' , ' {#emit SetupSetting("AppId")}' ]);
115+ if not RegQueryStringValue(HKEY_LOCAL_MACHINE, RegKey, ' QuietUninstallString' , Result) then
116+ begin
117+ RegQueryStringValue(HKEY_CURRENT_USER, RegKey, ' QuietUninstallString' , Result);
118+ end ;
119+ end ;
120+
94121function InitializeSetup (): Boolean;
95122var
96123 ResultCode: Integer;
97- ResultStr: String;
98124 ParameterStr : String;
125+ UninstPath : String;
99126begin
100127
101128 Result := True;
102129
103130 // Check if the application is already installed by the old NSIS installer, and uninstall it
104- // Look into the different registry entries: win32, win64 and without user rights
105- if not RegQueryStringValue(HKLM, ' SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Betaflight Configurator' , ' UninstallString' , ResultStr) then
106- begin
107- if not RegQueryStringValue(HKLM, ' SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Betaflight Configurator' , ' UninstallString' , ResultStr) then
108- begin
109- RegQueryStringValue(HKCU, ' SOFTWARE\Betaflight\Betaflight Configurator' , ' UninstallString' , ResultStr)
110- end ;
111- end ;
131+ UninstPath := GetOldNsisUninstallerPath();
112132
113133 // Found, start uninstall
114- if ResultStr <> ' ' then
134+ if UninstPath <> ' ' then
115135 begin
116136
117- ResultStr:= RemoveQuotes(ResultStr );
137+ UninstPath := RemoveQuotes(UninstPath );
118138
119139 // Add this parameter to not return until uninstall finished. The drawback is that the uninstaller file is not deleted
120- ParameterStr := ' _?=' + ExtractFilePath(ResultStr );
140+ ParameterStr := ' _?=' + ExtractFilePath(UninstPath );
121141
122- if Exec(ResultStr , ParameterStr, ' ' , SW_SHOW, ewWaitUntilTerminated, ResultCode) then
142+ if Exec(UninstPath , ParameterStr, ' ' , SW_SHOW, ewWaitUntilTerminated, ResultCode) then
123143 begin
124144 // Delete the unistaller file and empty folders. Not deleting the files.
125- DeleteFile(ResultStr );
126- DelTree(ExtractFilePath(ResultStr ), True, False, True);
145+ DeleteFile(UninstPath );
146+ DelTree(ExtractFilePath(UninstPath ), True, False, True);
127147 end
128148 else begin
129149 Result := False;
130150 MsgBox(' Error uninstalling old Configurator ' + SysErrorMessage(ResultCode) + ' .' , mbError, MB_OK);
131151 end ;
132- end ;
152+ end
153+ else begin
133154
155+ // Search for new Inno Setup installations
156+ UninstPath := GetQuietUninstallerPath();
157+ if UninstPath <> ' ' then
158+ begin
159+ if not Exec(' >' , UninstPath, ' ' , SW_SHOW, ewWaitUntilTerminated, ResultCode) then
160+ begin
161+ Result := False;
162+ MsgBox(' Error uninstalling Configurator ' + SysErrorMessage(ResultCode) + ' .' , mbError, MB_OK);
163+ end ;
164+ end ;
165+ end ;
134166end ;
0 commit comments