139 lines
6.4 KiB
Plaintext
139 lines
6.4 KiB
Plaintext
[Setup]
|
|
AppId={{E914E883-46F9-4B82-B27F-BDB2B40DCC90}
|
|
AppName=Agent Workbench
|
|
AppVersion={#Version}
|
|
DefaultDirName={localappdata}\Programs\AgentWorkbench
|
|
DefaultGroupName=Agent Workbench
|
|
PrivilegesRequired=lowest
|
|
ArchitecturesAllowed=x64compatible
|
|
ArchitecturesInstallIn64BitMode=x64compatible
|
|
DisableProgramGroupPage=yes
|
|
UsePreviousAppDir=yes
|
|
OutputDir={#OutputRoot}
|
|
OutputBaseFilename={#OutputName}
|
|
SetupIconFile={#PortableRoot}\public\workbench-icon.ico
|
|
UninstallDisplayIcon={app}\AgentWorkbench.exe
|
|
Compression=lzma2/fast
|
|
SolidCompression=yes
|
|
CloseApplications=no
|
|
RestartApplications=no
|
|
ChangesAssociations=no
|
|
WizardStyle=modern
|
|
Uninstallable=yes
|
|
|
|
[Files]
|
|
Source: "{#PortableRoot}\runtime\node.exe"; DestName: "awb-install-node.exe"; Flags: dontcopy
|
|
Source: "{#PortableRoot}\dist-server\install-manager.mjs"; DestName: "awb-install-manager.mjs"; Flags: dontcopy
|
|
Source: "{#PortableRoot}\*"; DestDir: "{app}\versions\{#VersionDirectory}"; Flags: ignoreversion recursesubdirs createallsubdirs
|
|
Source: "{#PortableRoot}\AgentWorkbench.exe"; DestDir: "{app}"; Flags: onlyifdoesntexist
|
|
|
|
[Icons]
|
|
Name: "{group}\Agent Workbench"; Filename: "{app}\AgentWorkbench.exe"
|
|
Name: "{userdesktop}\Agent Workbench"; Filename: "{app}\AgentWorkbench.exe"; Tasks: desktopicon
|
|
|
|
[Tasks]
|
|
Name: "desktopicon"; Description: "创建桌面快捷方式"; Flags: unchecked
|
|
|
|
[Run]
|
|
Filename: "{app}\AgentWorkbench.exe"; Description: "打开 Agent Workbench"; Flags: nowait postinstall skipifsilent; Check: WasActivated
|
|
|
|
[Code]
|
|
var DataRoot: String; Port: String; StageOnly: Boolean; Activated: Boolean; ActivationFailed: Boolean;
|
|
OperationId: String; LastManagerError: String; PreflightPassed: Boolean; ManagerFinished: Boolean;
|
|
ManagerPage: TOutputProgressWizardPage;
|
|
|
|
function Quoted(Value: String): String;
|
|
begin
|
|
if (Pos('"', Value) > 0) or (Pos(#13, Value) > 0) or (Pos(#10, Value) > 0) then RaiseException('安装路径无效。');
|
|
Result := '"' + Value + '"';
|
|
end;
|
|
|
|
procedure LoadOptions;
|
|
begin
|
|
DataRoot := ExpandConstant('{param:DATA_ROOT|{localappdata}\AgentWorkbench}');
|
|
Port := ExpandConstant('{param:PORT|4318}');
|
|
StageOnly := ExpandConstant('{param:STAGE_ONLY|0}') = '1';
|
|
OperationId := GetSHA256OfString(ExpandConstant('{tmp}') + GetDateTimeString('yyyy-mm-dd hh:nn:ss', '-', ':'));
|
|
end;
|
|
|
|
procedure ManagerLog(const S: String; const Error, FirstLine: Boolean);
|
|
var Value: String; Separator: Integer;
|
|
begin
|
|
Log(S);
|
|
if Error and (LastManagerError = '') then LastManagerError := S;
|
|
if Pos('AWBERROR ', S) = 1 then LastManagerError := Copy(S, 10, Length(S));
|
|
if Pos('AWBPROGRESS ', S) = 1 then ManagerPage.SetText(Copy(S, 13, Length(S)), '正在核对实际文件和原状态;阶段变化来自安装进程。请保持此窗口打开。');
|
|
if Pos('AWBFILES ', S) = 1 then begin
|
|
Value := Copy(S, 10, Length(S)); Separator := Pos('/', Value);
|
|
ManagerPage.ProgressBar.Visible := Separator > 0;
|
|
if Separator > 0 then ManagerPage.SetProgress(StrToIntDef(Copy(Value, 1, Separator - 1), 0), StrToIntDef(Copy(Value, Separator + 1, Length(Value)), 1));
|
|
end;
|
|
end;
|
|
|
|
function RunManager(Command: String; Candidate: Boolean): Boolean;
|
|
var Parameters: String; ExitCode: Integer;
|
|
begin
|
|
LastManagerError := '';
|
|
Parameters := Quoted(ExpandConstant('{tmp}\awb-install-manager.mjs')) + ' ' + Command +
|
|
' --install-root ' + Quoted(ExpandConstant('{app}')) + ' --data-root ' + Quoted(DataRoot) + ' --port ' + Quoted(Port) +
|
|
' --operation-id ' + Quoted(OperationId) + ' --expected-manifest-sha256 {#ManifestSha256}';
|
|
if Candidate then Parameters := Parameters + ' --candidate-root ' + Quoted(ExpandConstant('{app}\versions\{#VersionDirectory}'));
|
|
if StageOnly then Parameters := Parameters + ' --stage-only';
|
|
if ManagerPage = nil then ManagerPage := CreateOutputProgressPage('Agent Workbench 版本更新', '核对原版本、当前阶段与实际结果');
|
|
ManagerPage.SetText('准备核对安装操作', '操作记录:' + ExpandConstant('{app}') + '\.installation\progress-' + OperationId + '.json');
|
|
ManagerPage.ProgressBar.Visible := False;
|
|
if Command <> 'cancel' then ManagerPage.Show;
|
|
WizardForm.CancelButton.Enabled := False;
|
|
try
|
|
Result := ExecAndLogOutput(ExpandConstant('{tmp}\awb-install-node.exe'), Parameters, ExpandConstant('{tmp}'), SW_HIDE, ewWaitUntilTerminated, ExitCode, @ManagerLog) and (ExitCode = 0);
|
|
if not Result and (LastManagerError = '') then LastManagerError := '安装进程未返回成功结果;请保留安装日志及原操作收据。';
|
|
finally
|
|
WizardForm.CancelButton.Enabled := True;
|
|
if Command <> 'cancel' then ManagerPage.Hide;
|
|
end;
|
|
end;
|
|
|
|
function PrepareToInstall(var NeedsRestart: Boolean): String;
|
|
begin
|
|
LoadOptions;
|
|
ExtractTemporaryFile('awb-install-node.exe'); ExtractTemporaryFile('awb-install-manager.mjs');
|
|
if DirExists(ExpandConstant('{app}\versions\{#VersionDirectory}')) then begin
|
|
Result := '该独立版本目录已经存在。请保留原版本,使用新的安装候选。'; exit;
|
|
end;
|
|
PreflightPassed := RunManager('preflight', False);
|
|
if not PreflightPassed then Result := '安装预检未通过:' + LastManagerError + #13#10 + '原程序和用户数据保留。日志及阶段记录见 .installation 目录。';
|
|
end;
|
|
|
|
procedure CurStepChanged(CurStep: TSetupStep);
|
|
begin
|
|
if CurStep = ssPostInstall then begin
|
|
ActivationFailed := True;
|
|
if not RunManager('activate', True) then RaiseException('候选激活未完成:' + LastManagerError + #13#10 + '请保留 .installation 原操作收据,核对当前指针和回退结果。');
|
|
ActivationFailed := False;
|
|
Activated := not StageOnly;
|
|
ManagerFinished := True;
|
|
end;
|
|
end;
|
|
|
|
procedure DeinitializeSetup;
|
|
begin
|
|
if PreflightPassed and not ManagerFinished and not ActivationFailed then RunManager('cancel', False);
|
|
end;
|
|
|
|
function GetCustomSetupExitCode: Integer;
|
|
begin
|
|
if ActivationFailed then Result := 8 else Result := 0;
|
|
end;
|
|
|
|
function WasActivated: Boolean;
|
|
begin Result := Activated; end;
|
|
|
|
function InitializeUninstall: Boolean;
|
|
var ExitCode: Integer;
|
|
begin
|
|
{ The native bootstrap verifies the entire registered immutable release before
|
|
invoking its fixed uninstall manager. No installed script is executed first. }
|
|
Result := Exec(ExpandConstant('{app}\AgentWorkbench.exe'), '--hidden-window --uninstall-preflight', ExpandConstant('{app}'), SW_HIDE, ewWaitUntilTerminated, ExitCode) and (ExitCode = 0);
|
|
if not Result then MsgBox('卸载预检未通过。请先关闭桌面窗口并等待活动结束;原程序和用户数据保留。', mbError, MB_OK);
|
|
end;
|