feat: ship lean runtime bundles and attributable update progress
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
import { InstallationManager } from '../core/desktop/install-manager.mjs';
|
||||
const args = process.argv.slice(2), command = args.shift(), options = {};
|
||||
if (!['preflight', 'activate', 'uninstall'].includes(command)) throw new Error('Unsupported installation operation.');
|
||||
if (!['preflight', 'activate', 'uninstall', 'cancel'].includes(command)) throw new Error('Unsupported installation operation.');
|
||||
while (args.length) {
|
||||
const flag = args.shift();
|
||||
if (flag === '--stage-only' && !options.stageOnly) { options.stageOnly = true; continue; }
|
||||
if (!['--install-root', '--data-root', '--candidate-root', '--port'].includes(flag) || !args.length || options[flag] !== undefined) throw new Error('Unsupported or repeated installation field.');
|
||||
if (!['--install-root', '--data-root', '--candidate-root', '--port', '--operation-id', '--expected-manifest-sha256'].includes(flag) || !args.length || options[flag] !== undefined) throw new Error('Unsupported or repeated installation field.');
|
||||
options[flag] = args.shift();
|
||||
}
|
||||
try {
|
||||
const manager = new InstallationManager({ installRoot: options['--install-root'], dataRoot: options['--data-root'], candidateRoot: options['--candidate-root'], port: Number(options['--port'] || 4318) });
|
||||
const result = command === 'preflight' ? await manager.preflight({ stageOnly: !!options.stageOnly }) : command === 'activate' ? await manager.activate({ stageOnly: !!options.stageOnly }) : await manager.prepareUninstall();
|
||||
const manager = new InstallationManager({ installRoot: options['--install-root'], dataRoot: options['--data-root'], candidateRoot: options['--candidate-root'], port: Number(options['--port'] || 4318), operationId: options['--operation-id'] ?? null, expectedManifestSha256: options['--expected-manifest-sha256'] ?? null,
|
||||
onProgress: value => {
|
||||
const counts = value.counts;
|
||||
console.log('AWBPROGRESS ' + (value.label + (counts ? ` · ${counts.completedFiles}/${counts.totalFiles} 文件` + (counts.completedBytes !== null ? ` · ${counts.completedBytes}/${counts.totalBytes} 字节` : '') + (counts.currentPath ? ' · ' + counts.currentPath : '') : '')).replace(/[\r\n]/g, ' '));
|
||||
console.log('AWBFILES ' + (counts ? counts.completedFiles + '/' + counts.totalFiles : '-'));
|
||||
} });
|
||||
const result = command === 'preflight' ? await manager.preflight({ stageOnly: !!options.stageOnly }) : command === 'activate' ? await manager.activate({ stageOnly: !!options.stageOnly }) : command === 'cancel' ? await manager.cancelPreparation() : await manager.prepareUninstall();
|
||||
console.log(JSON.stringify(result));
|
||||
} catch (error) { console.error(JSON.stringify({ success: false, code: error.code || 'INSTALLATION_FAILED', message: error.message })); process.exitCode = 1; }
|
||||
} catch (error) { console.error('AWBERROR ' + error.message); console.error(JSON.stringify({ success: false, code: error.code || 'INSTALLATION_FAILED', message: error.message })); process.exitCode = 1; }
|
||||
|
||||
@@ -39,6 +39,8 @@ Filename: "{app}\AgentWorkbench.exe"; Description: "打开 Agent Workbench"; Fla
|
||||
|
||||
[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
|
||||
@@ -51,16 +53,44 @@ 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);
|
||||
' --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';
|
||||
Result := Exec(ExpandConstant('{tmp}\awb-install-node.exe'), Parameters, ExpandConstant('{tmp}'), SW_HIDE, ewWaitUntilTerminated, ExitCode) and (ExitCode = 0);
|
||||
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;
|
||||
@@ -70,19 +100,26 @@ begin
|
||||
if DirExists(ExpandConstant('{app}\versions\{#VersionDirectory}')) then begin
|
||||
Result := '该独立版本目录已经存在。请保留原版本,使用新的安装候选。'; exit;
|
||||
end;
|
||||
if not RunManager('preflight', False) then Result := '安装预检未通过。请等待任务、审批与工具结束并关闭桌面窗口,保留后台执行宿主及原数据;端口和安装身份仍需核对。';
|
||||
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('候选激活失败;已尝试恢复原安装指针和执行宿主。请保留 .installation 操作收据核对结果。');
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user