Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
569 views
in Technique[技术] by (71.8m points)

inno setup - Access file list via script in InnoSetup

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...