fix: remove unused appx package (#258741)

* fix: remove unused appx package

* fix: inno compilation

* chore: reduce the number of remove and add commands
This commit is contained in:
Robo 2025-07-30 21:13:27 +09:00 committed by GitHub
parent 64b6f08dc7
commit 73f08941a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 5 deletions

View File

@ -114,6 +114,7 @@ function buildWin32Setup(arch, target) {
if (quality !== 'exploration') {
definitions['AppxPackage'] = `${quality === 'stable' ? 'code' : 'code_insider'}_${arch}.appx`;
definitions['AppxPackageDll'] = `${quality === 'stable' ? 'code' : 'code_insider'}_explorer_command_${arch}.dll`;
definitions['AppxPackageName'] = `${product.win32AppUserModelId}`;
}

View File

@ -96,7 +96,8 @@ Source: "tools\*"; DestDir: "{app}\tools"; Flags: ignoreversion
Source: "{#ProductJsonPath}"; DestDir: "{code:GetDestDir}\resources\app"; Flags: ignoreversion
#ifdef AppxPackageName
#if "user" == InstallTarget
Source: "appx\*"; DestDir: "{app}\appx"; BeforeInstall: RemoveAppxPackage; AfterInstall: AddAppxPackage; Flags: ignoreversion; Check: IsWindows11OrLater
Source: "appx\{#AppxPackage}"; DestDir: "{app}\appx"; BeforeInstall: RemoveAppxPackage; Flags: ignoreversion; Check: IsWindows11OrLater
Source: "appx\{#AppxPackageDll}"; DestDir: "{app}\appx"; AfterInstall: AddAppxPackage; Flags: ignoreversion; Check: IsWindows11OrLater
#endif
#endif
@ -1479,11 +1480,12 @@ begin
Log(S);
end;
function AppxPackageInstalled(var ResultCode: Integer): Boolean;
function AppxPackageInstalled(const name: String; var ResultCode: Integer): Boolean;
begin
AppxPackageFullname := '';
try
ExecAndLogOutput('powershell.exe', '-NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -Command ' + AddQuotes('Get-AppxPackage -Name ''{#AppxPackageName}'' | Select-Object -ExpandProperty PackageFullName'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode, @ExecAndGetFirstLineLog);
Log('Get-AppxPackage for package with name: ' + name);
ExecAndLogOutput('powershell.exe', '-NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -Command ' + AddQuotes('Get-AppxPackage -Name ''' + name + ''' | Select-Object -ExpandProperty PackageFullName'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode, @ExecAndGetFirstLineLog);
except
Log(GetExceptionMessage);
end;
@ -1497,8 +1499,10 @@ procedure AddAppxPackage();
var
AddAppxPackageResultCode: Integer;
begin
if not AppxPackageInstalled(AddAppxPackageResultCode) then begin
if not AppxPackageInstalled(ExpandConstant('{#AppxPackageName}'), AddAppxPackageResultCode) then begin
Log('Installing appx ' + AppxPackageFullname + ' ...');
ShellExec('', 'powershell.exe', '-NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -Command ' + AddQuotes('Add-AppxPackage -Path ''' + ExpandConstant('{app}\appx\{#AppxPackage}') + ''' -ExternalLocation ''' + ExpandConstant('{app}\appx') + ''''), '', SW_HIDE, ewWaitUntilTerminated, AddAppxPackageResultCode);
Log('Add-AppxPackage complete.');
end;
end;
@ -1506,8 +1510,18 @@ procedure RemoveAppxPackage();
var
RemoveAppxPackageResultCode: Integer;
begin
if AppxPackageInstalled(RemoveAppxPackageResultCode) then begin
// Remove the old context menu package
// Following condition can be removed after two versions.
if QualityIsInsiders() and AppxPackageInstalled('Microsoft.VSCodeInsiders', RemoveAppxPackageResultCode) then begin
Log('Deleting old appx ' + AppxPackageFullname + ' installation...');
ShellExec('', 'powershell.exe', '-NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -Command ' + AddQuotes('Remove-AppxPackage -Package ''' + AppxPackageFullname + ''''), '', SW_HIDE, ewWaitUntilTerminated, RemoveAppxPackageResultCode);
DeleteFile(ExpandConstant('{app}\appx\code_insiders_explorer_{#Arch}.appx'));
DeleteFile(ExpandConstant('{app}\appx\code_insiders_explorer_command.dll'));
end;
if AppxPackageInstalled(ExpandConstant('{#AppxPackageName}'), RemoveAppxPackageResultCode) then begin
Log('Removing current ' + AppxPackageFullname + ' appx installation...');
ShellExec('', 'powershell.exe', '-NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -Command ' + AddQuotes('Remove-AppxPackage -Package ''' + AppxPackageFullname + ''''), '', SW_HIDE, ewWaitUntilTerminated, RemoveAppxPackageResultCode);
Log('Remove-AppxPackage for current appx installation complete.');
end;
end;
#endif