It’s really easy to open the files
For example create a TStringList named List and use List.LoadFromFile(filename) then get strings like this List.strings[0] = program type, List.strings[1] = Program Title, etc (But this approach makes the script to become Huge, and the initialization of program takes more time on slow CD-ROMs, because you need to read all the information stored in files, at startup).
I propose another approach that is easier:
The file program.desc, make him an INI file with the following form:
[Info]
Type=File Managers
Name=Total Commander 6.0
Desc=Total Commander 32 bit international version, file manager replacement for Windows
Screenshot=totalcmd.bmp
File=totalcmdsetup.exe
Bellow is an example that makes an autorun similar to the CHIP CD interface, etc.
To test the project, follow my instructions.
Save The Text bellow to a file named Form1.dfm, the start APB go to edited form, right click, choose Form - Load From File(select the form1.dfm file).
-----=====Bellow Starts the Form1.dfm file (do NOT include this line).=====-----
object Form1: TForm
Left = 48
Top = 51
Width = 490
Height = 405
Caption = 'LIKE CHIP CD INTERFACE'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Visible = True
PixelsPerInch = 96
TextHeight = 13
object Image1: TImage
Left = 232
Top = 24
Width = 233
Height = 169
ParentShowHint = False
Proportional = True
ShowHint = False
Stretch = True
end
object Label1: TLabel
Left = 232
Top = 8
Width = 57
Height = 13
Caption = 'Screenshot:'
end
object Label2: TLabel
Left = 232
Top = 200
Width = 56
Height = 13
Caption = 'Description:'
end
object ComboBox1: TComboBox
Left = 24
Top = 24
Width = 185
Height = 21
Style = csDropDownList
Color = clWhite
ItemHeight = 13
TabOrder = 0
end
object Memo1: TMemo
Left = 232
Top = 216
Width = 233
Height = 89
BevelInner = bvNone
BevelOuter = bvNone
BorderStyle = bsNone
Color = clBtnFace
ReadOnly = True
ScrollBars = ssVertical
TabOrder = 1
end
object ListBox1: TListBox
Left = 24
Top = 48
Width = 185
Height = 257
ItemHeight = 13
TabOrder = 2
end
object Button1: TButton
Left = 24
Top = 336
Width = 75
Height = 25
Caption = 'Install'
Enabled = False
TabOrder = 3
end
object Button2: TButton
Left = 104
Top = 336
Width = 75
Height = 25
Caption = 'CopyTo'
Enabled = False
TabOrder = 4
end
end
-----=====Up this ends the Form1.dfm file (do NOT include this line).=====-----
-----=====Bellow is the script. Copy and paste to the Code Editor.=====-----
//The Pascal Scripting is a very powerfull feature of APB
//This can help you do things that other autorun builders can't
var FileList,FT,FN,FF : TStringList;
LABELME : TLabel;
I : integer;
CURFILE : string;
FFORM : TFORM;
const
INFOFILENAME = 'program.desc';
SMESSAGE ='Please wait...'+#13#10+'Loading CD Structure';
procedure ComboBox1OnChange(Sender: TObject); forward;
procedure ShowSplash(Show : boolean);
begin
if Show then
begin
FFORM := TFORM.Create(nil);
FFORM.Width := 250;
FFORM.Height := 100;
FFORM.color := clbtnface;
FFORM.bordericons := FFORM.bordericons - [bisystemmenu];
FFORM.caption := 'Your compilation';
FFORM.borderstyle := bsdialog;
LABELME := TLabel.create(nil);
LABELME.Parent := FFORM;
LABELME.Caption := SMESSAGE;
LABELME.Top := 0;
LABELME.Left := 0;
LABELME.align := alclient;
LABELME.Show;
FFORM.position := PoScreenCenter;
FFORM.show;
LABELME.alignment := taCenter;
LABELME.layout := tlcenter;
LABELME.Font.Style := LABELME.Font.Style + [fsbold];
FFORM.Refresh;
end
else
begin
LABELME.Free;
FFORM.Free;
end;
end;
procedure Form1OnCreate(Sender: TObject);
var S : string;
begin
//Create Lists To Hold Informations
FileList := TStringList.Create;
FT := TStringList.Create;
FN := TStringList.Create;
FF := TStringList.Create;
//Show a splashscreen, getting CD Structure information could take some time
ShowSplash(True);
// Retrieve available programs in all dirs
FileList := ListFilesRecursive(RepConst('%SRCDRIVE%'),INFOFILENAME,true);
ShowSplash(False);
// populate Categories, etc
for i:=0 to FileList.Count-1 do
begin
S := GetIniString('Info','Type','',FileList.Strings
);
FT.Add(S);
FN.Add(GetIniString('Info','Name','',FileList.Strings));
FF.Add(FileList.Strings);
if Combobox1.items.indexof(s)<0 then combobox1.items.add(s);
end;
combobox1.itemindex := 0; //set first category
ComboBox1OnChange(ComboBox1);
end;
procedure Form1OnDestroy(Sender: TObject);
begin
//Free Resources
FileList.Free;
FT.Free;
FN.Free;
FF.Free;
end;
procedure ComboBox1OnChange(Sender: TObject);
var i:integer;
begin
ListBox1.Items.Clear;
for i:=0 to FT.Count-1 do
begin
if SameText(FT.Strings,Combobox1.Text) then
begin
ListBox1.Items.add(FN.strings);
end;
end;
end;
procedure ListBox1OnClick(Sender: TObject);
var i:integer;
s : string;
begin
if listbox1.itemindex<0 then exit;
for i:=0 to FT.Count-1 do
begin
if SameText(FT.Strings,Combobox1.Text) and SameText(FN.Strings,ListBox1.Items.Strings[listbox1.itemindex]) then
begin
s := GetIniString('Info','Screenshot','',FF.Strings);
s := AddBackSlash(ExtractFileDir(FF.Strings)) + s; //scrennshot is in dir with program.desc
if fileexists(s) then LoadImage(Image1,S);
memo1.lines.text := GetIniString('Info','Desc','',FF.Strings);
CURFILE := GetIniString('Info','File','',FF.Strings);
CURFILE := AddBackSlash(ExtractFileDir(FF.Strings)) + CURFILE; //file is in dir with program.desc
Button1.Enabled := FileExists(CURFILE);
Button2.Enabled := FileExists(CURFILE);
end;
end;
end;
procedure Button1OnClick(Sender: TObject);
begin
if not SameText(ExtractFileExt(CURFILE),'.exe') then exit;
FileExec(CURFILE,False,false); // no need to wait...
end;
procedure Button2OnClick(Sender: TObject);
var DIR : string;
begin
DIR := SelectDirectory('Please select a location to copy the file...');
if DIR = '' then exit;
CopyFilesAndOrDirs(CURFILE,DIR,'',Self.Handle,false);
end;
----------========== THE SCRIPT ENDS HERE =========---------
Please let me know if this helps you.
Best wishes,
Murariu Alexandru