mirror of
https://github.com/nini22P/iris.git
synced 2026-09-03 06:24:07 +08:00
feat: close running processes during update or uninstall on Windows
This commit is contained in:
79
inno.iss
79
inno.iss
@@ -8,6 +8,8 @@
|
||||
#define MyAppExeName "iris.exe"
|
||||
#define MyAppAssocName MyAppPublisher + "." + MyAppName + ".AssocFile"
|
||||
#define MyAppDesc "Iris Media Player"
|
||||
#define MySetupMutex "iris_player"
|
||||
#define MyProcessName "iris"
|
||||
|
||||
[Setup]
|
||||
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
|
||||
@@ -37,6 +39,8 @@ OutputDir=build\windows\x64\runner\Release
|
||||
OutputBaseFilename=Iris-windows-installer
|
||||
SolidCompression=yes
|
||||
WizardStyle=modern
|
||||
CloseApplications=force
|
||||
SetupMutex={#MySetupMutex}
|
||||
|
||||
[Languages]
|
||||
Name: "english"; MessagesFile: "windows\inno-languages\English.isl"
|
||||
@@ -150,10 +154,6 @@ Root: HKLM; Subkey: "Software\{#MyAppPublisher}\{#MyAppName}\Capabilities"; Valu
|
||||
Root: HKLM; Subkey: "Software\Microsoft\Windows\CurrentVersion\App Paths\{#MyAppExeName}"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName}"; Flags: uninsdeletekey
|
||||
Root: HKLM; Subkey: "Software\Microsoft\Windows\CurrentVersion\App Paths\{#MyAppExeName}"; ValueType: string; ValueName: "Path"; ValueData: "{app}"
|
||||
|
||||
[UninstallDelete]
|
||||
Type: filesandordirs; Name: "{app}\*"
|
||||
Type: filesandordirs; Name: "{app}"
|
||||
|
||||
[Icons]
|
||||
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
|
||||
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
|
||||
@@ -161,3 +161,74 @@ Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: de
|
||||
[Run]
|
||||
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
|
||||
|
||||
[Code]
|
||||
function ReadFileContent(const FileName: String): String;
|
||||
var
|
||||
StringList: TStringList;
|
||||
begin
|
||||
Result := '';
|
||||
StringList := TStringList.Create;
|
||||
try
|
||||
StringList.LoadFromFile(FileName);
|
||||
Result := StringList.Text;
|
||||
finally
|
||||
StringList.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function GetProcessPIDs(const ProcessName: string): String;
|
||||
var
|
||||
ResultCode: Integer;
|
||||
Cmd: String;
|
||||
OutputFile: String;
|
||||
begin
|
||||
OutputFile := ExpandConstant('{tmp}\..\pid_output.txt');
|
||||
Cmd := '-Command "Get-Process -Name ''' + ProcessName + ''' | ForEach-Object { if ($_.Path -and (Test-Path (Join-Path (Split-Path $_.Path) ''libass.dll''))) { $_.Id } } > ''' + OutputFile + '''"';
|
||||
if Exec('powershell.exe', Cmd, '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
|
||||
begin
|
||||
Result := ReadFileContent(OutputFile);
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result := '';
|
||||
end;
|
||||
if FileExists(OutputFile) then
|
||||
DeleteFile(OutputFile);
|
||||
end;
|
||||
|
||||
function InitializeUninstall(): Boolean;
|
||||
var
|
||||
ErrorCode: Integer;
|
||||
UserResponse: Integer;
|
||||
PIDs: String;
|
||||
PIDList: TStringList;
|
||||
i: Integer;
|
||||
begin
|
||||
PIDs := GetProcessPIDs('{#MyProcessName}');
|
||||
|
||||
if PIDs <> '' then
|
||||
begin
|
||||
UserResponse := MsgBox(FmtMessage(CustomMessage('CloseRunningAppToContinueUninstall'), ['{#MyAppName}']), mbConfirmation, MB_YESNO);
|
||||
|
||||
if UserResponse = IDNO then
|
||||
begin
|
||||
Result := False;
|
||||
Exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
PIDList := TStringList.Create;
|
||||
try
|
||||
PIDList.CommaText := PIDs;
|
||||
for i := 0 to PIDList.Count - 1 do
|
||||
begin
|
||||
ShellExec('open', 'taskkill.exe', '/f /pid ' + PIDList[i], '', SW_HIDE, ewNoWait, ErrorCode);
|
||||
end;
|
||||
finally
|
||||
PIDList.Free;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
@@ -401,3 +401,5 @@ AssocingFileExtension=正在将 %2 文件扩展名与 %1 建立关联...
|
||||
AutoStartProgramGroupDescription=启动:
|
||||
AutoStartProgram=自动启动 %1
|
||||
AddonHostProgramNotFound=您选择的文件夹中无法找到 %1。%n%n您要继续吗?
|
||||
|
||||
CloseRunningAppToContinueUninstall=%1 当前正在运行。需要先将其关闭才能继续卸载。是否立即关闭?
|
||||
@@ -389,3 +389,5 @@ AssocingFileExtension=Associating %1 with the %2 file extension...
|
||||
AutoStartProgramGroupDescription=Startup:
|
||||
AutoStartProgram=Automatically start %1
|
||||
AddonHostProgramNotFound=%1 could not be located in the folder you selected.%n%nDo you want to continue anyway?
|
||||
|
||||
CloseRunningAppToContinueUninstall=%1 is currently running. It needs to be closed before the uninstallation can continue. Do you want to close now?
|
||||
|
||||
Reference in New Issue
Block a user