Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

innosetup to start/stop tunnel service #180527

Merged
merged 21 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build/gulpfile.vscode.win32.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ function buildWin32Setup(arch, target) {
RegValueName: product.win32RegValueName,
ShellNameShort: product.win32ShellNameShort,
AppMutex: product.win32MutexName,
TunnelMutex: product.win32TunnelMutex,
TunnelServiceMutex: product.win32TunnelServiceMutex,
ApplicationName: product.applicationName,
Arch: arch,
AppId: { 'ia32': ia32AppId, 'x64': x64AppId, 'arm64': arm64AppId }[arch],
IncompatibleTargetAppId: { 'ia32': product.win32AppId, 'x64': product.win32x64AppId, 'arm64': product.win32arm64AppId }[arch],
Expand Down
100 changes: 81 additions & 19 deletions build/win32/code.iss
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ Name: "hungarian"; MessagesFile: "{#RepoDir}\build\win32\i18n\Default.hu.isl,{#R
Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl,{#RepoDir}\build\win32\i18n\messages.tr.isl" {#LocalizedLanguageFile("trk")}

[InstallDelete]
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: filesandordirs; Name: "{app}\resources\app\node_modules.asar.unpacked"; Check: IsNotUpdate
Type: files; Name: "{app}\resources\app\node_modules.asar"; Check: IsNotUpdate
Type: files; Name: "{app}\resources\app\Credits_45.0.2454.85.html"; Check: IsNotUpdate
Type: filesandordirs; Name: "{app}\resources\app\out"; Check: IsNotBackgroundUpdate
Type: filesandordirs; Name: "{app}\resources\app\plugins"; Check: IsNotBackgroundUpdate
Type: filesandordirs; Name: "{app}\resources\app\extensions"; Check: IsNotBackgroundUpdate
Type: filesandordirs; Name: "{app}\resources\app\node_modules"; Check: IsNotBackgroundUpdate
Type: filesandordirs; Name: "{app}\resources\app\node_modules.asar.unpacked"; Check: IsNotBackgroundUpdate
Type: files; Name: "{app}\resources\app\node_modules.asar"; Check: IsNotBackgroundUpdate
Type: files; Name: "{app}\resources\app\Credits_45.0.2454.85.html"; Check: IsNotBackgroundUpdate

[UninstallDelete]
Type: filesandordirs; Name: "{app}\_"
Expand Down Expand Up @@ -1299,6 +1299,16 @@ Root: {#SoftwareClassesRootKey}; Subkey: "Software\Classes\Drive\shell\{#RegValu
Root: {#EnvironmentRootKey}; Subkey: "{#EnvironmentKey}"; ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}\bin"; Tasks: addtopath; Check: NeedsAddPath(ExpandConstant('{app}\bin'))

[Code]
function IsBackgroundUpdate(): Boolean;
begin
Result := ExpandConstant('{param:update|false}') <> 'false';
end;

function IsNotBackgroundUpdate(): Boolean;
begin
Result := not IsBackgroundUpdate();
end;

// Don't allow installing conflicting architectures
function InitializeSetup(): Boolean;
var
Expand Down Expand Up @@ -1351,6 +1361,13 @@ begin
MsgBox('Please uninstall the ' + AltArch + '-bit version of {#NameShort} before installing this ' + ThisArch + '-bit version.', mbInformation, MB_OK);
end;
end;

if IsNotBackgroundUpdate() and CheckForMutexes('{#TunnelMutex}') then
begin
MsgBox('{#NameShort} is still running a tunnel. Please stop the tunnel before installing.', mbInformation, MB_OK);
Result := false
end;

end;

function WizardNotSilent(): Boolean;
Expand All @@ -1359,14 +1376,44 @@ begin
end;

// Updates
function IsBackgroundUpdate(): Boolean;

var
ShouldRestartTunnelService: Boolean;

procedure StopTunnelServiceIfNeeded();
var
StopServiceResultCode: Integer;
WaitCounter: Integer;
begin
Result := ExpandConstant('{param:update|false}') <> 'false';
ShouldRestartTunnelService := False;
if CheckForMutexes('{#TunnelServiceMutex}') then begin
// stop the tunnel service
Log('Stopping the tunnel service using ' + ExpandConstant('"{app}\bin\{#ApplicationName}.cmd"'));
ShellExec('', ExpandConstant('"{app}\bin\{#ApplicationName}.cmd"'), 'tunnel service uninstall', '', SW_HIDE, ewWaitUntilTerminated, StopServiceResultCode);

Log('Stopping the tunnel service completed with result code ' + IntToStr(StopServiceResultCode));

WaitCounter := 10;
while (WaitCounter > 0) and CheckForMutexes('{#TunnelServiceMutex}') do
begin
Log('Tunnel service is still running, waiting');
Sleep(500);
WaitCounter := WaitCounter - 1
end;
if CheckForMutexes('{#TunnelServiceMutex}') then
Log('Unable to stop tunnel service')
else
joaomoreno marked this conversation as resolved.
Show resolved Hide resolved
ShouldRestartTunnelService := True;
end
end;

function IsNotUpdate(): Boolean;

// called before the wizard checks for running application
function PrepareToInstall(var NeedsRestart: Boolean): String;
begin
Result := not IsBackgroundUpdate();
if IsNotBackgroundUpdate() then
StopTunnelServiceIfNeeded();
Result := ''
end;

// VS Code will create a flag file before the update starts (/update=C:\foo\bar)
Expand Down Expand Up @@ -1450,18 +1497,33 @@ end;
procedure CurStepChanged(CurStep: TSetupStep);
var
UpdateResultCode: Integer;
StartServiceResultCode: Integer;
begin
if IsBackgroundUpdate() and (CurStep = ssPostInstall) then
if CurStep = ssPostInstall then
begin
CreateMutex('{#AppMutex}-ready');

while (CheckForMutexes('{#AppMutex}')) do
if IsBackgroundUpdate() then
begin
Log('Application is still running, waiting');
Sleep(1000);
CreateMutex('{#AppMutex}-ready');

while (CheckForMutexes('{#AppMutex}')) do
begin
Log('Application is still running, waiting');
Sleep(1000)
end;

StopTunnelServiceIfNeeded();

Exec(ExpandConstant('{app}\tools\inno_updater.exe'), ExpandConstant('"{app}\{#ExeBasename}.exe" ' + BoolToStr(LockFileExists())), '', SW_SHOW, ewWaitUntilTerminated, UpdateResultCode);
end;

Exec(ExpandConstant('{app}\tools\inno_updater.exe'), ExpandConstant('"{app}\{#ExeBasename}.exe" ' + BoolToStr(LockFileExists())), '', SW_SHOW, ewWaitUntilTerminated, UpdateResultCode);
if ShouldRestartTunnelService then
begin
// start the tunnel service
Log('Restarting the tunnel service...');
ShellExec('', ExpandConstant('"{app}\bin\{#ApplicationName}.cmd"'), 'tunnel service install', '', SW_HIDE, ewWaitUntilTerminated, StartServiceResultCode);
Log('Starting the tunnel service completed with result code ' + IntToStr(StartServiceResultCode));
ShouldRestartTunnelService := False
end;
end;
end;

Expand Down Expand Up @@ -1545,4 +1607,4 @@ begin
#endif

Exec(ExpandConstant('{sys}\icacls.exe'), ExpandConstant('"{app}" /inheritancelevel:r ') + Permissions, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;
end;
4 changes: 2 additions & 2 deletions product.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"win32arm64UserAppId": "{{3AEBF0C8-F733-4AD4-BADE-FDB816D53D7B}",
"win32AppUserModelId": "Microsoft.CodeOSS",
"win32ShellNameShort": "C&ode - OSS",
"win32TunnelServiceMutex": "vscodetunnelserviceoss",
"win32TunnelMutex": "vscodetunneloss",
"win32TunnelServiceMutex": "vscodeoss-tunnelservice",
"win32TunnelMutex": "vscodeoss-tunnel",
"darwinBundleIdentifier": "com.visualstudio.code.oss",
"linuxIconName": "code-oss",
"licenseFileName": "LICENSE.txt",
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/update/electron-main/updateService.win32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class Win32UpdateService extends AbstractUpdateService {
this.availableUpdate.updateFilePath = path.join(cachePath, `CodeSetup-${this.productService.quality}-${update.version}.flag`);

await pfs.Promises.writeFile(this.availableUpdate.updateFilePath, 'flag');
const child = spawn(this.availableUpdate.packagePath, ['/verysilent', `/update="${this.availableUpdate.updateFilePath}"`, '/nocloseapplications', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
const child = spawn(this.availableUpdate.packagePath, ['/verysilent', '/log', `/update="${this.availableUpdate.updateFilePath}"`, '/nocloseapplications', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
detached: true,
stdio: ['ignore', 'ignore', 'ignore'],
windowsVerbatimArguments: true
Expand Down Expand Up @@ -241,7 +241,7 @@ export class Win32UpdateService extends AbstractUpdateService {
if (this.state.update.supportsFastUpdate && this.availableUpdate.updateFilePath) {
fs.unlinkSync(this.availableUpdate.updateFilePath);
} else {
spawn(this.availableUpdate.packagePath, ['/silent', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
spawn(this.availableUpdate.packagePath, ['/silent', '/log', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
detached: true,
stdio: ['ignore', 'ignore', 'ignore']
});
Expand Down