Inno Setup-检查是否存在多个文件夹 [英] Inno Setup - Check if multiple folders exist

查看:93
本文介绍了Inno Setup-检查是否存在多个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义卸载页面,该页面由以下行调用:

I have a custom uninstall page, which is invoked with this line:

UninstallProgressForm.InnerNotebook.ActivePage := UninstallConfigsPage;

现在,这仅在每次运行卸载程序时显示该页面,但仅在存在某些文件夹(其中有6个)的情况下,我才需要显示该页面.我可以用一堆或来做一个 if 语句,但是我想知道是否有一种更整洁的方法.

Now, this just shows the page every time the uninstaller is run, but I need it to show only if certain folders exist (there's 6 of them). I could make an if statement with a bunch of or's, but I'm wondering if there's a neater way to do it.

推荐答案

通常,没有比调用每个文件夹的 DirExists :

In general, there's no better way than calling DirExists for each folder:

if DirExists('C:\path1') or
   DirExists('C:\path2') or
   DirExists('C:\path3') then
begin
  { ... }
end;


但是,在处理一组文件/文件夹时,建议将其列表存储在某个容器中(例如我对其他问题的解决方案中的( Dirs:TStringList ).


Though, when processing a set of files/folders, it's advisable to have their list stored in some container (like TStringList or array of string), to allow their (repeated) bulk-processing. You already have that (Dirs: TStringList) from my solution to your other question.

var
  Dirs: TStringList;
begin
  Dirs := TStringList.Create();
  Dirs.Add('C:\path1');
  Dirs.Add('C:\path2');
  Dirs.Add('C:\path2');
end;

function AnyDirExists(Dirs: TStringList): Boolean;
var
  I: Integer;
begin
  for I := 0 to Dirs.Count - 1 do
  begin
    if DirExists(Dirs[I]) then
    begin
      Result := True;
      Exit;
    end;
  end;

  Result := False;
end;


但是从您的其他问题中我知道,您已将所有路径映射到复选框.因此,您要做的就是检查是否有任何复选框:


But I know from your other question, that you map all the paths to checkboxes. Hence, all you need to do, is to check, if there's any checkbox:

if CheckListBox.Items.Count > 0 then
begin
  UninstallProgressForm.InnerNotebook.ActivePage := UninstallConfigssPage;

  { ... }

  if UninstallProgressForm.ShowModal = mrCancel then Abort;

  { ... }

  UninstallProgressForm.InnerNotebook.ActivePage := UninstallProgressForm.InstallingPage;
end;

这篇关于Inno Setup-检查是否存在多个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆