仅将 Inno 安装程序 UI 用作自解压程序 - 无需安装



>我将Inno Setup用于许多"标准"安装程序,但是对于此任务,我需要提取一堆临时文件,运行其中一个,然后删除它们并退出安装程序(实际上没有安装任何东西(。

基本上,我希望制作一个没有"安装程序"的自解压器,并且正在通过 inno 设置获得最佳用户体验。

我有以下代码几乎可以正常工作:

[Files]
Source: "dist*"; Flags: recursesubdirs ignoreversion dontcopy;
[Code]
function InitializeSetup(): Boolean;
var
ResultCode: Integer;
begin
Result := True;
MsgBox('Please wait a minute or two...', mbInformation, MB_OK);
ExtractTemporaryFiles('{tmp}*');
Exec(ExpandConstant('{tmp}MyScript.exe'), '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
Abort();
end;

问题是我在这里能做的最好的事情就是显示一个消息框"请稍等一两分钟...",用户单击[确定],然后等待,因为屏幕上没有任何内容似乎没有发生,然后MyScript.exe开始。

我想要的是一个向导页面,上面写着"请稍候,因为临时文件被提取了..."带有npbstMarquee样式的进度条,然后在提取文件并启动脚本后消失。

我认为没有办法告诉 Inno Setup 在ExtractTemporaryFiles()进行时显示进度条(这将是理想的(,并且将其处理到自定义向导页面中让我感到困惑。

  • "安装"文件到{tmp},而不是使用ExtractTemporaryFiles;
  • 执行从Run部分提取到{tmp}的文件(或在安装文件后使用AfterInstall参数或CurStepChanged触发Pascal脚本代码(;
  • Uninstallable设置为no;
  • CreateAppDir设置为no;
  • 使用[Messages]部分编辑过于以安装程序为中心的向导文本,以满足您的需求。
[Setup]
Uninstallable=no
CreateAppDir=no
[Files]
Source: "dist*"; DestDir: {tmp}; Flags: recursesubdirs
[Run]
FileName: "{tmp}MyScript.exe"

笔记:

  • 当"安装程序"关闭时,{tmp}文件夹会自动删除;
  • 安装到新的空文件夹时不需要ignoreversion标志。

相关问题:仅运行一组嵌入式安装程序的 Inno 安装程序


有关文字问题的答案,请参阅Inno设置:提取临时文件导致向导冻结。或者关于该主题的更通用的问题:Inno Setup:如何修改长时间运行的脚本,使其不会冻结 GUI?

似乎 ExtractTemporaryFiles(( 基本上锁定了 UI,直到它完成,所以没有办法在这里获得进度条(或选框(动画。

在ExtractTemporaryFiles((正在进行时在屏幕上收到消息也很困难。我是这样解决的:

const
WM_SYSCOMMAND = 274;
SC_MINIMIZE = $F020;
//-------------------------------------------------------------------
procedure MinimizeButtonClick();
begin
PostMessage(WizardForm.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
end;
//-------------------------------------------------------------------
procedure CurPageChanged(CurPageID: Integer);
var
ResultCode: Integer;
begin
if CurPageID = wpPreparing then
begin
MinimizeButtonClick();
Exec(ExpandConstant('{tmp}MyScript.exe'), '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;
end;
//-------------------------------------------------------------------
function NextButtonClick(CurPageID: Integer): Boolean;
var
ProgressPage: TOutputProgressWizardPage;
begin
if CurPageID = wpReady then
begin
ProgressPage := CreateOutputProgressPage('Preparing files...', '');
ProgressPage.Show;
try
ProgressPage.Msg1Label.Caption := 'This process can take several minutes; please wait ...';
ExtractTemporaryFiles('{tmp}*');
finally
ProgressPage.Hide;
end;
end;
Result := True;
end;
//-------------------------------------------------------------------
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
begin
//MinimizeButtonClick() is called here as the Wizard flashes up for a second
// and minimizing it makes that 1/2 a second instead...
MinimizeButtonClick();
Abort();
end;
end;

然后,我更改了"就绪"页面上的文本以适应使用[消息]部分。

结果是:

  • 一个向导页,询问用户是否要继续
  • 一个向导页告诉用户"请稍候..."提取临时文件时
  • 提取文件后,向导将被隐藏,并且从临时文件夹中运行 MyScript.exe
  • MyScript 完成后.exe向导将干净地退出并删除临时文件

相关内容

最新更新