Skip to content

Commit 42fcfb8

Browse files
authored
innosetup to start/stop tunnel service (microsoft#180527)
* innosetup to start/stop tunnel service * better messages for tunnel still running * fix error * more logs * add '/log' * update * fix * update * add kill & timeout wait * stop service in PrepareToInstall * non-background: check for tunnel mutex when wizard starts * polish tunnel mutex names, prompt if tunnel is still running
1 parent b930d45 commit 42fcfb8

File tree

4 files changed

+88
-23
lines changed

4 files changed

+88
-23
lines changed

build/gulpfile.vscode.win32.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ function buildWin32Setup(arch, target) {
9999
RegValueName: product.win32RegValueName,
100100
ShellNameShort: product.win32ShellNameShort,
101101
AppMutex: product.win32MutexName,
102+
TunnelMutex: product.win32TunnelMutex,
103+
TunnelServiceMutex: product.win32TunnelServiceMutex,
104+
ApplicationName: product.applicationName,
102105
Arch: arch,
103106
AppId: { 'ia32': ia32AppId, 'x64': x64AppId, 'arm64': arm64AppId }[arch],
104107
IncompatibleTargetAppId: { 'ia32': product.win32AppId, 'x64': product.win32x64AppId, 'arm64': product.win32arm64AppId }[arch],

build/win32/code.iss

Lines changed: 81 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ Name: "hungarian"; MessagesFile: "{#RepoDir}\build\win32\i18n\Default.hu.isl,{#R
6262
Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl,{#RepoDir}\build\win32\i18n\messages.tr.isl" {#LocalizedLanguageFile("trk")}
6363

6464
[InstallDelete]
65-
Type: filesandordirs; Name: "{app}\resources\app\out"; Check: IsNotUpdate
66-
Type: filesandordirs; Name: "{app}\resources\app\plugins"; Check: IsNotUpdate
67-
Type: filesandordirs; Name: "{app}\resources\app\extensions"; Check: IsNotUpdate
68-
Type: filesandordirs; Name: "{app}\resources\app\node_modules"; Check: IsNotUpdate
69-
Type: filesandordirs; Name: "{app}\resources\app\node_modules.asar.unpacked"; Check: IsNotUpdate
70-
Type: files; Name: "{app}\resources\app\node_modules.asar"; Check: IsNotUpdate
71-
Type: files; Name: "{app}\resources\app\Credits_45.0.2454.85.html"; Check: IsNotUpdate
65+
Type: filesandordirs; Name: "{app}\resources\app\out"; Check: IsNotBackgroundUpdate
66+
Type: filesandordirs; Name: "{app}\resources\app\plugins"; Check: IsNotBackgroundUpdate
67+
Type: filesandordirs; Name: "{app}\resources\app\extensions"; Check: IsNotBackgroundUpdate
68+
Type: filesandordirs; Name: "{app}\resources\app\node_modules"; Check: IsNotBackgroundUpdate
69+
Type: filesandordirs; Name: "{app}\resources\app\node_modules.asar.unpacked"; Check: IsNotBackgroundUpdate
70+
Type: files; Name: "{app}\resources\app\node_modules.asar"; Check: IsNotBackgroundUpdate
71+
Type: files; Name: "{app}\resources\app\Credits_45.0.2454.85.html"; Check: IsNotBackgroundUpdate
7272

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

13011301
[Code]
1302+
function IsBackgroundUpdate(): Boolean;
1303+
begin
1304+
Result := ExpandConstant('{param:update|false}') <> 'false';
1305+
end;
1306+
1307+
function IsNotBackgroundUpdate(): Boolean;
1308+
begin
1309+
Result := not IsBackgroundUpdate();
1310+
end;
1311+
13021312
// Don't allow installing conflicting architectures
13031313
function InitializeSetup(): Boolean;
13041314
var
@@ -1351,6 +1361,13 @@ begin
13511361
MsgBox('Please uninstall the ' + AltArch + '-bit version of {#NameShort} before installing this ' + ThisArch + '-bit version.', mbInformation, MB_OK);
13521362
end;
13531363
end;
1364+
1365+
if IsNotBackgroundUpdate() and CheckForMutexes('{#TunnelMutex}') then
1366+
begin
1367+
MsgBox('{#NameShort} is still running a tunnel. Please stop the tunnel before installing.', mbInformation, MB_OK);
1368+
Result := false
1369+
end;
1370+
13541371
end;
13551372
13561373
function WizardNotSilent(): Boolean;
@@ -1359,14 +1376,44 @@ begin
13591376
end;
13601377
13611378
// Updates
1362-
function IsBackgroundUpdate(): Boolean;
1379+
1380+
var
1381+
ShouldRestartTunnelService: Boolean;
1382+
1383+
procedure StopTunnelServiceIfNeeded();
1384+
var
1385+
StopServiceResultCode: Integer;
1386+
WaitCounter: Integer;
13631387
begin
1364-
Result := ExpandConstant('{param:update|false}') <> 'false';
1388+
ShouldRestartTunnelService := False;
1389+
if CheckForMutexes('{#TunnelServiceMutex}') then begin
1390+
// stop the tunnel service
1391+
Log('Stopping the tunnel service using ' + ExpandConstant('"{app}\bin\{#ApplicationName}.cmd"'));
1392+
ShellExec('', ExpandConstant('"{app}\bin\{#ApplicationName}.cmd"'), 'tunnel service uninstall', '', SW_HIDE, ewWaitUntilTerminated, StopServiceResultCode);
1393+
1394+
Log('Stopping the tunnel service completed with result code ' + IntToStr(StopServiceResultCode));
1395+
1396+
WaitCounter := 10;
1397+
while (WaitCounter > 0) and CheckForMutexes('{#TunnelServiceMutex}') do
1398+
begin
1399+
Log('Tunnel service is still running, waiting');
1400+
Sleep(500);
1401+
WaitCounter := WaitCounter - 1
1402+
end;
1403+
if CheckForMutexes('{#TunnelServiceMutex}') then
1404+
Log('Unable to stop tunnel service')
1405+
else
1406+
ShouldRestartTunnelService := True;
1407+
end
13651408
end;
13661409
1367-
function IsNotUpdate(): Boolean;
1410+
1411+
// called before the wizard checks for running application
1412+
function PrepareToInstall(var NeedsRestart: Boolean): String;
13681413
begin
1369-
Result := not IsBackgroundUpdate();
1414+
if IsNotBackgroundUpdate() then
1415+
StopTunnelServiceIfNeeded();
1416+
Result := ''
13701417
end;
13711418
13721419
// VS Code will create a flag file before the update starts (/update=C:\foo\bar)
@@ -1450,18 +1497,33 @@ end;
14501497
procedure CurStepChanged(CurStep: TSetupStep);
14511498
var
14521499
UpdateResultCode: Integer;
1500+
StartServiceResultCode: Integer;
14531501
begin
1454-
if IsBackgroundUpdate() and (CurStep = ssPostInstall) then
1502+
if CurStep = ssPostInstall then
14551503
begin
1456-
CreateMutex('{#AppMutex}-ready');
1457-
1458-
while (CheckForMutexes('{#AppMutex}')) do
1504+
if IsBackgroundUpdate() then
14591505
begin
1460-
Log('Application is still running, waiting');
1461-
Sleep(1000);
1506+
CreateMutex('{#AppMutex}-ready');
1507+
1508+
while (CheckForMutexes('{#AppMutex}')) do
1509+
begin
1510+
Log('Application is still running, waiting');
1511+
Sleep(1000)
1512+
end;
1513+
1514+
StopTunnelServiceIfNeeded();
1515+
1516+
Exec(ExpandConstant('{app}\tools\inno_updater.exe'), ExpandConstant('"{app}\{#ExeBasename}.exe" ' + BoolToStr(LockFileExists())), '', SW_SHOW, ewWaitUntilTerminated, UpdateResultCode);
14621517
end;
14631518
1464-
Exec(ExpandConstant('{app}\tools\inno_updater.exe'), ExpandConstant('"{app}\{#ExeBasename}.exe" ' + BoolToStr(LockFileExists())), '', SW_SHOW, ewWaitUntilTerminated, UpdateResultCode);
1519+
if ShouldRestartTunnelService then
1520+
begin
1521+
// start the tunnel service
1522+
Log('Restarting the tunnel service...');
1523+
ShellExec('', ExpandConstant('"{app}\bin\{#ApplicationName}.cmd"'), 'tunnel service install', '', SW_HIDE, ewWaitUntilTerminated, StartServiceResultCode);
1524+
Log('Starting the tunnel service completed with result code ' + IntToStr(StartServiceResultCode));
1525+
ShouldRestartTunnelService := False
1526+
end;
14651527
end;
14661528
end;
14671529
@@ -1545,4 +1607,4 @@ begin
15451607
#endif
15461608
15471609
Exec(ExpandConstant('{sys}\icacls.exe'), ExpandConstant('"{app}" /inheritancelevel:r ') + Permissions, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
1548-
end;
1610+
end;

product.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"win32arm64UserAppId": "{{3AEBF0C8-F733-4AD4-BADE-FDB816D53D7B}",
2525
"win32AppUserModelId": "Microsoft.CodeOSS",
2626
"win32ShellNameShort": "C&ode - OSS",
27-
"win32TunnelServiceMutex": "vscodetunnelserviceoss",
28-
"win32TunnelMutex": "vscodetunneloss",
27+
"win32TunnelServiceMutex": "vscodeoss-tunnelservice",
28+
"win32TunnelMutex": "vscodeoss-tunnel",
2929
"darwinBundleIdentifier": "com.visualstudio.code.oss",
3030
"linuxIconName": "code-oss",
3131
"licenseFileName": "LICENSE.txt",

src/vs/platform/update/electron-main/updateService.win32.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export class Win32UpdateService extends AbstractUpdateService {
212212
this.availableUpdate.updateFilePath = path.join(cachePath, `CodeSetup-${this.productService.quality}-${update.version}.flag`);
213213

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

0 commit comments

Comments
 (0)