在代码部分使用TASK结果

时间:2015-01-18 15:14:38

标签: task inno-setup

根据TASK向导页面上的用户选择,我需要能够使用答案创建5个不同的变量/变体,以便在FILES&图标部分。

实例; 1.-结果将指示放置文件的目录。 2.-结果还将表明Perameters中的TEXT是什么。

上面的每个例子都是不同的变量/变体

这些变体基本上会取代我目前使用的#define(s)变量。

我的应用程序是一个多状态应用程序,每个状态都有不同的支持文件内容,我希望能够使用TASK选项,而不是每个都有一个单独的exe文件。

1 个答案:

答案 0 :(得分:1)

您的问题太广泛而无法涵盖,因此我将尝试向您展示从脚本代码中获取[Files]条目DestDir参数的原则,这也是您可以应用于{{{ 1}}参数。关键是使用{code:...}常量,您可以在其中指定在脚本的[Icons]部分中声明的getter函数。以下示例显示了如何根据所选任务将文件安装到4个不同的目录中:

[Code]

您可以使用许多部分参数,但不是全部(这是一个非常广泛的主题)。还要注意,有些参数是评估的(当用户还没有看到任务时),其中一些参数稍后会被评估。此外,一些参数会被多次评估(指定的getter函数可能会执行多次)。

所以它取决于你要指定哪种参数。对于您提及的#define PathNone "None" #define PathBoth "Both" #define PathFirst "First" #define PathSecond "Second" [Setup] AppName=My Program AppVersion=1.5 DefaultDirName={pf}\My Program [Tasks] Name: TaskFirst; Description: "First task" Name: TaskSecond; Description: "Second task" [Files] Source: "MyApp.exe"; DestDir: "{code:GetMyAppDir}" [Code] function GetMyAppDir(Param: string): string; begin // check if both tasks are selected; if yes, then assign a subfolder path defined // by the PathBoth preprocessor variable to the Result if IsTaskSelected('TaskFirst') and IsTaskSelected('TaskSecond') then Result := '{#PathBoth}' else // both tasks are not selected, so let's check if the first one is; if yes, then // assign the PathFirst preprocessor variable to the Result if IsTaskSelected('TaskFirst') then Result := '{#PathFirst}' else // first task nor both are selected, so let's check if the second one is; if so, // assign the PathSecond preprocessor variable to the Result if IsTaskSelected('TaskSecond') then Result := '{#PathSecond}' else // no task is selected (this is the last possible situation), let's assign the // PathNone preprocessor variable to the Result Result := '{#PathNone}'; // finally prepend to the Result the {app} constant and expand all the constants Result := ExpandConstant('{app}\' + Result); end; 部分[Files]参数和DestDir部分[Icons]参数,您可以使用此方法。