update inno updater, selectively launch code after update

This commit is contained in:
Joao Moreno
2018-01-18 14:56:13 +01:00
parent 460e00c575
commit 011c4f9b15
2 changed files with 25 additions and 14 deletions

View File

@@ -47,11 +47,11 @@ Name: "simplifiedChinese"; MessagesFile: "{#RepoDir}\build\win32\i18n\Default.zh
Name: "traditionalChinese"; MessagesFile: "{#RepoDir}\build\win32\i18n\Default.zh-tw.isl,{#RepoDir}\build\win32\i18n\messages.zh-tw.isl" {#LocalizedLanguageFile("cht")}
[InstallDelete]
Type: filesandordirs; Name: "{app}\resources\app\out"
Type: filesandordirs; Name: "{app}\resources\app\plugins"
Type: filesandordirs; Name: "{app}\resources\app\extensions"
Type: filesandordirs; Name: "{app}\resources\app\node_modules"
Type: files; Name: "{app}\resources\app\Credits_45.0.2454.85.html"
Type: filesandordirs; Name: "{app}\resources\app\out"; Check: IsNotUpdate
Type: filesandordirs; Name: "{app}\resources\app\plugins"; Check: IsNotUpdate
Type: filesandordirs; Name: "{app}\resources\app\extensions"; Check: IsNotUpdate
Type: filesandordirs; Name: "{app}\resources\app\node_modules"; Check: IsNotUpdate
Type: files; Name: "{app}\resources\app\Credits_45.0.2454.85.html"; Check: IsNotUpdate
[UninstallDelete]
Type: filesandordirs; Name: "{app}\_"
@@ -76,7 +76,7 @@ Name: "{commondesktop}\{#NameLong}"; Filename: "{app}\{#ExeBasename}.exe"; Tasks
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#NameLong}"; Filename: "{app}\{#ExeBasename}.exe"; Tasks: quicklaunchicon; AppUserModelID: "{#AppUserId}"
[Run]
Filename: "{app}\{#ExeBasename}.exe"; Description: "{cm:LaunchProgram,{#NameLong}}"; Tasks: runcode; Flags: nowait postinstall; Check: WizardSilent
Filename: "{app}\{#ExeBasename}.exe"; Description: "{cm:LaunchProgram,{#NameLong}}"; Tasks: runcode; Flags: nowait postinstall; Check: ShouldRunAfterUpdate
Filename: "{app}\{#ExeBasename}.exe"; Description: "{cm:LaunchProgram,{#NameLong}}"; Flags: nowait postinstall; Check: WizardNotSilent
[Registry]
@@ -963,7 +963,23 @@ end;
// Updates
function IsUpdate(): Boolean;
begin
Result := ExpandConstant('{param:update|false}') = 'true';
Result := ExpandConstant('{param:update|false}') <> 'false';
end;
function IsNotUpdate(): Boolean;
begin
Result := not IsUpdate();
end;
// VS Code will create a flag file before the update starts (/update=C:\foo\bar)
// - if the file exists at this point, the user quit Code before the update finished, so don't start Code after update
// - otherwise, the user has accepted to apply the update and Code should start
function ShouldRunAfterUpdate(): Boolean;
begin
if IsUpdate() then
Result := not FileExists(ExpandConstant('{param:update}'))
else
Result := False;
end;
function GetAppMutex(Value: string): string;
@@ -986,7 +1002,7 @@ procedure CurStepChanged(CurStep: TSetupStep);
var
UpdateResultCode: Integer;
begin
if (CurStep = ssPostInstall) and (ExpandConstant('{param:update|false}') = 'true') then
if IsUpdate() and (CurStep = ssPostInstall) then
begin
CreateMutex('{#AppMutex}-ready');
@@ -996,12 +1012,7 @@ begin
Sleep(1000);
end;
Sleep(1000);
if Exec(ExpandConstant('{app}\inno_updater.exe'), ExpandConstant('--apply-update _ "{app}\unins000.dat"'), '', SW_SHOW, ewWaitUntilTerminated, UpdateResultCode) then
Log('Update applied successfully!')
else
Log('Failed to apply update!');
Exec(ExpandConstant('{app}\inno_updater.exe'), ExpandConstant('--apply-update _ "{app}\unins000.dat"'), '', SW_SHOW, ewWaitUntilTerminated, UpdateResultCode);
end;
end;