运行安装程序时,有什么方法可以从 PascalScript 访问文件列表([Files] 部分中的条目)?我们试图使应用程序可以直接从设置中运行,而不是必须安装它,这将使维护文件列表更容易。
问问题
2960 次
1 回答
6
这里的想法是将文件名存储到单独的文本文件(Source.txt
此处)中,其中每一行都是一个文件。然后预处理器将为您生成脚本。实际上它创建了一个包含文件列表的数组,Source.txt
并将其所有元素添加到该[Files]
部分中,并且在该[Code]
部分中它将填充字符串列表(这里使用列表框来显示内容)。
重要的:
您必须在文件末尾有一个额外的非空行Source.txt
,因此只需在文件末尾添加 eg ;
。
脚本:
#define FilesSource "d:\Source.txt"
#define FileLine
#define FileIndex
#define FileCount
#define FileHandle
#dim FileList[65536]
#sub ProcessFileLine
#if FileLine != ""
#expr FileList[FileCount] = FileLine
#expr FileCount = ++FileCount
#endif
#endsub
#for {FileHandle = FileOpen(FilesSource); \
FileHandle && !FileEof(FileHandle); \
FileLine = FileRead(FileHandle)} \
ProcessFileLine
#if FileHandle
#expr FileClose(FileHandle)
#endif
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Files]
#sub AddFileItem
#emit 'Source: "' + FileList[FileIndex] + '"; DestDir: "{app}"'
#endsub
#for {FileIndex = 0; FileIndex < FileCount; FileIndex++} AddFileItem
[Code]
procedure InitializeWizard;
var
FileList: TStringList;
FileListBox: TListBox;
CustomPage: TWizardPage;
begin
CustomPage := CreateCustomPage(wpWelcome, 'Theme selection page', '');
FileListBox := TListBox.Create(WizardForm);
FileListBox.Parent := CustomPage.Surface;
FileListBox.Align := alClient;
FileList := TStringList.Create;
try
#sub AddFileItemCode
#emit ' FileList.Add(''' + FileList[FileIndex] + ''');'
#endsub
#for {FileIndex = 0; FileIndex < FileCount; FileIndex++} AddFileItemCode
FileListBox.Items.Assign(FileList);
finally
FileList.Free;
end;
end;
#expr SaveToFile("d:\PreprocessedScript.iss")
测试 Source.txt:
MyProg.exe
MyProg.chm
Readme.txt
;
测试 PreprocessedScript.iss 的输出:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"
Source: "Readme.txt"; DestDir: "{app}"
[Code]
procedure InitializeWizard;
var
FileList: TStringList;
FileListBox: TListBox;
CustomPage: TWizardPage;
begin
CustomPage := CreateCustomPage(wpWelcome, 'Theme selection page', '');
FileListBox := TListBox.Create(WizardForm);
FileListBox.Parent := CustomPage.Surface;
FileListBox.Align := alClient;
FileList := TStringList.Create;
try
FileList.Add('MyProg.exe');
FileList.Add('MyProg.chm');
FileList.Add('Readme.txt');
FileListBox.Items.Assign(FileList);
finally
FileList.Free;
end;
end;
于 2012-07-31T08:58:13.787 回答