UnitMain: Replace the name of Label1 with Label_WineVersion.
[WineLauncher.git] / UnitMain.pas
blob4b35b74c370714d35ec915a760af6e180ee4dfd2
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 fixes branch. }
17 { Fpc 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, AsyncProcess, ExtCtrls, Math;
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 ConfigPath:string;
102 Sh_Path:string; { Path for the shell }
103 GetCurrentDir:string;
104 AProcess: TProcess;
105 Channel:string; { Debug channel name }
106 HideChannel:boolean; { Cut down on the spam }
107 IgnoreChannelList:Tstrings;
108 WinePath:string; { New var for "~/[wine-stuff]/wine/[OS name]/[OS version]/[Architecture] }
109 WineUserFolder:string; { E.G. "wine-stuff" }
110 UnixDirPath:string; { Needed for setting the working dir at 'Run'. }
111 Mode:boolean;
112 AsyncProcessScan:TAsyncProcess;
113 Timer:TTimer;
115 implementation
116 uses UnitMisc, UnitDebugConfig, UnitAbout, UnitSettings, UnitProgramsList;
118 { TForm1 }
120 function TForm1.Isblocked(Path:string): longint ;
122 CL:string;
123 begin
124 CL := 'Isblocked';
125 Result := 0 ;
126 { Checks to see string is backup "~" or / and hided "." }
127 if AnsiStartsText( '.', Path) = true then
128 begin
129 log( 1, CL, 'This can not be hided');
130 Result := 1;
131 exit;
133 else
134 begin
136 end;
138 if AnsiEndsText( '~', Path ) = true then
139 begin
140 log( 1, CL, 'This can not be a backup file');
141 Result := 1;
142 exit;
144 else
145 begin
147 end;
148 end;
151 procedure TForm1.ListFileDir({0} Path: string; {1} FileList: TStrings; {2} GroupList: TStrings; {3} DirListClean: TStrings; {4} DirListPath: TStrings; {5} isFileList: Boolean );
153 SR: TSearchRec;
154 begin
156 if FindFirst(Path + '*', faAnyFile , SR) = 0 then
157 begin
158 repeat
159 if ((SR.Attr and faDirectory = 0) = isFileList) then
160 begin
161 { removes folders called "." & ".." }
162 if SR.Name <> '.' then if SR.Name <> '..' then
163 begin
164 if ( DirListPath <> nil) then
165 DirListPath.Add( (path + SR.Name + '/') );
167 if ( FileList <> nil) then
168 FileList.Add(SR.Name);
169 end;
170 end;
171 until FindNext(SR) <> 0;
172 FindClose(SR);
175 end;
178 end;
181 procedure TForm1.CheckWineVersion();
183 WineCheck:string;
184 begin
185 { TODO : Add better filtering. }
187 {Get Distribution name. }
188 WineCheck := ( GetEnvironmentVariable('HOME') + '/' + WineUserFolder + '/wine/' );
189 ComboBox_DistributionName.Items.Clear;
190 ListFileDir( {0} WineCheck , {1} ComboBox_DistributionName.Items , {2} nil , {3} nil , {4} nil , {5} false );
192 { Get Distribution version. }
193 if DoesFolderExists( WineCheck, ComboBox_DistributionName.Text ) = true then
194 begin
195 ComboBox_DistributionVersion.Items.Clear;
196 ListFileDir( {0} ( WineCheck + ComboBox_DistributionName.Text + '/' ) , {1} ComboBox_DistributionVersion.Items , {2} nil , {3} nil , {4} nil , {5} false );
197 end;
199 { Get Architecture. }
200 WineCheck := ( WineCheck + ComboBox_DistributionName.Text );
201 if DoesFolderExists( WineCheck, ( '/' + ComboBox_DistributionVersion.Text )) = true then
202 begin
203 ComboBox_Architecture.Items.Clear;
204 ListFileDir( {0} ( WineCheck + '/' + ComboBox_DistributionVersion.Text + '/' ) , {1} ComboBox_Architecture.Items , {2} nil , {3} nil , {4} nil , {5} false );
205 end;
207 { Get Wine version. }
208 WineCheck := ( WineCheck + '/' + ComboBox_DistributionVersion.Text + '/' + ComboBox_Architecture.Text );
209 ComboBox_WineVersion.Items.Clear;
210 ListFileDir( {0} WineCheck + '/' , {1} ComboBox_WineVersion.Items , {2} nil , {3} nil , {4} nil , {5} false );
212 WineCheck := ( WineCheck + '/' + ComboBox_WineVersion.Text );
213 { Export var }
214 WinePath := WineCheck;
216 { Save settings }
217 SaveLastUsedConfig();
219 end;
221 procedure TForm1.FormCreate(Sender: TObject);
222 begin
223 { TODO : Change all code to uses this var. }
224 WineUserFolder := 'wine-stuff';
225 Channel := (Form1.Name +'.FormCreate');
226 HideChannel := true; {Cut down on the logging spam.}
227 ConfigPath := (GetEnvironmentVariable('HOME') + '/.config/WineLauncher');
228 AProcess := TProcess.Create(nil); {Used in RunWineCheck.}
230 {Check all the files and folders this program needs to access.}
231 if CheckPaths() <> true then halt();
233 {Select first item.}
234 if ComboBox_SoundWrapper.items.Count <> 0 then ComboBox_SoundWrapper.Text := ComboBox_SoundWrapper.Items[0];
235 if ComboBox_TerminalName.items.Count <> 0 then ComboBox_TerminalName.Text := ComboBox_TerminalName.Items[0];
237 {Load LastUsedConfig.}
238 LoadLastUsedConfig();
240 {Get Wine path info.}
241 CheckWineVersion();
244 AsyncProcessScan := TAsyncProcess.Create(nil) ;
245 AsyncProcessScan.Options := AsyncProcessScan.Options + [poUsePipes,poStderrToOutPut,poNoconsole,poNewProcessGroup];
246 Timer := TTimer.Create(nil) ;
247 Timer.OnTimer := @TimerOnTimer;
248 Timer.Enabled := false;
249 Timer.Interval := 100;
251 {$IFDEF GuiTest}
252 Btn_StopScan.Visible := true;
253 {$ENDIF}
254 end;
256 procedure TForm1.FormResize(Sender: TObject);
257 begin
258 Btn_StopScan.Left := (floor(form1.Width / 2) - floor(Btn_StopScan.Width / 2));
259 end;
261 procedure TForm1.TimerOnTimer(Sender: TObject);
263 TempList:Tstrings;
264 begin
265 { We should not use a timer to check this. The is a bug in lazarus, 'OnTerminate' of AsyncProcess never runs.}
266 if AsyncProcessScan.Active = true then
267 begin
268 Timer.Enabled := true;
269 Btn_StopScan.Visible := true;
271 else
272 begin
273 Btn_StopScan.Visible := false;
274 TempList := TStringlist.Create;
275 Timer.Enabled := false;
276 TempList.LoadFromStream(AsyncProcessScan.OutPut);
278 if TempList.Count = 0 then
279 begin
280 DiscErrorText := 'Drive' + wrap('D' + ':') + 'has no executable files.';
281 LastReadLinkPath := '';
283 else
284 begin
285 DiscErrorText := '';
286 end;
288 while TempList.Count <> 0 do
289 begin
290 CdData.Add(UnixToWinPath(TempList.Strings[0],'d'));
291 TempList.Delete(0);
292 end;
294 ComboBox_PreFixChange(self);
295 TempList.Destroy;
297 CheckListBox_Flags.Clear;
298 end;
299 end;
301 procedure TForm1.TogBtn_ListdriveChange(Sender: TObject);
302 begin
303 if Mode = true then
304 begin
305 Mode := false;
306 AsyncProcessScan.Active := false;
307 Btn_StopScan.Visible := false;
308 CheckListBox_Flags.Enabled := true;
309 EditBox_ProgramPath.Clear;
310 ComboBox_PreFixChange(self);
311 ComboBox_ProgramsListChange(self);
313 else
314 begin
315 Mode := true;
316 if CdData = nil then CdData := TStringlist.Create;
317 if CdDataName = nil then CdDataName := TStringlist.Create;
319 log(0,'', LastReadLinkPath);
320 ComboBox_PreFixChange(self);
321 CheckListBox_Flags.Clear;
322 EditBox_ProgramPath.Clear;
323 end;
324 end;
329 procedure TForm1.Btn_RunClick(Sender: TObject);
330 begin
331 RunWineCheck( '', '' );
332 end;
334 procedure TForm1.Btn_SettingsClick(Sender: TObject);
335 begin
336 UnitSettings.Form4.Show ;
337 end;
339 procedure TForm1.Btn_StopScanClick(Sender: TObject);
340 begin
341 AsyncProcessScan.Active := false;
342 end;
344 procedure TForm1.Button_RegeditClick(Sender: TObject);
345 begin
346 RunWineCheck( 'Regedit', '' );
347 end;
349 procedure TForm1.Button_WinecfgClick(Sender: TObject);
350 begin
351 RunWineCheck( 'winecfg', '' );
352 end;
354 procedure TForm1.CheckBox_UseSoundWrapperChange(Sender: TObject);
355 begin
356 SaveLastUsedConfig();
357 end;
359 procedure TForm1.Check_TerminalChange(Sender: TObject);
360 begin
361 SaveLastUsedConfig();
362 end;
364 procedure TForm1.ComboBox_ArchitectureChange(Sender: TObject);
365 begin
366 CheckWineVersion();
367 end;
369 procedure TForm1.ComboBox_DistributionNameEditingDone(Sender: TObject);
370 begin
371 CheckWineVersion();
372 end;
374 procedure TForm1.ComboBox_DistributionVersionEditingDone(Sender: TObject);
375 begin
376 CheckWineVersion();
377 end;
379 procedure TForm1.ComboBox_PreFixChange(Sender: TObject);
381 ChannelLocal:string;
382 myloop:integer;
383 done:boolean;
384 temp:string;
385 PrefixInt:integer;
386 begin
387 ComboBox_ProgramsList.Items.Clear;
388 done := false;
389 myloop := 1;
391 EditBox_ProgramPath.Enabled := true;
392 ComboBox_ProgramsList.Enabled := true;
394 if Mode = false then
395 begin
396 while not done do
397 begin
398 if Data[ComboBox_PreFix.ItemIndex].Grid.Cells[0, myloop] <> '' then
399 begin
400 ComboBox_ProgramsList.Items.Add(Data[ComboBox_PreFix.ItemIndex].Grid.Cells[0, myloop]);
401 inc(myloop);
403 else
404 begin
405 done := true;
406 end;
407 end;
409 if ComboBox_ProgramsList.Items.Count <> 0 then
410 begin
411 ComboBox_ProgramsList.Text := ComboBox_ProgramsList.Items[0];
412 ComboBox_ProgramsListChange(Self);
413 EditBox_ProgramPath.Enabled := true;
414 ComboBox_ProgramsList.Enabled := true;
416 else
417 begin
418 ComboBox_ProgramsList.Text := '';
419 EditBox_ProgramPath.Text := '';
420 EditBox_ProgramPath.Enabled := false;
421 ComboBox_ProgramsList.Enabled := false;
422 end;
425 else
426 begin
427 ListProgramsOnDisc(CdData, 'D');
428 if CdData.Text <> '' then
429 begin
430 CdDataName.Clear;
431 CdDataName.AddStrings(CdData);
433 for myloop := 0 to CdDataName.Count -1 do
434 begin
435 temp := CdDataName.Strings[myloop];
436 temp := AnsiReverseString(temp);
437 temp := Copy2Symb(temp, '\');
438 Copy2SymbDel(temp, '.');
439 temp := AnsiReverseString(temp);
441 CdDataName.Strings[myloop] := temp;
442 end;
443 ComboBox_ProgramsList.Items := CdDataName;
444 if ComboBox_ProgramsList.Items.Count <> 0 then
445 begin
446 ComboBox_ProgramsList.Text := ComboBox_ProgramsList.Items[0];
447 EditBox_ProgramPath.Enabled := true;
448 ComboBox_ProgramsList.Enabled := true;
449 ComboBox_ProgramsListChange(self);
450 end;
453 else
454 begin
455 ComboBox_ProgramsList.Text := DiscErrorText;
456 EditBox_ProgramPath.Text := '';
457 EditBox_ProgramPath.Enabled := false;
458 ComboBox_ProgramsList.Enabled := false;
459 CheckListBox_Flags.Clear;
460 end;
462 end;
463 end;
465 procedure TForm1.ComboBox_ProgramsListChange(Sender: TObject);
467 ProgramsListSelectedItem:integer;
468 PrefixInt:integer;
469 begin
470 if Mode = false then
471 begin
472 PrefixInt := FindPrefixInt(ComboBox_PreFix.Items.Strings[ComboBox_PreFix.ItemIndex]);
473 EditBox_ProgramPath.Enabled := true;
474 {Plus one to line it up with the grid}
475 ProgramsListSelectedItem := (Data[PrefixInt].Grid.cols[0].IndexOf(Data[PrefixInt].Grid.cols[0].Strings[ComboBox_ProgramsList.ItemIndex]) +1);
476 {Cells[{Col},{Row}]}
477 EditBox_ProgramPath.Text := Data[PrefixInt].Grid.Cells[1, ProgramsListSelectedItem] ;
478 CutUpFlags(Data[PrefixInt].Grid.Cells[2, ProgramsListSelectedItem]);
481 else
482 begin
483 if CdData.Text <> '' then
484 begin
485 EditBox_ProgramPath.Text := CdData.Strings[CdDataName.IndexOf(ComboBox_ProgramsList.Text)] ;
486 end;
487 end;
488 end;
490 procedure TForm1.ComboBox_WineVersionEditingDone(Sender: TObject);
491 begin
492 CheckWineVersion();
493 end;
495 procedure TForm1.EditBox_ProgramPathChange(Sender: TObject);
496 begin
497 ColourCheck(EditBox_ProgramPath);
498 end;
501 procedure TForm1.Btn_AboutClick(Sender: TObject);
502 begin
503 UnitAbout.Form3.Show ;
504 end;
506 procedure TForm1.Btn_DebugChannelsConfigClick(Sender: TObject);
507 begin
508 UnitDebugConfig.Form2.Show ;
509 end;
514 initialization
515 {$I UnitMain.lrs}
517 end.