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, either version 3 of the License, or
6 (at your option) any later version.
8 WineLauncher is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with WineLauncher. If not, see <http://www.gnu.org/licenses/>.
24 Classes
, SysUtils
, LResources
, Forms
, Controls
, Graphics
, Dialogs
, StdCtrls
, BaseUnix
,
33 ComboBox_PreFix
: TComboBox
;
34 ComboBox_ShellPath
: TComboBox
;
37 StringGrid_TerminalSettings
: TStringGrid
;
38 StringGrid_ProgramsList
: TStringGrid
;
40 procedure ComboBox_PreFixChange(Sender
: TObject
);
41 procedure ComboBox_ShellPathEditingDone(Sender
: TObject
);
42 procedure FormClose(Sender
: TObject
; var CloseAction
: TCloseAction
);
43 procedure FormCreate(Sender
: TObject
);
44 procedure FormDestroy(Sender
: TObject
);
45 procedure StringGrid_ProgramsListDrawCell(Sender
: TObject
; aCol
,
46 aRow
: Integer; aRect
: TRect
; aState
: TGridDrawState
);
47 procedure StringGrid_ProgramsListEditingDone(Sender
: TObject
);
48 procedure StringGrid_TerminalSettingsEditingDone(Sender
: TObject
);
50 function PreFixExists():boolean;
53 procedure ProgramsUpdate();
56 { public declarations }
61 TerminalPathClean
:Tstrings
;
62 TerminalPathFlags
:Tstrings
;
63 TerrminalSettingsIsFine
:boolean;
64 ShellPathIsFine
:boolean;
65 ProgramsList
:Tstrings
;
74 procedure TForm4
.FormCreate(Sender
: TObject
);
80 TerminalPathClean
:= TStringlist
.Create
;
81 ProgramsList
:= TStringlist
.Create
;
83 StringGrid_ProgramsList
.SaveOptions
:= [soDesign
,{soAttributes,}soContent
{,soPosition}] ;
86 {Cheep Hack to check the StringGrid and sych the combobox. }
87 StringGrid_TerminalSettingsEditingDone(self
);
90 ComboBox_ShellPath
.Text := ComboBox_ShellPath
.Items
[0] ;
92 {Load StringGrid_TerminalSettings}
94 if FileExists ( ConfigPath
+ '/StringGrid_TerminalSettings') = true then
96 {NOTE StringGrid.LoadFromFile has no error checking? http://www.freepascal.org/docs-html/lcl/grids/tcustomgrid.loadfromfile.html}
97 StringGrid_TerminalSettings
.LoadFromFile( ConfigPath
+ '/StringGrid_TerminalSettings' );
98 Log(3, LocalChannel
, ( ConfigPath
+ '/StringGrid_TerminalSettings' + ' ) has being loaded.'));
102 Log(4, LocalChannel
, ( ConfigPath
+ '/StringGrid_TerminalSettings' + ' ) does not exists.'));
105 {Lay out for PreFixList: array of Tstrings}
106 {The first Tstrings is for prefix names}
107 {The second Tstrings is for the paths of the prefix's}
108 SetLength(PreFixList
, 2);
109 PreFixList
[0] := TStringlist
.Create
;
110 PreFixList
[1] := TStringlist
.Create
;
112 if PreFixExists() = true then
118 UnitMain
.form1
.Btn_Settings
.Enabled
:= false;
119 UnitMain
.form1
.Button_Winecfg
.Enabled
:= false;
120 UnitMain
.form1
.Button_Regedit
.Enabled
:= false;
121 UnitMain
.form1
.Btn_Run
.Enabled
:= false;
122 UnitMain
.form1
.TogBtn_Listdrive
.Enabled
:= false;
123 UnitMain
.form1
.EditBox_ProgramPath
.Text := '';
124 UnitMain
.form1
.EditBox_ProgramPath
.Enabled
:= false;
126 MessageDlg('Please create a wine prefix', 'You need to create a wine prefix see the create prefix tab.', mtWarning
, [mbOK
], '');
131 procedure TForm4
.FormDestroy(Sender
: TObject
);
133 PreFixList
[1].Destroy
;
134 PreFixList
[0].Destroy
;
135 TerminalPathClean
.Destroy
;
136 ProgramsList
.Destroy
;
139 procedure TForm4
.StringGrid_ProgramsListDrawCell(Sender
: TObject
; aCol
,
140 aRow
: Integer; aRect
: TRect
; aState
: TGridDrawState
);
142 StringGrid_ProgramsList
.AutoSizeColumns
;
145 procedure TForm4
.StringGrid_ProgramsListEditingDone(Sender
: TObject
);
150 LocalChannel
:= 'StringGrid_ProgramsListEditingDone';
152 {TODO Went Editing this runs two times, abit pointless and not CPU friendy}
153 {TODO may add some checks to the flags. Can that be done ?}
156 Log(5, LocalChannel
, ('-----------------'));
157 Log(3, LocalChannel
, ( StringGrid_ProgramsList
.Name
+ ' editing has finished.' ));
159 for loop
:= 1 to StringGrid_ProgramsList
.Cols
[DataNameCol
].Count
-1 do
161 if (StringGrid_ProgramsList
.Cells
[DataNameCol
,loop
]) = '' then
163 StringGrid_ProgramsList
.MoveColRow(false,loop
, (StringGrid_ProgramsList
.Cols
[DataNameCol
].Count
-1)) ;
164 StringGrid_ProgramsList
.Rows
[StringGrid_ProgramsList
.Cols
[DataNameCol
].Count
-1].Clear
;
172 procedure TForm4
.ProgramsUpdate();
178 PrefixInt
:= FindPrefixInt(ComboBox_PreFix
.Items
.Strings
[ComboBox_PreFix
.ItemIndex
]);
179 for B
:= 0 to Data
[PrefixInt
].Grid
.RowCount
-1 do
181 Data
[PrefixInt
].Grid
.Rows
[B
].Text := StringGrid_ProgramsList
.Rows
[B
].text;
185 function TForm4
.PreFixExists():boolean;
187 PreFixFolders
:Tstrings
;
192 ChannelLocal
:= ('PreFixExists');
193 { TODO : procedure for telling you a procedure has being called. }
194 Log(5, '', ('-----------------'));
195 Log(0, ChannelLocal
, ('PreFixExists has being Called.'));
197 CheckList
:= TStringlist
.Create
;
198 PreFixFolders
:= TStringlist
.Create
;
201 CheckList
.Add('/dosdevices') ;
202 CheckList
.Add('/drive_c') ;
204 { TODO : ListFileDir can only handly one path at ones }
206 ListFileDir({0} PathToPrefix
, {1} PreFixFolders
, {2} nil, {3} nil, {4} nil, {5} false);
208 for loop
:= 0 to (PreFixFolders
.Count
-1) do
210 if AnsiEndsText('~', PreFixFolders
.Strings
[loop
]) = false then
212 { Folder and file check. }
214 if DoesFoldersExists((PathToPrefix
+ PreFixFolders
.Strings
[loop
]), CheckList
) = true then
216 if FileExistsAndIsExecutable(PathToPrefix
+ PreFixFolders
.Strings
[loop
] + '/system.reg',true) = true then
218 if FileExistsAndIsExecutable(PathToPrefix
+ PreFixFolders
.Strings
[loop
] + '/user.reg', true) = true then
220 PreFixList
[0].add(PreFixFolders
.Strings
[loop
]);
221 PreFixList
[1].add(PathToPrefix
+ PreFixFolders
.Strings
[loop
]);
229 if PreFixList
[0].Count
<> 0 then
231 {Sych Tstrings with Comobox.}
232 UnitMain
.Form1
.ComboBox_PreFix
.Items
:= PreFixList
[0];
233 ComboBox_PreFix
.Items
:= PreFixList
[0];
235 {Cheep hack to stop crashs.}
236 UnitMain
.Form1
.ComboBox_PreFix
.Text := UnitMain
.Form1
.ComboBox_PreFix
.Items
[0];
237 ComboBox_PreFix
.Text := ComboBox_PreFix
.Items
[0];
248 PreFixFolders
.Destroy
;
253 procedure TForm4
.FormClose(Sender
: TObject
; var CloseAction
: TCloseAction
);
259 { TODO : Set LocalChannel. }
262 Log(5, LocalChannel
, ('-----------------'));
263 Log(3, LocalChannel
, ( Form4
.Name
+ ' close has happen.' ));
266 for loop
:= 0 to (PreFixList
[0].Count
-1) do
268 ProgramsListSavePrefix(PreFixList
[0][loop
]);
272 {Temp save of StringGrid_TerminalSettings}
273 if TerrminalSettingsIsFine
= true then
275 Log(3, LocalChannel
, ( 'Saving' + Wrap(StringGrid_TerminalSettings
.Name
) + 'to' + Wrap(ConfigPath
+ '/StringGrid_TerminalSettings') ));
276 StringGrid_TerminalSettings
.SaveOptions
:= [soDesign
,{soAttributes,}soContent
{,soPosition}] ;
277 {TODO error checking for save.}
278 StringGrid_TerminalSettings
.SaveToFile( ConfigPath
+ '/StringGrid_TerminalSettings' );
282 Log(1, LocalChannel
, ('Not saving' + Wrap(StringGrid_TerminalSettings
.Name
) + 'because the is something wrong with it.'));
288 {Remember the selected item.}
289 TempInt
:= UnitMain
.Form1
.ComboBox_ProgramsList
.ItemIndex
;
290 {Update ComboBox_PreFix, This clears ComboBox_ProgramsList.}
291 UnitMain
.Form1
.ComboBox_PreFixChange(self
);
292 {Write back the remembered selected item.}
293 UnitMain
.Form1
.ComboBox_ProgramsList
.ItemIndex
:= TempInt
;
294 {This updates EditBox_ProgramPath.}
295 UnitMain
.Form1
.ComboBox_ProgramsListChange(self
);
297 {Note flag settings are losted.}
302 procedure TForm4
.ComboBox_ShellPathEditingDone(Sender
: TObject
);
306 { TODO : Set LocalChannel. }
309 Log(5, LocalChannel
, ('-----------------'));
310 Log(3, LocalChannel
, ( ComboBox_ShellPath
.Name
+ ' editing has finished.' ));
312 if FileExistsAndIsExecutable( {FullPath:string}ComboBox_ShellPath
.text, {JustCheckExists:boolean}false ) = true then
314 ShellPathIsFine
:= true;
315 { TODO -cColour : Work out why "clwindow" does not work. }
316 ComboBox_ShellPath
.Color
:= clwhite
;
320 ShellPathIsFine
:= false;
321 ComboBox_ShellPath
.Color
:= clred
;
326 procedure TForm4
.ComboBox_PreFixChange(Sender
: TObject
);
331 StringGrid_ProgramsList
.Clean
;
332 StringGrid_ProgramsList
.FixedRows
:= 1 ;
333 PrefixInt
:= FindPrefixInt(ComboBox_PreFix
.Items
.Strings
[ComboBox_PreFix
.ItemIndex
]);
337 StringGrid_ProgramsList
.Rows
[B
].text := Data
[PrefixInt
].Grid
.Rows
[B
].Text;
342 procedure TForm4
.StringGrid_TerminalSettingsEditingDone(Sender
: TObject
);
349 { TODO : Went Editing this runs two times, abit pointless and not CPU friendy}
350 { TODO : May add some checks to the flags. Can that be done ?}
351 { TODO : Set LocalChannel. }
356 Log(5, LocalChannel
, ('-----------------'));
357 Log(3, LocalChannel
, ( StringGrid_TerminalSettings
.Name
+ ' editing has finished.'));
359 {USEFUL INFO: stringGrid.Cells[col,row] }
361 {Check the no row is blank other then the last one}
362 if IsFine
= true then
364 for loop
:= 0 to ( StringGrid_TerminalSettings
.RowCount
-2 )do {Ignore last row}
366 {TODO : check the whole row not just the frist cell }
367 if StringGrid_TerminalSettings
.Cells
[0,loop
] = '' then {delete it!}
369 StringGrid_TerminalSettings
.DeleteColRow(false,loop
);
370 Log(4, LocalChannel
, ('Not Fine deleting row.'));
371 exit
; {exit or out of range error}
381 {Check the Names are unique or you can get the wrong path}
382 if IsFine
= true then
384 //UnitMain.form1.log('Running Check the Names are unique');
385 for loop
:= 1 to ( StringGrid_TerminalSettings
.RowCount
-1 )do
387 for loop2
:= 0 to ( StringGrid_TerminalSettings
.RowCount
-1 )do
389 if StringGrid_TerminalSettings
.cells
[0,loop
] = StringGrid_TerminalSettings
.cells
[0,loop2
] then
391 if loop2
<> loop
then
394 Log(4, LocalChannel
, ( 'Col(0)Row(' + inttostr(loop
) + ') has the same name as Col(0)Row(' + inttostr(loop2
) + ').'));
407 {Check that Path does exists and is executable.}
408 if IsFine
= true then
410 for loop
:= 0 to ( StringGrid_TerminalSettings
.RowCount
-1 )do
412 if loop
= ( StringGrid_TerminalSettings
.RowCount
-1 ) then
414 if StringGrid_TerminalSettings
.Cells
[0,loop
] <> '' then
416 if FileExists( StringGrid_TerminalSettings
.Cells
[1,loop
] ) then
418 Log(3, LocalChannel
, ('Col(1)Row(' + inttostr(loop
) + ') file ( ' + StringGrid_TerminalSettings
.Cells
[1,loop
] + ' ) does exists.'));
419 if FpAccess( StringGrid_TerminalSettings
.Cells
[1,loop
] , X_OK
{Exe flag check}) = 0 then
421 Log(1, LocalChannel
, ('Col(1)Row(' + inttostr(loop
) + ') file ( ' + StringGrid_TerminalSettings
.Cells
[1,loop
] + ' ) is executable.'));
427 Log(1, LocalChannel
, ('Col(1)Row(' + inttostr(loop
) + ') file (' + StringGrid_TerminalSettings
.Cells
[1,loop
] + ' ) is not executable.'));
434 Log(1, LocalChannel
, ('Col(1)Row(' + inttostr(loop
) + ') file ( ' + StringGrid_TerminalSettings
.Cells
[1,loop
] + ' ) does not exists.'));
436 end; { StringGrid_TerminalSettings.Cells[0,loop] <> '' END }
438 else { ELSE loop = ( StringGrid_TerminalSettings.RowCount -1 ) }
446 {if last row is used then add a new one}
447 if IsFine
= true then
449 if StringGrid_TerminalSettings
.cells
[0,(StringGrid_TerminalSettings
.RowCount
-1)] <> '' then
451 StringGrid_TerminalSettings
.RowCount
:= ( StringGrid_TerminalSettings
.RowCount
+ 1 );
456 if Isfine
= true then
458 TerrminalSettingsIsFine
:= true;
459 Log(0, LocalChannel
, ('Terminal settings are fine.'));
463 TerrminalSettingsIsFine
:= false;
464 Log(1, LocalChannel
, ('The is an error in the terminal settings.'));
469 if Isfine
= true then
471 TerminalPathClean
.Clear
;
472 for loop
:= 0 to ( StringGrid_TerminalSettings
.RowCount
-2 )do {Last row is ignore WILL be blank}
474 TerminalPathClean
.Add(StringGrid_TerminalSettings
.Cells
[0,loop
] );
477 UnitMain
.Form1
.ComboBox_TerminalName
.Items
:= TerminalPathClean
;
478 {INFO this will change your seleted item back to the first item, not the worlds best code but it stops crashs}
479 UnitMain
.Form1
.ComboBox_TerminalName
.Text := UnitMain
.Form1
.ComboBox_TerminalName
.Items
[0];
488 {$I UnitSettings.lrs}