2012-03-02 154 views
1

我有一个INNO安装程序,它像一个魅力一样工作。现在我需要为用户预先安装主题选项以选择应用程序的主题。这些主题是在安装时复制到{tmp}文件夹的部署目录中定义的。INNO安装程序在安装前开始安装时提取目录树

我想要做的是在这个目录部分查找特定的目录/文件来确定主题选项。当我找到一个主题时,我会将一个选项添加到组合框供用户选择。此选择将影响应用程序的安装(也来自{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; 

回答

1

做到这一点,最好的办法是使用ISPP枚举文件,并建立相关的条目在编译时列表你可以在运行时阅读。

这可以直接输出到一个pascal数组中,也可以输出到一个文件,然后在运行时读取并读取它。

+1

你能举个例子吗?我不确定我是否知道你在说什么。谢谢。 – 2012-03-05 13:11:19

+0

Steve,添加了一个例子(相当晚了:-) @Deanna,我认为从InnoSetup预处理器输出的东西不会输出到运行时输出(*输出直接输入到一个pascal数组*)。常量数组不受支持。 – TLama 2012-07-30 00:11:55

+1

@TLama正如你已经证明的那样,它可以输出代码来填充数组,虽然:) – Deanna 2012-07-30 08:49:23

1

很晚,我知道:-)只是为了完成你的问题与代码示例;以下示例使用由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") 
相关问题