Skip to content

Commit 4c4e6c9

Browse files
author
Bud
committed
Last minute Overhaul
changed appid to be VirtualDisplayDriver (inno auto appends _is1 to the end) added uninstaller on running installer again to prevent multiple installs of it
1 parent a27a0a0 commit 4c4e6c9

File tree

1 file changed

+88
-12
lines changed

1 file changed

+88
-12
lines changed

Setup.iss

Lines changed: 88 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
#define MyAppSupportURL "https://github.com/itsmikethetech/Virtual-Display-Driver/issues"
66
#define MyAppURL "https://vdd.mikethetech.com"
77
#define InstallPath "C:\VirtualDisplayDriver"
8+
#define AppId "VirtualDisplayDriver"
89

910
[Setup]
1011
//no network storage installs
1112
AllowUNCPath=False
1213
AlwaysShowGroupOnReadyPage=yes
1314
AppendDefaultDirName=False
14-
AppId={{85ECF661-C369-443D-846B-285CFB698447}
15+
AppId={#AppId}
1516
AppName={#MyAppName}
1617
AppPublisher={#MyAppPublisher}
1718
AppPublisherURL={#MyAppURL}
@@ -112,7 +113,71 @@ var
112113
GPUList: TStringList;
113114
SelectedGPU: string;
114115
CurrentPageID: Integer;
115-
116+
IsAlreadyInstalled: Boolean;
117+
ResultCode: Integer;
118+
119+
function IsAppAlreadyInstalled(): Boolean;
120+
var
121+
InstalledBy: string;
122+
begin
123+
Result := RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\MikeTheTech\VirtualDisplayDriver', 'InstalledBy', InstalledBy);
124+
if Result then
125+
Log('App is already installed by: ' + InstalledBy)
126+
else
127+
Log('App is not installed');
128+
end;
129+
130+
function GetUninstallString(): string;
131+
var
132+
UninstallString: string;
133+
RegPath: string;
134+
begin
135+
RegPath := 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + '{#AppId}' + '_is1';
136+
137+
if RegQueryStringValue(HKEY_LOCAL_MACHINE, RegPath, 'UninstallString', UninstallString) then
138+
begin
139+
UninstallString := Trim(UninstallString);
140+
if (Length(UninstallString) > 1) and (UninstallString[1] = '"') and (UninstallString[Length(UninstallString)] = '"') then
141+
begin
142+
UninstallString := Copy(UninstallString, 2, Length(UninstallString) - 2);
143+
end;
144+
Result := UninstallString;
145+
end
146+
else
147+
begin
148+
Result := '';
149+
end;
150+
end;
151+
152+
153+
function AskToUninstall(): Boolean;
154+
var
155+
MsgResult: Integer;
156+
begin
157+
MsgResult := MsgBox('{#MyAppName} is already installed. Would you like to uninstall it?', mbConfirmation, MB_YESNO);
158+
Result := MsgResult = IDYES;
159+
end;
160+
161+
function TriggerWindowsUninstall(): Boolean;
162+
var
163+
UninstallString: string;
164+
ExecResult: Boolean;
165+
begin
166+
Result := False;
167+
UninstallString := GetUninstallString();
168+
169+
if UninstallString <> '' then
170+
begin
171+
ExecResult := Exec(UninstallString, '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
172+
if ExecResult and (ResultCode = 0) then
173+
Result := True;
174+
end
175+
else
176+
begin
177+
MsgBox('Unable to locate uninstallation information in Windows registry.', mbError, MB_OK);
178+
end;
179+
end;
180+
116181
procedure CheckLicenseAccepted(Sender: TObject);
117182
begin
118183
WizardForm.NextButton.Enabled :=
@@ -283,18 +348,28 @@ var
283348
isSilent: Boolean;
284349
285350
function InitializeSetup(): Boolean;
286-
var
287-
j: Integer;
288351
begin
289-
Result := True;
290-
IsSilent := False;
291-
for j := 1 to ParamCount do
352+
Result := True;
353+
354+
if IsAppAlreadyInstalled() then
292355
begin
293-
if (CompareText(ParamStr(j), '/verysilent') = 0) or
294-
(CompareText(ParamStr(j), '/silent') = 0) then
356+
if AskToUninstall() then
295357
begin
296-
IsSilent := True;
297-
Break;
358+
if TriggerWindowsUninstall() then
359+
begin
360+
MsgBox('{#MyAppName} was successfully uninstalled. The setup will now restart.', mbInformation, MB_OK);
361+
Result := True;
362+
end
363+
else
364+
begin
365+
MsgBox('Failed to uninstall {#MyAppName} using Windows uninstaller. Setup will now exit.', mbError, MB_OK);
366+
Result := False;
367+
end;
368+
end
369+
else
370+
begin
371+
MsgBox('Setup was canceled because {#MyAppName} is already installed.', mbInformation, MB_OK);
372+
Result := False;
298373
end;
299374
end;
300375
end;
@@ -303,7 +378,6 @@ procedure CurPageChanged(CurPageID: Integer);
303378
var
304379
I: Integer;
305380
begin
306-
// Automatically accept licenses if running in silent mode
307381
if IsSilent then
308382
begin
309383
for I := 0 to GetArrayLength(LicenseAcceptedRadioButtons) - 1 do
@@ -318,6 +392,8 @@ end;
318392
Root: HKLM; Subkey: "SOFTWARE\MikeTheTech"; Flags: uninsdeletekeyifempty
319393
Root: HKLM; Subkey: "SOFTWARE\MikeTheTech\VirtualDisplayDriver"; Flags: uninsdeletekeyifempty
320394
Root: HKLM; Subkey: "SOFTWARE\MikeTheTech\VirtualDisplayDriver"; ValueType: string; ValueName: "VDDPATH"; ValueData: "{app}"; Flags: uninsdeletevalue
395+
Root: HKLM; Subkey: "SOFTWARE\MikeTheTech\VirtualDisplayDriver"; ValueType: string; ValueName: "InstalledBy"; ValueData: "Installer"; Flags: uninsdeletevalue
396+
321397

322398
[Run]
323399
Filename: "{app}\install.bat"; Parameters: "{code:MergePar}"; WorkingDir: "{app}"; Flags: runascurrentuser runhidden waituntilterminated

0 commit comments

Comments
 (0)