セットアップの実行時に PascalScript からファイルのリスト ([Files] セクションのエントリ) にアクセスする方法はありますか? アプリケーションをインストールするのではなく、セットアップから直接実行できるようにしようとしています。これにより、ファイル リストの管理が容易になります。
2960 次
1 に答える
6
ここでの考え方は、ファイル名を個別のテキストファイル(Source.txt
ここ)に保存することです。ここで、各行は1つのファイルになります。その後、プリプロセッサがスクリプトを生成します。実際には、からのファイルのリストを含む配列を作成し、Source.txt
そのすべての要素を[Files]
セクションに追加し、[Code]
セクションで文字列リストを埋めます(ここではコンテンツを表示するためにリストボックスを使用します)。
重要:
ファイルの最後に空でない行を追加する必要があるSource.txt
ため、たとえば;
ファイルの最後に追加するだけです。
脚本:
#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 に答える