Идея заключается в том, чтобы хранить имена файлов в отдельном текстовом файле (здесь Source.txt
), где каждая строка будет одним файлом. Препроцессор сгенерирует скрипт для вас. Фактически он создает массив, который содержит список файлов из 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;