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/>.
23 Classes
, SysUtils
, LResources
, Forms
, Controls
, Graphics
, Dialogs
, StdCtrls
, BaseUnix
,
32 ComboBox_PreFix
: TComboBox
;
33 ComboBox_ShellPath
: TComboBox
;
36 StringGrid_TerminalSettings
: TStringGrid
;
37 StringGrid_ProgramsList
: TStringGrid
;
39 procedure ComboBox_PreFixChange(Sender
: TObject
);
40 procedure ComboBox_ShellPathEditingDone(Sender
: TObject
);
41 procedure FormClose(Sender
: TObject
; var CloseAction
: TCloseAction
);
42 procedure FormCreate(Sender
: TObject
);
43 procedure StringGrid_ProgramsListDrawCell(Sender
: TObject
; aCol
,
44 aRow
: Integer; aRect
: TRect
; aState
: TGridDrawState
);
45 procedure StringGrid_ProgramsListEditingDone(Sender
: TObject
);
46 procedure StringGrid_TerminalSettingsEditingDone(Sender
: TObject
);
48 function PreFixExists():boolean;
51 procedure ProgramsUpdate();
54 { public declarations }
59 TerminalPathClean
:Tstrings
;
60 TerminalPathFlags
:Tstrings
;
61 TerrminalSettingsIsFine
:boolean;
62 ShellPathIsFine
:boolean;
63 ProgramsList
:Tstrings
;
72 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
.StringGrid_ProgramsListDrawCell(Sender
: TObject
; aCol
,
132 aRow
: Integer; aRect
: TRect
; aState
: TGridDrawState
);
134 StringGrid_ProgramsList
.AutoSizeColumns
;
137 procedure TForm4
.StringGrid_ProgramsListEditingDone(Sender
: TObject
);
143 LocalChannel
:= 'StringGrid_ProgramsListEditingDone';
145 {TODO Went Editing this runs two times, abit pointless and not CPU friendy}
146 {TODO may add some checks to the flags. Can that be done ?}
149 Log(5, LocalChannel
, ('-----------------'));
150 Log(3, LocalChannel
, ( StringGrid_ProgramsList
.Name
+ ' editing has finished.' ));
152 for loop
:= 1 to StringGrid_ProgramsList
.Cols
[DataNameCol
].Count
-1 do
154 if (StringGrid_ProgramsList
.Cells
[DataNameCol
,loop
]) = '' then
156 StringGrid_ProgramsList
.MoveColRow(false,loop
, (StringGrid_ProgramsList
.Cols
[DataNameCol
].Count
-1)) ;
157 StringGrid_ProgramsList
.Rows
[StringGrid_ProgramsList
.Cols
[DataNameCol
].Count
-1].Clear
;
165 procedure TForm4
.ProgramsUpdate();
171 PrefixInt
:= FindPrefixInt(ComboBox_PreFix
.Items
.Strings
[ComboBox_PreFix
.ItemIndex
]);
172 for B
:= 0 to Data
[PrefixInt
].Grid
.RowCount
-1 do
174 Data
[PrefixInt
].Grid
.Rows
[B
].Text := StringGrid_ProgramsList
.Rows
[B
].text;
178 function TForm4
.PreFixExists():boolean;
180 PreFixFolders
:Tstrings
;
185 ChannelLocal
:= ('PreFixExists');
186 { TODO : procedure for telling you a procedure has being called. }
187 Log(5, '', ('-----------------'));
188 Log(0, ChannelLocal
, ('PreFixExists has being Called.'));
190 CheckList
:= TStringlist
.Create
;
191 PreFixFolders
:= TStringlist
.Create
;
194 CheckList
.Add('/dosdevices') ;
195 CheckList
.Add('/drive_c') ;
197 { TODO : ListFileDir can only handly one path at ones }
199 ListFileDir({0} PathToPrefix
, {1} PreFixFolders
, {2} nil, {3} nil, {4} nil, {5} false);
201 for loop
:= 0 to (PreFixFolders
.Count
-1) do
203 if AnsiEndsText('~', PreFixFolders
.Strings
[loop
]) = false then
205 { Folder and file check. }
207 if DoesFoldersExists((PathToPrefix
+ PreFixFolders
.Strings
[loop
]), CheckList
) = true then
209 if FileExistsAndIsExecutable(PathToPrefix
+ PreFixFolders
.Strings
[loop
] + '/system.reg',true) = true then
211 if FileExistsAndIsExecutable(PathToPrefix
+ PreFixFolders
.Strings
[loop
] + '/user.reg', true) = true then
213 PreFixList
[0].add(PreFixFolders
.Strings
[loop
]);
214 PreFixList
[1].add(PathToPrefix
+ PreFixFolders
.Strings
[loop
]);
222 if PreFixList
[0].Count
<> 0 then
224 {Sych Tstrings with Comobox.}
225 UnitMain
.Form1
.ComboBox_PreFix
.Items
:= PreFixList
[0];
226 ComboBox_PreFix
.Items
:= PreFixList
[0];
228 {Cheep hack to stop crashs.}
229 UnitMain
.Form1
.ComboBox_PreFix
.Text := UnitMain
.Form1
.ComboBox_PreFix
.Items
[0];
230 ComboBox_PreFix
.Text := ComboBox_PreFix
.Items
[0];
241 PreFixFolders
.Destroy
;
246 procedure TForm4
.FormClose(Sender
: TObject
; var CloseAction
: TCloseAction
);
252 { TODO : Set LocalChannel. }
255 Log(5, LocalChannel
, ('-----------------'));
256 Log(3, LocalChannel
, ( Form4
.Name
+ ' close has happen.' ));
259 for loop
:= 0 to (PreFixList
[0].Count
-1) do
261 ProgramsListSavePrefix(PreFixList
[0][loop
]);
265 {Temp save of StringGrid_TerminalSettings}
266 if TerrminalSettingsIsFine
= true then
268 Log(3, LocalChannel
, ( 'Saving' + Wrap(StringGrid_TerminalSettings
.Name
) + 'to' + Wrap(ConfigPath
+ '/StringGrid_TerminalSettings') ));
269 StringGrid_TerminalSettings
.SaveOptions
:= [soDesign
,{soAttributes,}soContent
{,soPosition}] ;
270 {TODO error checking for save.}
271 StringGrid_TerminalSettings
.SaveToFile( ConfigPath
+ '/StringGrid_TerminalSettings' );
275 Log(1, LocalChannel
, ('Not saving' + Wrap(StringGrid_TerminalSettings
.Name
) + 'because the is something wrong with it.'));
281 {Remember the selected item.}
282 TempInt
:= UnitMain
.Form1
.ComboBox_ProgramsList
.ItemIndex
;
283 {Update ComboBox_PreFix, This clears ComboBox_ProgramsList.}
284 UnitMain
.Form1
.ComboBox_PreFixChange(self
);
285 {Write back the remembered selected item.}
286 UnitMain
.Form1
.ComboBox_ProgramsList
.ItemIndex
:= TempInt
;
287 {This updates EditBox_ProgramPath.}
288 UnitMain
.Form1
.ComboBox_ProgramsListChange(self
);
290 {Note flag settings are losted.}
295 procedure TForm4
.ComboBox_ShellPathEditingDone(Sender
: TObject
);
299 { TODO : Set LocalChannel. }
302 Log(5, LocalChannel
, ('-----------------'));
303 Log(3, LocalChannel
, ( ComboBox_ShellPath
.Name
+ ' editing has finished.' ));
305 if FileExistsAndIsExecutable( {FullPath:string}ComboBox_ShellPath
.text, {JustCheckExists:boolean}false ) = true then
307 ShellPathIsFine
:= true;
308 { TODO -cColour : Work out why "clwindow" does not work. }
309 ComboBox_ShellPath
.Color
:= clwhite
;
313 ShellPathIsFine
:= false;
314 ComboBox_ShellPath
.Color
:= clred
;
319 procedure TForm4
.ComboBox_PreFixChange(Sender
: TObject
);
324 StringGrid_ProgramsList
.Clean
;
325 StringGrid_ProgramsList
.FixedRows
:= 1 ;
326 PrefixInt
:= FindPrefixInt(ComboBox_PreFix
.Items
.Strings
[ComboBox_PreFix
.ItemIndex
]);
330 StringGrid_ProgramsList
.Rows
[B
].text := Data
[PrefixInt
].Grid
.Rows
[B
].Text;
335 procedure TForm4
.StringGrid_TerminalSettingsEditingDone(Sender
: TObject
);
342 { TODO : Went Editing this runs two times, abit pointless and not CPU friendy}
343 { TODO : May add some checks to the flags. Can that be done ?}
344 { TODO : Set LocalChannel. }
349 Log(5, LocalChannel
, ('-----------------'));
350 Log(3, LocalChannel
, ( StringGrid_TerminalSettings
.Name
+ ' editing has finished.'));
352 {USEFUL INFO: stringGrid.Cells[col,row] }
354 {Check the no row is blank other then the last one}
355 if IsFine
= true then
357 for loop
:= 0 to ( StringGrid_TerminalSettings
.RowCount
-2 )do {Ignore last row}
359 {TODO : check the whole row not just the frist cell }
360 if StringGrid_TerminalSettings
.Cells
[0,loop
] = '' then {delete it!}
362 StringGrid_TerminalSettings
.DeleteColRow(false,loop
);
363 Log(4, LocalChannel
, ('Not Fine deleting row.'));
364 exit
; {exit or out of range error}
374 {Check the Names are unique or you can get the wrong path}
375 if IsFine
= true then
377 //UnitMain.form1.log('Running Check the Names are unique');
378 for loop
:= 1 to ( StringGrid_TerminalSettings
.RowCount
-1 )do
380 for loop2
:= 0 to ( StringGrid_TerminalSettings
.RowCount
-1 )do
382 if StringGrid_TerminalSettings
.cells
[0,loop
] = StringGrid_TerminalSettings
.cells
[0,loop2
] then
384 if loop2
<> loop
then
387 Log(4, LocalChannel
, ( 'Col(0)Row(' + inttostr(loop
) + ') has the same name as Col(0)Row(' + inttostr(loop2
) + ').'));
400 {Check that Path does exists and is executable.}
401 if IsFine
= true then
403 for loop
:= 0 to ( StringGrid_TerminalSettings
.RowCount
-1 )do
405 if loop
= ( StringGrid_TerminalSettings
.RowCount
-1 ) then
407 if StringGrid_TerminalSettings
.Cells
[0,loop
] <> '' then
409 if FileExists( StringGrid_TerminalSettings
.Cells
[1,loop
] ) then
411 Log(3, LocalChannel
, ('Col(1)Row(' + inttostr(loop
) + ') file ( ' + StringGrid_TerminalSettings
.Cells
[1,loop
] + ' ) does exists.'));
412 if FpAccess( StringGrid_TerminalSettings
.Cells
[1,loop
] , X_OK
{Exe flag check}) = 0 then
414 Log(1, LocalChannel
, ('Col(1)Row(' + inttostr(loop
) + ') file ( ' + StringGrid_TerminalSettings
.Cells
[1,loop
] + ' ) is executable.'));
420 Log(1, LocalChannel
, ('Col(1)Row(' + inttostr(loop
) + ') file (' + StringGrid_TerminalSettings
.Cells
[1,loop
] + ' ) is not executable.'));
427 Log(1, LocalChannel
, ('Col(1)Row(' + inttostr(loop
) + ') file ( ' + StringGrid_TerminalSettings
.Cells
[1,loop
] + ' ) does not exists.'));
429 end; { StringGrid_TerminalSettings.Cells[0,loop] <> '' END }
431 else { ELSE loop = ( StringGrid_TerminalSettings.RowCount -1 ) }
439 {if last row is used then add a new one}
440 if IsFine
= true then
442 if StringGrid_TerminalSettings
.cells
[0,(StringGrid_TerminalSettings
.RowCount
-1)] <> '' then
444 StringGrid_TerminalSettings
.RowCount
:= ( StringGrid_TerminalSettings
.RowCount
+ 1 );
449 if Isfine
= true then
451 TerrminalSettingsIsFine
:= true;
452 Log(0, LocalChannel
, ('Terminal settings are fine.'));
456 TerrminalSettingsIsFine
:= false;
457 Log(1, LocalChannel
, ('The is an error in the terminal settings.'));
462 if Isfine
= true then
464 TerminalPathClean
.Clear
;
465 for loop
:= 0 to ( StringGrid_TerminalSettings
.RowCount
-2 )do {Last row is ignore WILL be blank}
467 TerminalPathClean
.Add(StringGrid_TerminalSettings
.Cells
[0,loop
] );
470 UnitMain
.Form1
.ComboBox_TerminalName
.Items
:= TerminalPathClean
;
471 {INFO this will change your seleted item back to the first item, not the worlds best code but it stops crashs}
472 UnitMain
.Form1
.ComboBox_TerminalName
.Text := UnitMain
.Form1
.ComboBox_TerminalName
.Items
[0];
481 {$I UnitSettings.lrs}