【问题标题】:INNO setup extract dir tree when setup starts prior to install安装前安装程序开始时 INNO 安装程序提取目录树
【发布时间】:2012-03-02 21:36:06
【问题描述】:

我有一个 INNO 安装程序,它就像一个魅力。现在我需要添加一个主题选项预安装,以便用户为应用程序选择主题。这些主题在部署目录中定义,安装时会复制到 {tmp} 文件夹。

我要做的是在此目录部分中查找特定目录/文件以确定主题选项。当我找到一个主题时,我会在组合框中添加一个选项供用户选择。然后,此选择将​​影响应用程序的安装(也来自 {tmp} 区域)。

我的问题是在单击安装按钮之前,文件没有解压到 {tmp} 目录。有没有办法在安装之前查看压缩文件结构或将这些文件强制到 {tmp} 目录?每个主题的文件结构都不同,并且根据客户,只有某些主题可用。

我之前使用过ExtractTemporaryFile方法,但是直到目录被提取出来我才知道运行时存在哪些主题。能够提取整个目录树会很好,但我没有找到一种简单的方法来做到这一点。

感谢您的帮助。

以下是我最初尝试做的示例脚本:

[Setup]
AppName=Test
AppVersion=1.5
DefaultDirName={pf}\test
OutputDir=Output
OutputBaseFilename=tt
DisableReadyPage=false

[Files]
;;Source: readme.txt; DestDir: {tmp}\App\deploy\themes\theme1; Flags: ignoreversion replacesameversion
;;Source: readme.txt; DestDir: {tmp}\App\deploy\themes\theme2; Flags: ignoreversion     replacesameversion
;;Source: readme.txt; DestDir: {tmp}\App\deploy\themes\theme3; Flags: ignoreversion replacesameversion
;;Source: readme.txt; DestDir: {tmp}\App\deploy\themes\theme4; Flags: ignoreversion replacesameversion
Source: App\*.*; DestDir: {tmp}\App; Flags: ignoreversion replacesameversion recursesubdirs createallsubdirs
Source: readme.txt; DestDir: {app}; Flags: ignoreversion replacesameversion

[Run]

[Code]

var
   curDir : String;
   TestPage : TWizardPage;
   ThemeComboBox: TNewComboBox;

procedure InitializeWizard;
begin
   TestPage := CreateCustomPage(wpSelectTasks, 'My test page', 'run test');

   // create the theme combo box
   ThemeComboBox := TNewComboBox.Create(TestPage);
   ThemeComboBox.Name := 'themeselection';
   ThemeComboBox.Width := TestPage.SurfaceWidth;
   ThemeComboBox.Parent := TestPage.Surface;
   ThemeComboBox.Style := csDropDownList;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
   ThemeDir: String;
begin
   Result := True;

   if CurPageID = wpSelectDir then
   begin
      // look for the networks and then add the ones that exist to the combo box
      ThemeDir := ExpandConstant('{tmp}\App\deploy\themes\tmeme1');
      MsgBox(ThemeDir, mbInformation, MB_OK);
      if DirExists(ThemeDir) then
      begin
         // populate the combo box
         // this is theme1 so it is Standard
         ThemeComboBox.Items.Add('Standard');
      end;

      ThemeDir := ExpandConstant('{tmp}\App\deploy\themes\theme2');
      if DirExists(ThemeDir) then
      begin
         // populate the combo box
         ThemeComboBox.Items.Add('theme2');
      end;

      ThemeDir := ExpandConstant('{tmp}\App\deploy\themes\theme3');
      if DirExists(ThemeDir) then
      begin
         // populate the combo box
         ThemeComboBox.Items.Add('theme3');
      end;

      ThemeDir := ExpandConstant('{tmp}\App\deploy\themes\theme4');
      if DirExists(ThemeDir) then
      begin
         // populate the combo box
         ThemeComboBox.Items.Add('theme4');
      end;
   end;
end;

【问题讨论】:

    标签: installation inno-setup pascalscript


    【解决方案1】:

    执行此操作的最佳方法是使用 ISPP 枚举文件并在编译时构建相关条目列表,以便在运行时读取。

    这可以直接输出到帕斯卡数组中,也可以输出到文件中,然后在运行时提取和读取。

    【讨论】:

    • 你能举个例子吗?我不确定我知道你在说什么。谢谢。
    • 史蒂夫,添加了示例(虽然很晚:-) @Deanna,我认为不可能从 InnoSetup 预处理器输出某些内容到运行时输出(直接输出到帕斯卡数组)。不支持常量数组。
    • @TLama 正如你所展示的,它可以输出代码来填充数组:)
    【解决方案2】:

    很晚了,我知道 :-) 只是为了用代码示例完成您的问题;以下示例使用在SearchMask 变量指定的路径上找到的所有文件夹名称填充组合框。每次在该指定位置找到一个文件夹时,它都会在字符串列表中添加一行。完成位置搜索后,将字符串列表分配给组合框:

    [Setup]
    AppName=My Program
    AppVersion=1.5
    DefaultDirName={pf}\My Program
    
    [Files]
    Source: App\*.*; DestDir: {tmp}\App; Flags: ignoreversion
    
    [Code]
    var
      CustomPage: TWizardPage;
    
    procedure InitializeWizard;
    var  
      ThemeList: TStringList;
      ThemeComboBox: TNewComboBox;
    begin
      CustomPage := CreateCustomPage(wpWelcome, 'Theme selection page', '');
    
      ThemeComboBox := TNewComboBox.Create(WizardForm);
      ThemeComboBox.Parent := CustomPage.Surface;
      ThemeComboBox.Style := csDropDownList;
      ThemeComboBox.Width := CustomPage.SurfaceWidth;  
    
      ThemeList := TStringList.Create;
      try
        #define SearchHandle
        #define SearchResult
        #define SearchMask "App\Deploy\Themes\*.*"
        #sub ProcessFoundFile
          #define FileName FindGetFileName(SearchHandle)
          #if (FileName != ".") && (FileName != "..")
            #emit '    ThemeList.Add(''' + FileName + ''');'
          #endif
        #endsub
        #for {SearchHandle = SearchResult = FindFirst(SearchMask, faDirectory); \
          SearchResult; SearchResult = FindNext(SearchHandle)} ProcessFoundFile
        #if SearchHandle
          #expr FindClose(SearchHandle)
        #endif
        ThemeComboBox.Items.Assign(ThemeList);
      finally
        ThemeList.Free;
      end;
    end;
    
    // you can save the current script file output after compilation preprocessing 
    // to see the result
    #expr SaveToFile("d:\OutputScript.iss")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2017-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-04
      • 2016-05-11
      相关资源
      最近更新 更多