3

如何搜索现有的 exe 文件,然后将该目录用于我的安装程序?

如果找不到 exe 文件,我希望用户浏览路径。如果exe文件安装在其他地方。

Senario 1(最常见的情况):

默认目录是 c:\test\My program

这应该显示为“选择目标位置”页面上的路径当用户按下一步时,应该有一个检查。要确保默认目录存在(c:\test\My 程序),如果存在,用户应该继续到准备安装页面。

Senario 2(极少数情况):

默认目录是 c:\test\My program

这应该显示为“选择目标位置”页面上的路径当用户按下一步时,应该有一个检查。确保默认目录存在 (c:\test\My program) 如果不存在,应提示用户输入“我的程序”的路径。用户随后应继续进入“准备安装”页面。然后我只相信用户选择了正确的路径

如何在 InnoSetup 中执行此操作?

4

2 回答 2

5

我已经用我的安装程序做了类似的事情。我要做的第一件事是需要从程序中读取注册表值,如果该注册表值不存在,那么我选择该程序的默认目录。例如:

DefaultDirName={reg:HKLM\Software\Activision\Battlezone II,STInstallDir|reg:HKLM\Software\Activision\Battlezone II,Install121Dir|{pf32}\Battlezone II}

现在,用户运行安装程序,它必须检查程序是否在正确的文件夹中。它通过检查程序的可执行文件是否已经存在来做到这一点。我使用这段代码来做到这一点。

{ Below code warns end user if he tries to install into a folder that does not contain bzone.exe. Useful if user tries to install into addon or any non-BZ2 folder. }
function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Log('NextButtonClick(' + IntToStr(CurPageID) + ') called');
  case CurPageID of
    wpSelectDir:
    if not FileExists(ExpandConstant('{app}\bzone.exe')) then begin
      MsgBox('Setup has detected that that this is not the main program folder of a Battlezone II install, and the created shortcuts to launch {#MyAppName} will not work.' #13#13 'You should probably go back and browse for a valid Battlezone II folder (and not any subfolders like addon).', mbError, MB_OK);
      end;
    wpReady:
  end;
  Result := True;
end;

上面的代码只是检查目标可执行文件是否存在,如果不存在则警告用户,让他有机会返回并更改目录,但也可以继续安装。

此外,由于您似乎正在为现有程序安装补丁或插件,我建议您设置

DirExistsWarning=no
AppendDefaultDirName=false

如果您不创建开始菜单条目,还可以选择防止出现不必要的屏幕

DisableProgramGroupPage=yes
于 2013-06-11T19:32:39.950 回答
3

我会制作一个文件输入页面并让用户Picture.exe手动选择二进制位置,当它在预期位置找不到时。

您可以遵循此代码的注释版本

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output

[Files]
Source: "CurrentBinary.exe"; DestDir: "{app}"
Source: "PictureExtension.dll"; DestDir: "{code:GetDirPath}"

[Code]
var
  FilePage: TInputFileWizardPage;

function GetDirPath(const Value: string): string;
begin
  Result := '';
  if FileExists(FilePage.Values[0]) then
    Result := ExtractFilePath(FilePage.Values[0]);
end;         

procedure InitializeWizard;
var
  FilePath: string;
begin
  FilePage := CreateInputFilePage(wpSelectDir, 'Select Picture.exe location', 
    'Where is Picture.exe installed ?', 'Select where Picture.exe is located, ' +
    'then click Next.');
  FilePage.Add('Location of Picture.exe:', 'Picture project executable|Picture.exe', 
    '.exe');

  FilePage.Edits[0].ReadOnly := True;
  FilePage.Edits[0].Color := clBtnFace;

  FilePath := ExpandConstant('{pf}\Picture\Picture.exe');
  if FileExists(FilePath) then
    FilePage.Values[0] := FilePath;
end;
于 2013-02-12T21:07:51.627 回答