UnitMain: Make the Wine version selecting combo boxes read only.
[WineLauncher.git] / UnitMain.pas
blobb3321f99a6cd436a7340dd60c7e8fd11f37eecd5
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 ComboBox_ArchitectureEditingDone(Sender: TObject);
73 procedure ComboBox_ArchitectureEnter(Sender: TObject);
74 procedure ComboBox_DistributionNameEditingDone(Sender: TObject);
75 procedure ComboBox_DistributionNameEnter(Sender: TObject);
76 procedure ComboBox_DistributionVersionEditingDone(Sender: TObject);
77 procedure ComboBox_DistributionVersionEnter(Sender: TObject);
78 procedure ComboBox_PreFixChange(Sender: TObject);
79 procedure ComboBox_ProgramsListChange(Sender: TObject);
80 procedure ComboBox_WineVersionEditingDone(Sender: TObject);
81 procedure ComboBox_WineVersionEnter(Sender: TObject);
82 procedure EditBox_ProgramPathChange(Sender: TObject);
83 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
84 procedure FormCreate(Sender: TObject);
85 procedure FormResize(Sender: TObject);
86 procedure TogBtn_ListdriveChange(Sender: TObject);
87 procedure TimerOnTimer(Sender: TObject);
89 private { private declarations }
91 public { public declarations }
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 UnixDirPath:string; { Needed for setting the working dir at 'Run'. }
105 Mode:boolean;
106 Timer:TTimer; {The timer is a workaround.}
108 implementation
109 uses
110 UnitInitialization,
111 UnitMainBackend,
112 UnitMisc,
113 UnitDebugConfig,
114 UnitAbout,
115 UnitSettings,
116 UnitProgramsList;
118 procedure TForm1.FormCreate(Sender: TObject);
119 begin
120 {The timer is a workaround.}
121 Timer := TTimer.Create(nil) ;
122 Timer.OnTimer := @TimerOnTimer;
123 Timer.Enabled := false;
124 Timer.Interval := 100;
126 {Select first item.}
127 if ComboBox_SoundWrapper.items.Count <> 0 then ComboBox_SoundWrapper.Text := ComboBox_SoundWrapper.Items[0];
128 if ComboBox_TerminalName.items.Count <> 0 then ComboBox_TerminalName.Text := ComboBox_TerminalName.Items[0];
130 {Scan for wine.}
131 ComboBox_DistributionNameEnter(Self);
133 {Load LastUsedConfig.}
134 LoadLastUsedConfig();
136 {$IFDEF GuiTest}
137 Btn_StopScan.Visible := true;
138 {$ENDIF}
139 end;
141 procedure TForm1.FormResize(Sender: TObject);
142 begin
143 if Btn_StopScan.Visible = true then Btn_StopScan.Left := (floor(form1.Width / 2) - floor(Btn_StopScan.Width / 2));
144 end;
146 procedure TForm1.TimerOnTimer(Sender: TObject);
148 TempList:Tstrings;
149 begin
150 {We should not use a timer to check this. The is a bug in lazarus, 'OnTerminate' of AsyncProcess never runs.}
151 if AsyncProcessScan.Active = true then
152 begin
153 Timer.Enabled := true;
154 Btn_StopScan.Visible := true;
155 FormResize(self);
157 else
158 begin
159 Btn_StopScan.Visible := false;
160 TempList := TStringlist.Create;
161 Timer.Enabled := false;
162 TempList.LoadFromStream(AsyncProcessScan.OutPut);
164 if TempList.Count = 0 then
165 begin
166 DiscErrorText := 'Drive' + wrap('D' + ':') + 'has no executable files.';
167 LastReadLinkPath := '';
169 else
170 begin
171 DiscErrorText := '';
172 end;
174 while TempList.Count <> 0 do
175 begin
176 CdData.Add(UnixToWinPath(TempList.Strings[0],'d'));
177 TempList.Delete(0);
178 end;
180 ComboBox_PreFixChange(self);
181 TempList.Destroy;
183 CheckListBox_Flags.Clear;
184 end;
185 end;
187 procedure TForm1.TogBtn_ListdriveChange(Sender: TObject);
188 begin
189 if Mode = true then
190 begin
191 Mode := false;
192 AsyncProcessScan.Active := false;
193 Btn_StopScan.Visible := false;
194 CheckListBox_Flags.Enabled := true;
195 EditBox_ProgramPath.Clear;
196 ComboBox_PreFixChange(self);
197 ComboBox_ProgramsListChange(self);
199 else
200 begin
201 Mode := true;
202 if CdData = nil then CdData := TStringlist.Create;
203 if CdDataName = nil then CdDataName := TStringlist.Create;
205 log(0,'', LastReadLinkPath);
206 ComboBox_PreFixChange(self);
207 CheckListBox_Flags.Clear;
208 EditBox_ProgramPath.Clear;
209 end;
210 end;
215 procedure TForm1.Btn_RunClick(Sender: TObject);
216 begin
217 RunWineCheck( '', '' );
218 end;
220 procedure TForm1.Btn_SettingsClick(Sender: TObject);
221 begin
222 UnitSettings.Form4.Show ;
223 end;
225 procedure TForm1.Btn_StopScanClick(Sender: TObject);
226 begin
227 AsyncProcessScan.Active := false;
228 end;
230 procedure TForm1.Button_RegeditClick(Sender: TObject);
231 begin
232 RunWineCheck( 'Regedit', '' );
233 end;
235 procedure TForm1.Button_WinecfgClick(Sender: TObject);
236 begin
237 RunWineCheck( 'winecfg', '' );
238 end;
240 procedure TForm1.ComboBox_ArchitectureEditingDone(Sender: TObject);
241 begin
242 WineVersionEditingDone();
243 OnWineVersionChange();
244 end;
246 procedure TForm1.ComboBox_ArchitectureEnter(Sender: TObject);
248 ItemTextName:string;
249 ItemTextVersion:string;
250 begin
251 //Log(0, '', 'Running Architecture');
252 if ComboBox_DistributionName.ItemIndex <> -1 then
253 begin
254 ItemTextName := ComboBox_DistributionName.Items.Strings[ComboBox_DistributionName.ItemIndex];
255 if ComboBox_DistributionVersion.ItemIndex <> -1 then
256 begin
257 ItemTextVersion := ComboBox_DistributionVersion.Items.Strings[ComboBox_DistributionVersion.ItemIndex];
258 FolderScan(ComboBox_Architecture, (PathToWine + ItemTextName + '/' + ItemTextVersion + '/'));
259 ComboBox_WineVersionEnter(self);
260 end;
261 end;
262 OnWineVersionChange();
263 end;
265 procedure TForm1.ComboBox_DistributionNameEditingDone(Sender: TObject);
266 begin
267 WineVersionEditingDone();
268 OnWineVersionChange();
269 end;
272 procedure TForm1.ComboBox_DistributionNameEnter(Sender: TObject);
273 begin
274 //Log(0, '', 'Running DistributionName');
275 if DoesFolderExists(PathToWine) = true then
276 begin
277 FolderScan(ComboBox_DistributionName, PathToWine);
278 end;
279 ComboBox_DistributionVersionEnter(self);
280 end;
282 procedure TForm1.ComboBox_DistributionVersionEditingDone(Sender: TObject);
283 begin
284 WineVersionEditingDone();
285 OnWineVersionChange();
286 end;
288 procedure TForm1.ComboBox_DistributionVersionEnter(Sender: TObject);
290 ItemText:string;
291 FullPath:string;
292 begin
293 //Log(0, '', 'Running DistributionVersion');
294 if ComboBox_DistributionName.ItemIndex <> -1 then
295 begin
296 ItemText := ComboBox_DistributionName.Items.Strings[ComboBox_DistributionName.ItemIndex];
297 FolderScan(ComboBox_DistributionVersion, (PathToWine + ComboBox_DistributionName.Text + '/'));
298 end;
299 ComboBox_ArchitectureEnter(self);
300 end;
302 procedure TForm1.ComboBox_PreFixChange(Sender: TObject);
304 ChannelLocal:string;
305 myloop:integer;
306 done:boolean;
307 temp:string;
308 PrefixInt:integer;
309 begin
310 ComboBox_ProgramsList.Items.Clear;
311 done := false;
312 myloop := 1;
314 EditBox_ProgramPath.Enabled := true;
315 ComboBox_ProgramsList.Enabled := true;
317 if Mode = false then
318 begin
319 while not done do
320 begin
321 if Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop] <> '' then
322 begin
323 ComboBox_ProgramsList.Items.Add(Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop]);
324 inc(myloop);
326 else
327 begin
328 done := true;
329 end;
330 end;
332 if ComboBox_ProgramsList.Items.Count <> 0 then
333 begin
334 ComboBox_ProgramsList.ItemIndex := 0;
335 EditBox_ProgramPath.Enabled := true;
336 ComboBox_ProgramsList.Enabled := true;
337 ComboBox_ProgramsListChange(Self);
339 else
340 begin
341 ComboBox_ProgramsList.Text := '';
342 EditBox_ProgramPath.Text := '';
343 EditBox_ProgramPath.Enabled := false;
344 ComboBox_ProgramsList.Enabled := false;
345 end;
348 else
349 begin
350 ListProgramsOnDisc(CdData, 'D');
351 if CdData.Text <> '' then
352 begin
353 CdDataName.Clear;
354 CdDataName.AddStrings(CdData);
356 for myloop := 0 to CdDataName.Count -1 do
357 begin
358 {Take path and return the file name only.}
359 CdDataName.Strings[myloop] := GetWinFileName(CdDataName.Strings[myloop]);
360 end;
361 ComboBox_ProgramsList.Items := CdDataName;
362 if ComboBox_ProgramsList.Items.Count <> 0 then
363 begin
364 ComboBox_ProgramsList.Text := ComboBox_ProgramsList.Items[0];
365 EditBox_ProgramPath.Enabled := true;
366 ComboBox_ProgramsList.Enabled := true;
367 ComboBox_ProgramsListChange(self);
368 end;
371 else
372 begin
373 ComboBox_ProgramsList.Items.Add(DiscErrorText);
374 ComboBox_ProgramsList.ItemIndex := 0;
375 EditBox_ProgramPath.Text := '';
376 EditBox_ProgramPath.Enabled := false;
377 ComboBox_ProgramsList.Enabled := false;
378 CheckListBox_Flags.Clear;
379 end;
381 end;
382 end;
384 procedure TForm1.ComboBox_ProgramsListChange(Sender: TObject);
386 ProgramsListSelectedItem:integer;
387 PrefixInt:integer;
388 begin
389 if Mode = false then
390 begin
391 PrefixInt := FindPrefixInt(ComboBox_PreFix.Items.Strings[ComboBox_PreFix.ItemIndex]);
392 EditBox_ProgramPath.Enabled := true;
393 {Plus one to line it up with the grid}
394 ProgramsListSelectedItem := (Data[PrefixInt].Grid.cols[DataNameCol].IndexOf(Data[PrefixInt].Grid.cols[DataNameCol].Strings[ComboBox_ProgramsList.ItemIndex]) +1);
395 {Cells[{Col},{Row}]}
396 EditBox_ProgramPath.Text := Data[PrefixInt].Grid.Cells[DataPathCol, ProgramsListSelectedItem] ;
397 CutUpFlags(Data[PrefixInt].Grid.Cells[DataFlagsCol, ProgramsListSelectedItem]);
399 else
400 begin
401 if CdData.Text <> '' then
402 begin
403 EditBox_ProgramPath.Text := CdData.Strings[CdDataName.IndexOf(ComboBox_ProgramsList.Text)] ;
404 end;
405 end;
406 end;
408 procedure TForm1.ComboBox_WineVersionEditingDone(Sender: TObject);
409 begin
410 WineVersionEditingDone();
411 OnWineVersionChange();
412 end;
414 procedure TForm1.ComboBox_WineVersionEnter(Sender: TObject);
416 ItemTextName:string;
417 ItemTextVersion:string;
418 ItemTextArchitecture:string;
419 begin
420 //Log(0, '', 'Running WineVersion');
421 if ComboBox_DistributionName.ItemIndex <> -1 then
422 begin
423 ItemTextName := ComboBox_DistributionName.Items.Strings[ComboBox_DistributionName.ItemIndex];
424 if ComboBox_DistributionVersion.ItemIndex <> -1 then
425 begin
426 ItemTextVersion := ComboBox_DistributionVersion.Items.Strings[ComboBox_DistributionVersion.ItemIndex];
427 if ComboBox_Architecture.ItemIndex <> -1 then
428 begin
429 ItemTextArchitecture := ComboBox_Architecture.Items.Strings[ComboBox_Architecture.ItemIndex];
430 FolderScan(ComboBox_WineVersion, (PathToWine + ItemTextName + '/' + ItemTextVersion + '/' + ItemTextArchitecture + '/'));
431 end;
432 end;
434 end;
435 OnWineVersionChange();
436 end;
438 procedure TForm1.EditBox_ProgramPathChange(Sender: TObject);
439 begin
440 ColourCheck(EditBox_ProgramPath);
441 end;
443 procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
444 begin
445 SaveLastUsedConfig();
446 end;
449 procedure TForm1.Btn_AboutClick(Sender: TObject);
450 begin
451 UnitAbout.Form3.Show ;
452 end;
454 procedure TForm1.Btn_DebugChannelsConfigClick(Sender: TObject);
455 begin
456 UnitDebugConfig.Form2.Show ;
457 end;
462 initialization
463 {$I UnitMain.lrs}
465 end.