1 { This file is part of WineLauncher.
3 WineLauncher is free software: you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation, version 3 of the License.
7 WineLauncher is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with WineLauncher. If not, see <http://www.gnu.org/licenses/>.
16 unit UnitProgramsList
;
24 Classes
, SysUtils
, XMLCfg
, Grids
;
26 function ProgramsListSavePrefix(PrefixName
:string):boolean;
27 function ProgramsListLoadPrefix(PrefixName
:string):boolean;
28 function SetUpGrid(A
:integer):boolean;
29 function SetUpArray():boolean;
38 PreFixList
:array of Tstrings
;
41 Data
:array of DataStore
;
47 PrefixDataName
= 'PrefixData.xml';
56 function ProgramsListSavePrefix(PrefixName
:string):boolean;
59 FullPathWithName
:string;
62 SaveConfig
:TXMLConfig
;
64 PrefixInt
:= FindPrefixInt(PrefixName
);
66 {Stop if the prefix does not exist.}
67 if PrefixInt
= -1 then exit
;
69 {Get the prefix path.}
70 PathWithName
:= (PreFixList
[1].Strings
[PrefixInt
]);
71 {Stop if the prefix path does not exist.}
72 if DoesFolderExists(PathWithName
) = false then exit(false);
74 FullPathWithName
:= (PathWithName
+ '/' + PrefixDataName
);
76 {Delete the old file.}
77 if FileExists(FullPathWithName
) then DeleteFile(FullPathWithName
);
78 SaveConfig
:= TXMLConfig
.Create(nil);
80 SaveConfig
.FileName
:= FullPathWithName
;
82 SaveConfig
.SetValue('Version', 6);
83 SaveConfig
.SetValue('PrefixName', PrefixName
);
85 {The frist row is the header}
86 for loop
:= 1 to (data
[PrefixInt
].Grid
.Cols
[DataNameCol
].Count
-1) do
88 {Do not save blank items.}
89 if data
[PrefixInt
].Grid
.Cells
[DataNameCol
,loop
] = '' then exit
;
91 {The items need to start at 0.}
92 SaveConfig
.SetValue('Item' + InttoStr(loop
- 1) + '/Name', data
[PrefixInt
].Grid
.Cells
[DataNameCol
, loop
]);
93 SaveConfig
.SetValue('Item' + InttoStr(loop
- 1) + '/Path', data
[PrefixInt
].Grid
.Cells
[DataPathCol
, loop
]);
95 if data
[PrefixInt
].Grid
.Cells
[DataFlagsCol
, loop
] <> '' then
97 SaveConfig
.SetValue('Item' + InttoStr(loop
- 1) + '/Flags', data
[PrefixInt
].Grid
.Cells
[DataFlagsCol
,loop
] );
109 function ProgramsListLoadPrefix(PrefixName
:string):boolean;
112 FullPathWithName
:string;
116 LoadConfig
:TXMLConfig
;
118 PrefixInt
:= FindPrefixInt(PrefixName
);
120 {Stop if the prefix does not exist.}
121 if PrefixInt
= -1 then exit
;
123 {Get the prefix path.}
124 PathWithName
:= (PreFixList
[1].Strings
[PrefixInt
]);
126 FullPathWithName
:= (PathWithName
+ '/' + PrefixDataName
);
128 LoadConfig
:= TXMLConfig
.Create(nil);
130 if FileExists(FullPathWithName
) = true then
133 LoadConfig
.FileName
:= FullPathWithName
;
135 {The items start at 0.}
139 if LoadConfig
.getValue('Version', -1) = 6 then
141 while Done
= false do
143 {Do not load blank items.}
144 if LoadConfig
.GetValue('Item' + InttoStr(LoopCount
) + '/Name', '') <> '' then
146 {Leave room for the header.}
147 data
[PrefixInt
].Grid
.Cells
[DataNameCol
, LoopCount
+1] := LoadConfig
.GetValue('Item' + InttoStr(LoopCount
) + '/Name', '');
148 data
[PrefixInt
].Grid
.Cells
[DataPathCol
, LoopCount
+1] := LoadConfig
.GetValue('Item' + InttoStr(LoopCount
) + '/Path', '');
150 if LoadConfig
.GetValue('Item' + InttoStr(LoopCount
) + '/Flags', '') <> '' then
152 data
[PrefixInt
].Grid
.Cells
[DataFlagsCol
, LoopCount
+1] := LoadConfig
.GetValue('Item' + InttoStr(LoopCount
) + '/Flags', '');
170 function SetUpGrid(A
:integer):boolean;
172 {This can not be nil or the debugger will get upset when you close the program.}
173 Data
[A
].Grid
:= TStringGrid
.Create(UnitSettings
.Form4
);
174 Data
[A
].Grid
.RowCount
:= 101;
175 Data
[A
].Grid
.ColCount
:= 3;
176 Data
[A
].PrefixName
:= PreFixList
[0][A
];
178 {Fill in the header for the grid.}
180 Data
[A
].Grid
.Cells
[DataNameCol
,0] := 'Name';
181 Data
[A
].Grid
.Cells
[DataPathCol
,0] := 'Path';
182 Data
[A
].Grid
.Cells
[DataFlagsCol
,0] := 'Flags';
185 function SetUpArray():boolean;
189 {Lay out for Data: array of DataStore}
190 {Type DataStore: string, TStringGrid}
192 SetLength(Data
, PreFixList
[0].count
);
193 for loop
:= 0 to (PreFixList
[0].count
-1) do
198 {Load from file(s) into the array}
199 for loop
:= 0 to (PreFixList
[0].Count
-1) do
201 ProgramsListLoadPrefix(PreFixList
[0][loop
]);
204 {Force the Grid to update, if we do not you can get data lost.}
205 UnitSettings
.form4
.ComboBox_PreFixChange(UnitSettings
.form4
);
206 {Force the Prefix Combobox to update, or the ProgramsList comobox will not list anything.}
207 UnitMain
.form1
.ComboBox_PreFixChange(UnitMain
.form1
);