UnitMain: No point in moving a button if you can not see it.
[WineLauncher.git] / UnitMain.pas
blob9f6f9dace2c7e8edf0f4fb4ad70ee0eb8493d129
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 {Made with Lazarus 0.9.26.3 fixes branch.}
17 {Free Pascal Compiler version 2.2.3.}
19 unit UnitMain;
21 {$mode objfpc}{$H+}
23 interface
25 uses
26 Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
27 DbCtrls, strutils, BaseUnix, Process, CheckLst, Math, ExtCtrls;
29 type
31 { TForm1 }
33 TForm1 = class(TForm)
34 Btn_Run: TButton;
35 Btn_DebugChannelsConfig: TButton;
36 Btn_About: TButton;
37 Btn_Settings: TButton;
38 Btn_StopScan: TButton;
39 Button_Regedit: TButton;
40 Button_Winecfg: TButton;
41 CheckBox_UseSoundWrapper: TCheckBox;
42 CheckBox_DebugChannelUse: TCheckBox;
43 CheckListBox_Flags: TCheckListBox;
44 Check_Terminal: TCheckBox;
45 ComboBox_ProgramsList: TComboBox;
46 ComboBox_Architecture: TComboBox;
47 ComboBox_DistributionVersion: TComboBox;
48 ComboBox_DistributionName: TComboBox;
49 ComboBox_PreFix: TComboBox;
50 ComboBox_SoundWrapper: TComboBox;
51 ComboBox_TerminalName: TComboBox;
52 ComboBox_WineVersion: TComboBox;
53 EditBox_ProgramPath: TEdit;
54 Label_WineVersion: TLabel;
55 Label_Flags: TLabel;
56 Label_ProgramPath: TLabel;
57 Label_ProgramsList: TLabel;
58 Label_WinePreFix: TLabel;
59 Label_DistributionName: TLabel;
60 Label_DistributionVersion: TLabel;
61 Label_Architecture: TLabel;
62 Memo_LogOutPut: TMemo;
63 TogBtn_Listdrive: TToggleBox;
65 procedure Btn_AboutClick(Sender: TObject);
66 procedure Btn_DebugChannelsConfigClick(Sender: TObject);
67 procedure Btn_RunClick(Sender: TObject);
68 procedure Btn_SettingsClick(Sender: TObject);
69 procedure Btn_StopScanClick(Sender: TObject);
70 procedure Button_RegeditClick(Sender: TObject);
71 procedure Button_WinecfgClick(Sender: TObject);
72 procedure CheckBox_UseSoundWrapperChange(Sender: TObject);
73 procedure Check_TerminalChange(Sender: TObject);
74 procedure ComboBox_ArchitectureChange(Sender: TObject);
75 procedure ComboBox_DistributionNameEditingDone(Sender: TObject);
76 procedure ComboBox_DistributionVersionEditingDone(Sender: TObject);
77 procedure ComboBox_PreFixChange(Sender: TObject);
78 procedure ComboBox_ProgramsListChange(Sender: TObject);
79 procedure ComboBox_WineVersionEditingDone(Sender: TObject);
80 procedure EditBox_ProgramPathChange(Sender: TObject);
81 procedure FormCreate(Sender: TObject);
82 procedure FormResize(Sender: TObject);
83 procedure TogBtn_ListdriveChange(Sender: TObject);
84 procedure TimerOnTimer(Sender: TObject);
86 private { private declarations }
87 procedure CheckWineVersion();
89 function Isblocked(Path:string): longint ;
91 public { public declarations }
92 procedure ListFileDir({0} Path: string; {1} FileList: TStrings; {2} GroupList: TStrings; {3} DirListClean: TStrings; {4} DirListPath: TStrings; {5} isFileList: Boolean );
93 end;
95 var
96 Form1: TForm1;
97 start_S1:string; { Script to write to the file. }
98 wine_version_full:string; { New code uses this to. }
99 RunIn:string; { terminal or shell set here }
100 NoError:Boolean; { Tbh this should not be here but im not sure need to check. }
101 Sh_Path:string; { Path for the shell }
102 GetCurrentDir:string;
103 Channel:string; { Debug channel name }
104 WinePath:string; { New var for "~/[wine-stuff]/wine/[OS name]/[OS version]/[Architecture] }
105 UnixDirPath:string; { Needed for setting the working dir at 'Run'. }
106 Mode:boolean;
107 Timer:TTimer; {The timer is a workaround.}
109 implementation
110 uses
111 UnitInitialization,
112 UnitMainBackend,
113 UnitMisc,
114 UnitDebugConfig,
115 UnitAbout,
116 UnitSettings,
117 UnitProgramsList;
119 function TForm1.Isblocked(Path:string): longint ;
121 CL:string;
122 begin
123 CL := 'Isblocked';
124 Result := 0 ;
125 { Checks to see string is backup "~" or / and hided "." }
126 if AnsiStartsText( '.', Path) = true then
127 begin
128 log( 1, CL, 'This can not be hided');
129 Result := 1;
130 exit;
132 else
133 begin
135 end;
137 if AnsiEndsText( '~', Path ) = true then
138 begin
139 log( 1, CL, 'This can not be a backup file');
140 Result := 1;
141 exit;
143 else
144 begin
146 end;
147 end;
150 procedure TForm1.ListFileDir({0} Path: string; {1} FileList: TStrings; {2} GroupList: TStrings; {3} DirListClean: TStrings; {4} DirListPath: TStrings; {5} isFileList: Boolean );
152 SR: TSearchRec;
153 begin
155 if FindFirst(Path + '*', faAnyFile , SR) = 0 then
156 begin
157 repeat
158 if ((SR.Attr and faDirectory = 0) = isFileList) then
159 begin
160 { removes folders called "." & ".." }
161 if SR.Name <> '.' then if SR.Name <> '..' then
162 begin
163 if ( DirListPath <> nil) then
164 DirListPath.Add( (path + SR.Name + '/') );
166 if ( FileList <> nil) then
167 FileList.Add(SR.Name);
168 end;
169 end;
170 until FindNext(SR) <> 0;
171 FindClose(SR);
174 end;
177 end;
180 procedure TForm1.CheckWineVersion();
182 WineCheck:string;
183 begin
184 { TODO : Add better filtering. }
186 {Get Distribution name. }
187 WineCheck := ( GetEnvironmentVariable('HOME') + '/' + WineUserFolder + '/wine/' );
188 ComboBox_DistributionName.Items.Clear;
189 ListFileDir( {0} WineCheck , {1} ComboBox_DistributionName.Items , {2} nil , {3} nil , {4} nil , {5} false );
191 { Get Distribution version. }
192 if DoesFolderExists( WineCheck, ComboBox_DistributionName.Text ) = true then
193 begin
194 ComboBox_DistributionVersion.Items.Clear;
195 ListFileDir( {0} ( WineCheck + ComboBox_DistributionName.Text + '/' ) , {1} ComboBox_DistributionVersion.Items , {2} nil , {3} nil , {4} nil , {5} false );
196 end;
198 { Get Architecture. }
199 WineCheck := ( WineCheck + ComboBox_DistributionName.Text );
200 if DoesFolderExists( WineCheck, ( '/' + ComboBox_DistributionVersion.Text )) = true then
201 begin
202 ComboBox_Architecture.Items.Clear;
203 ListFileDir( {0} ( WineCheck + '/' + ComboBox_DistributionVersion.Text + '/' ) , {1} ComboBox_Architecture.Items , {2} nil , {3} nil , {4} nil , {5} false );
204 end;
206 { Get Wine version. }
207 WineCheck := ( WineCheck + '/' + ComboBox_DistributionVersion.Text + '/' + ComboBox_Architecture.Text );
208 ComboBox_WineVersion.Items.Clear;
209 ListFileDir( {0} WineCheck + '/' , {1} ComboBox_WineVersion.Items , {2} nil , {3} nil , {4} nil , {5} false );
211 WineCheck := ( WineCheck + '/' + ComboBox_WineVersion.Text );
212 { Export var }
213 WinePath := WineCheck;
215 { Save settings }
216 SaveLastUsedConfig();
218 end;
220 procedure TForm1.FormCreate(Sender: TObject);
221 begin
222 {The timer is a workaround.}
223 Timer := TTimer.Create(nil) ;
224 Timer.OnTimer := @TimerOnTimer;
225 Timer.Enabled := false;
226 Timer.Interval := 100;
228 {Select first item.}
229 if ComboBox_SoundWrapper.items.Count <> 0 then ComboBox_SoundWrapper.Text := ComboBox_SoundWrapper.Items[0];
230 if ComboBox_TerminalName.items.Count <> 0 then ComboBox_TerminalName.Text := ComboBox_TerminalName.Items[0];
232 {Load LastUsedConfig.}
233 LoadLastUsedConfig();
235 {Get Wine path info.}
236 CheckWineVersion();
239 {$IFDEF GuiTest}
240 Btn_StopScan.Visible := true;
241 {$ENDIF}
242 end;
244 procedure TForm1.FormResize(Sender: TObject);
245 begin
246 if Btn_StopScan.Visible = true then Btn_StopScan.Left := (floor(form1.Width / 2) - floor(Btn_StopScan.Width / 2));
247 end;
249 procedure TForm1.TimerOnTimer(Sender: TObject);
251 TempList:Tstrings;
252 begin
253 {We should not use a timer to check this. The is a bug in lazarus, 'OnTerminate' of AsyncProcess never runs.}
254 if AsyncProcessScan.Active = true then
255 begin
256 Timer.Enabled := true;
257 Btn_StopScan.Visible := true;
258 FormResize(self);
260 else
261 begin
262 Btn_StopScan.Visible := false;
263 TempList := TStringlist.Create;
264 Timer.Enabled := false;
265 TempList.LoadFromStream(AsyncProcessScan.OutPut);
267 if TempList.Count = 0 then
268 begin
269 DiscErrorText := 'Drive' + wrap('D' + ':') + 'has no executable files.';
270 LastReadLinkPath := '';
272 else
273 begin
274 DiscErrorText := '';
275 end;
277 while TempList.Count <> 0 do
278 begin
279 CdData.Add(UnixToWinPath(TempList.Strings[0],'d'));
280 TempList.Delete(0);
281 end;
283 ComboBox_PreFixChange(self);
284 TempList.Destroy;
286 CheckListBox_Flags.Clear;
287 end;
288 end;
290 procedure TForm1.TogBtn_ListdriveChange(Sender: TObject);
291 begin
292 if Mode = true then
293 begin
294 Mode := false;
295 AsyncProcessScan.Active := false;
296 Btn_StopScan.Visible := false;
297 CheckListBox_Flags.Enabled := true;
298 EditBox_ProgramPath.Clear;
299 ComboBox_PreFixChange(self);
300 ComboBox_ProgramsListChange(self);
302 else
303 begin
304 Mode := true;
305 if CdData = nil then CdData := TStringlist.Create;
306 if CdDataName = nil then CdDataName := TStringlist.Create;
308 log(0,'', LastReadLinkPath);
309 ComboBox_PreFixChange(self);
310 CheckListBox_Flags.Clear;
311 EditBox_ProgramPath.Clear;
312 end;
313 end;
318 procedure TForm1.Btn_RunClick(Sender: TObject);
319 begin
320 RunWineCheck( '', '' );
321 end;
323 procedure TForm1.Btn_SettingsClick(Sender: TObject);
324 begin
325 UnitSettings.Form4.Show ;
326 end;
328 procedure TForm1.Btn_StopScanClick(Sender: TObject);
329 begin
330 AsyncProcessScan.Active := false;
331 end;
333 procedure TForm1.Button_RegeditClick(Sender: TObject);
334 begin
335 RunWineCheck( 'Regedit', '' );
336 end;
338 procedure TForm1.Button_WinecfgClick(Sender: TObject);
339 begin
340 RunWineCheck( 'winecfg', '' );
341 end;
343 procedure TForm1.CheckBox_UseSoundWrapperChange(Sender: TObject);
344 begin
345 SaveLastUsedConfig();
346 end;
348 procedure TForm1.Check_TerminalChange(Sender: TObject);
349 begin
350 SaveLastUsedConfig();
351 end;
353 procedure TForm1.ComboBox_ArchitectureChange(Sender: TObject);
354 begin
355 CheckWineVersion();
356 end;
358 procedure TForm1.ComboBox_DistributionNameEditingDone(Sender: TObject);
359 begin
360 CheckWineVersion();
361 end;
363 procedure TForm1.ComboBox_DistributionVersionEditingDone(Sender: TObject);
364 begin
365 CheckWineVersion();
366 end;
368 procedure TForm1.ComboBox_PreFixChange(Sender: TObject);
370 ChannelLocal:string;
371 myloop:integer;
372 done:boolean;
373 temp:string;
374 PrefixInt:integer;
375 begin
376 ComboBox_ProgramsList.Items.Clear;
377 done := false;
378 myloop := 1;
380 EditBox_ProgramPath.Enabled := true;
381 ComboBox_ProgramsList.Enabled := true;
383 if Mode = false then
384 begin
385 while not done do
386 begin
387 if Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop] <> '' then
388 begin
389 ComboBox_ProgramsList.Items.Add(Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop]);
390 inc(myloop);
392 else
393 begin
394 done := true;
395 end;
396 end;
398 if ComboBox_ProgramsList.Items.Count <> 0 then
399 begin
400 ComboBox_ProgramsList.ItemIndex := 0;
401 EditBox_ProgramPath.Enabled := true;
402 ComboBox_ProgramsList.Enabled := true;
403 ComboBox_ProgramsListChange(Self);
405 else
406 begin
407 ComboBox_ProgramsList.Text := '';
408 EditBox_ProgramPath.Text := '';
409 EditBox_ProgramPath.Enabled := false;
410 ComboBox_ProgramsList.Enabled := false;
411 end;
414 else
415 begin
416 ListProgramsOnDisc(CdData, 'D');
417 if CdData.Text <> '' then
418 begin
419 CdDataName.Clear;
420 CdDataName.AddStrings(CdData);
422 for myloop := 0 to CdDataName.Count -1 do
423 begin
424 {Take path and return the file name only.}
425 CdDataName.Strings[myloop] := GetWinFileName(CdDataName.Strings[myloop]);
426 end;
427 ComboBox_ProgramsList.Items := CdDataName;
428 if ComboBox_ProgramsList.Items.Count <> 0 then
429 begin
430 ComboBox_ProgramsList.Text := ComboBox_ProgramsList.Items[0];
431 EditBox_ProgramPath.Enabled := true;
432 ComboBox_ProgramsList.Enabled := true;
433 ComboBox_ProgramsListChange(self);
434 end;
437 else
438 begin
439 ComboBox_ProgramsList.Text := DiscErrorText;
440 EditBox_ProgramPath.Text := '';
441 EditBox_ProgramPath.Enabled := false;
442 ComboBox_ProgramsList.Enabled := false;
443 CheckListBox_Flags.Clear;
444 end;
446 end;
447 end;
449 procedure TForm1.ComboBox_ProgramsListChange(Sender: TObject);
451 ProgramsListSelectedItem:integer;
452 PrefixInt:integer;
453 begin
454 if Mode = false then
455 begin
456 PrefixInt := FindPrefixInt(ComboBox_PreFix.Items.Strings[ComboBox_PreFix.ItemIndex]);
457 EditBox_ProgramPath.Enabled := true;
458 {Plus one to line it up with the grid}
459 ProgramsListSelectedItem := (Data[PrefixInt].Grid.cols[DataNameCol].IndexOf(Data[PrefixInt].Grid.cols[DataNameCol].Strings[ComboBox_ProgramsList.ItemIndex]) +1);
460 {Cells[{Col},{Row}]}
461 EditBox_ProgramPath.Text := Data[PrefixInt].Grid.Cells[DataPathCol, ProgramsListSelectedItem] ;
462 CutUpFlags(Data[PrefixInt].Grid.Cells[DataFlagsCol, ProgramsListSelectedItem]);
464 else
465 begin
466 if CdData.Text <> '' then
467 begin
468 EditBox_ProgramPath.Text := CdData.Strings[CdDataName.IndexOf(ComboBox_ProgramsList.Text)] ;
469 end;
470 end;
471 end;
473 procedure TForm1.ComboBox_WineVersionEditingDone(Sender: TObject);
474 begin
475 CheckWineVersion();
476 end;
478 procedure TForm1.EditBox_ProgramPathChange(Sender: TObject);
479 begin
480 ColourCheck(EditBox_ProgramPath);
481 end;
484 procedure TForm1.Btn_AboutClick(Sender: TObject);
485 begin
486 UnitAbout.Form3.Show ;
487 end;
489 procedure TForm1.Btn_DebugChannelsConfigClick(Sender: TObject);
490 begin
491 UnitDebugConfig.Form2.Show ;
492 end;
497 initialization
498 {$I UnitMain.lrs}
500 end.