Is there any way to access the list of files (entries in the [Files] section) from PascalScript when running the setup? We're trying to make the application runnable directly from the setup, rather than having to install it, and this would make it easier to maintain the file list.
Asked
Active
Viewed 3,116 times
4
-
You should clarify your question, but if I understand you correctly you want to extract files from the setup at runtime in order to run them - if so look into the `ExtractTemporaryFile()` helper function. You can however AFAIK not access the list of files, you will have to hard-code the extraction of files you need. – mghie Jan 20 '12 at 07:34
-
1@mghie: Yes, we use ExtractTemporaryFile (and ran into other problems with that function, like not being able to extract multiple files with the same name to different directories) - but as of now, we hard-code the list of files to extract into the script, so we have two places to maintain when changing the list. It's unfortunate that the list cannot be accessed from script. – OregonGhost Jan 20 '12 at 10:44
-
Were you going to use wildcards to add files from directories or a list of single files ? In latter case would be possible to have a list of files in a single text file and add it to the files section as well as fill e.g. a string list in a code section using InnoSetup preprocessor. – TLama Jul 30 '12 at 01:30
-
@TLama: No, the problem is that the application be either installed by InnoSetup, or run directly from the Setup. For the latter, we currently have to maintain a separate file list to extract temporarily. It would be easier if I could just read the setup's actual file list and extract from there. Of course, having the file list in a separate file and generate both the files section and the extraction code may be an interesting idea. How would you do that with the preprocessor? – OregonGhost Jul 31 '12 at 08:28
-
See the update, now it works properly (except the need of extra line in the file with content of the `[Files]` section). – TLama Aug 01 '12 at 18:30
-
1@TLama: I'm sorry, the project is long over, so I didn't actually try it out. I'll have a look at your answer though, because this might come in handy in another project, because for some reason, the very same customer wants a single executable application again... :) The idea sounds good though. Didn't know you could do this with the preprocessor. Looks a lot like Basic... – OregonGhost Aug 15 '12 at 09:52
1 Answers
6
The idea here is to store the file names into the separate text file (the Source.txt
here) where each line will be one file. The preprocessor will then generate the script for you. Actually it creates the array which contains the list of the files from the Source.txt
and add all of its elements into the [Files]
section and in the [Code]
section it will fill the string list (here is used a list box to show the content).
Important:
You must have an extra non-empty line at the end of the Source.txt
file, so just add e.g. ;
at the end of the file.
Script:
#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")
Testing Source.txt:
MyProg.exe
MyProg.chm
Readme.txt
;
Output of testing 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;

TLama
- 75,147
- 17
- 214
- 392