1

我有一个像魅力一样工作的 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;
4

2 回答 2

1

Quite late, I know :-) Just to complete your question with the code sample; The following example fills the combo box with all folder names found on the path specified by the SearchMask variable. Every time it find a folder in that specified location, it adds a line to a string list. When the search through the location is done, the string list is assigned to the combo box:

[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")
于 2012-07-30T00:00:31.033 回答
1

最好的方法是使用 ISPP 枚举文件并在编译时建立相关条目的列表,您可以在运行时读取这些条目。

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

于 2012-03-05T12:17:50.120 回答