Skip to content

Commit 4b96f2c

Browse files
committed
Improved service management code to better handle edge cases.
1 parent 50c0dac commit 4b96f2c

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

setup.iss

+26-14
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ ArchitecturesInstallIn64BitMode=x64
2727
MinVersion=6.0
2828

2929
[Files]
30-
Source: "hectane-386.exe"; DestDir: "{app}"; DestName: "{#AppExe}"; Check: not Is64BitInstallMode
31-
Source: "hectane-amd64.exe"; DestDir: "{app}"; DestName: "{#AppExe}"; Check: Is64BitInstallMode
30+
Source: "hectane-386.exe"; DestDir: "{app}"; DestName: "{#AppExe}"; Check: not Is64BitInstallMode; BeforeInstall: PreInstall; AfterInstall: PostInstall
31+
Source: "hectane-amd64.exe"; DestDir: "{app}"; DestName: "{#AppExe}"; Check: Is64BitInstallMode; BeforeInstall: PreInstall; AfterInstall: PostInstall
3232

3333
[Code]
3434
@@ -42,21 +42,33 @@ begin
4242
Result := Exec(ExpandConstant('{app}\{#AppExe}'), Command, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
4343
end;
4444
45-
procedure CurStepChanged(CurStep: TSetupStep);
45+
// The service should only be installed if the executable didn't exist before
46+
// installation. A global variable is required to keep track of this so that
47+
// after installation, the appropriate action can be taken.
48+
49+
var
50+
FileExisted: Boolean;
51+
52+
procedure PreInstall();
53+
begin
54+
FileExisted := FileExists(ExpandConstant('{app}\{#AppExe}'));
55+
end;
56+
57+
// The service will automatically be stopped and restarted by the Restart
58+
// Manager if it was running prior to installation.
59+
60+
procedure PostInstall();
4661
begin
47-
if CurStep = ssPostInstall then
62+
if not FileExisted then
4863
begin
49-
if not RmSessionStarted() then
64+
WizardForm.StatusLabel.Caption := 'Installing & starting service...';
65+
if ServiceCommand(ExpandConstant('-directory "{app}\data" install')) then
5066
begin
51-
WizardForm.StatusLabel.Caption := 'Installing & starting service...';
52-
if ServiceCommand(ExpandConstant('-directory "{app}\data" install')) then
53-
begin
54-
if not ServiceCommand('start') then
55-
MsgBox('Unable to start service.', mbError, MB_OK);
56-
end
57-
else
58-
MsgBox('Unable to install service.', mbError, MB_OK);
59-
end;
67+
if not ServiceCommand('start') then
68+
MsgBox('Unable to start service.', mbError, MB_OK);
69+
end
70+
else
71+
MsgBox('Unable to install service.', mbError, MB_OK);
6072
end;
6173
end;
6274

0 commit comments

Comments
 (0)