UnitMain: Add a TabSheet to hold all the frames.
[WineLauncher.git] / UnitMain.pas
blobb74b206671741f10053102b088dddcde5053c3b6
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, ComCtrls;
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_WineVersion: TComboBox;
46 ComboBox_ProgramsList: TComboBox;
47 ComboBox_PreFix: TComboBox;
48 ComboBox_SoundWrapper: TComboBox;
49 ComboBox_TerminalName: TComboBox;
50 EditBox_ProgramPath: TEdit;
51 Label_WineVersion: TLabel;
52 Label_Flags: TLabel;
53 Label_ProgramPath: TLabel;
54 Label_ProgramsList: TLabel;
55 Label_WinePreFix: TLabel;
56 Memo_LogOutPut: TMemo;
57 PageControl1: TPageControl;
58 Tab_Log: TTabSheet;
59 TogBtn_Listdrive: TToggleBox;
61 procedure Btn_AboutClick(Sender: TObject);
62 procedure Btn_DebugChannelsConfigClick(Sender: TObject);
63 procedure Btn_RunClick(Sender: TObject);
64 procedure Btn_SettingsClick(Sender: TObject);
65 procedure Btn_StopScanClick(Sender: TObject);
66 procedure Button_RegeditClick(Sender: TObject);
67 procedure Button_WinecfgClick(Sender: TObject);
68 procedure ComboBox_PreFixChange(Sender: TObject);
69 procedure ComboBox_ProgramsListChange(Sender: TObject);
70 procedure ComboBox_WineVersionEditingDone(Sender: TObject);
71 procedure ComboBox_WineVersionEnter(Sender: TObject);
72 procedure EditBox_ProgramPathChange(Sender: TObject);
73 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
74 procedure FormCreate(Sender: TObject);
75 procedure FormResize(Sender: TObject);
76 procedure TogBtn_ListdriveChange(Sender: TObject);
77 procedure TimerOnTimer(Sender: TObject);
79 private { private declarations }
81 public { public declarations }
83 end;
85 var
86 Form1: TForm1;
87 start_S1:string; { Script to write to the file. }
88 wine_version_full:string; { New code uses this to. }
89 RunIn:string; { terminal or shell set here }
90 NoError:Boolean; { Tbh this should not be here but im not sure need to check. }
91 Sh_Path:string; { Path for the shell }
92 GetCurrentDir:string;
93 Channel:string; { Debug channel name }
94 UnixDirPath:string; { Needed for setting the working dir at 'Run'. }
95 Mode:boolean;
96 Timer:TTimer; {The timer is a workaround.}
98 implementation
99 uses
100 UnitInitialization,
101 UnitMainBackend,
102 UnitMisc,
103 UnitDebugConfig,
104 UnitAbout,
105 UnitSettings,
106 UnitProgramsList;
108 procedure TForm1.FormCreate(Sender: TObject);
109 begin
110 {The timer is a workaround.}
111 Timer := TTimer.Create(nil) ;
112 Timer.OnTimer := @TimerOnTimer;
113 Timer.Enabled := false;
114 Timer.Interval := 100;
116 {Scan for wine.}
117 ComboBox_WineVersionEnter(Self);
119 {Select first item.}
120 if ComboBox_SoundWrapper.items.Count <> 0 then ComboBox_SoundWrapper.Text := ComboBox_SoundWrapper.Items[0];
121 if ComboBox_TerminalName.items.Count <> 0 then ComboBox_TerminalName.Text := ComboBox_TerminalName.Items[0];
122 if ComboBox_WineVersion.Items.Count <> 0 then ComboBox_WineVersion.Text := ComboBox_WineVersion.Items[0];
124 {Load LastUsedConfig.}
125 LoadLastUsedConfig();
127 {$IFDEF GuiTest}
128 Btn_StopScan.Visible := true;
129 {$ENDIF}
130 end;
132 procedure TForm1.FormResize(Sender: TObject);
133 begin
134 if Btn_StopScan.Visible = true then Btn_StopScan.Left := (floor(form1.Width / 2) - floor(Btn_StopScan.Width / 2));
135 end;
137 procedure TForm1.TimerOnTimer(Sender: TObject);
139 TempList:Tstrings;
140 begin
141 {We should not use a timer to check this. The is a bug in lazarus, 'OnTerminate' of AsyncProcess never runs.}
142 if AsyncProcessScan.Active = true then
143 begin
144 Timer.Enabled := true;
145 Btn_StopScan.Visible := true;
146 FormResize(self);
148 else
149 begin
150 Btn_StopScan.Visible := false;
151 TempList := TStringlist.Create;
152 Timer.Enabled := false;
153 TempList.LoadFromStream(AsyncProcessScan.OutPut);
155 if TempList.Count = 0 then
156 begin
157 DiscErrorText := 'Drive' + wrap('D' + ':') + 'has no executable files.';
158 LastReadLinkPath := '';
160 else
161 begin
162 DiscErrorText := '';
163 end;
165 while TempList.Count <> 0 do
166 begin
167 CdData.Add(UnixToWinPath(TempList.Strings[0],'d'));
168 TempList.Delete(0);
169 end;
171 ComboBox_PreFixChange(self);
172 TempList.Destroy;
174 CheckListBox_Flags.Clear;
175 end;
176 end;
178 procedure TForm1.TogBtn_ListdriveChange(Sender: TObject);
179 begin
180 if Mode = true then
181 begin
182 Mode := false;
183 AsyncProcessScan.Active := false;
184 Btn_StopScan.Visible := false;
185 CheckListBox_Flags.Enabled := true;
186 EditBox_ProgramPath.Clear;
187 ComboBox_PreFixChange(self);
188 ComboBox_ProgramsListChange(self);
190 else
191 begin
192 Mode := true;
193 if CdData = nil then CdData := TStringlist.Create;
194 if CdDataName = nil then CdDataName := TStringlist.Create;
196 log(0,'', LastReadLinkPath);
197 ComboBox_PreFixChange(self);
198 CheckListBox_Flags.Clear;
199 EditBox_ProgramPath.Clear;
200 end;
201 end;
206 procedure TForm1.Btn_RunClick(Sender: TObject);
207 begin
208 RunWineCheck( '', '' );
209 end;
211 procedure TForm1.Btn_SettingsClick(Sender: TObject);
212 begin
213 UnitSettings.Form4.Show ;
214 end;
216 procedure TForm1.Btn_StopScanClick(Sender: TObject);
217 begin
218 AsyncProcessScan.Active := false;
219 end;
221 procedure TForm1.Button_RegeditClick(Sender: TObject);
222 begin
223 RunWineCheck( 'Regedit', '' );
224 end;
226 procedure TForm1.Button_WinecfgClick(Sender: TObject);
227 begin
228 RunWineCheck( 'winecfg', '' );
229 end;
232 procedure TForm1.ComboBox_PreFixChange(Sender: TObject);
234 ChannelLocal:string;
235 myloop:integer;
236 done:boolean;
237 temp:string;
238 PrefixInt:integer;
239 begin
240 ComboBox_ProgramsList.Items.Clear;
241 done := false;
242 myloop := 1;
244 EditBox_ProgramPath.Enabled := true;
245 ComboBox_ProgramsList.Enabled := true;
247 if Mode = false then
248 begin
249 while not done do
250 begin
251 if Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop] <> '' then
252 begin
253 ComboBox_ProgramsList.Items.Add(Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop]);
254 inc(myloop);
256 else
257 begin
258 done := true;
259 end;
260 end;
262 if ComboBox_ProgramsList.Items.Count <> 0 then
263 begin
264 ComboBox_ProgramsList.ItemIndex := 0;
265 EditBox_ProgramPath.Enabled := true;
266 ComboBox_ProgramsList.Enabled := true;
267 ComboBox_ProgramsListChange(Self);
269 else
270 begin
271 ComboBox_ProgramsList.Text := '';
272 EditBox_ProgramPath.Text := '';
273 EditBox_ProgramPath.Enabled := false;
274 ComboBox_ProgramsList.Enabled := false;
275 end;
278 else
279 begin
280 ListProgramsOnDisc(CdData, 'D');
281 if CdData.Text <> '' then
282 begin
283 CdDataName.Clear;
284 CdDataName.AddStrings(CdData);
286 for myloop := 0 to CdDataName.Count -1 do
287 begin
288 {Take path and return the file name only.}
289 CdDataName.Strings[myloop] := GetWinFileName(CdDataName.Strings[myloop]);
290 end;
291 ComboBox_ProgramsList.Items := CdDataName;
292 if ComboBox_ProgramsList.Items.Count <> 0 then
293 begin
294 ComboBox_ProgramsList.Text := ComboBox_ProgramsList.Items[0];
295 EditBox_ProgramPath.Enabled := true;
296 ComboBox_ProgramsList.Enabled := true;
297 ComboBox_ProgramsListChange(self);
298 end;
301 else
302 begin
303 ComboBox_ProgramsList.Items.Add(DiscErrorText);
304 ComboBox_ProgramsList.ItemIndex := 0;
305 EditBox_ProgramPath.Text := '';
306 EditBox_ProgramPath.Enabled := false;
307 ComboBox_ProgramsList.Enabled := false;
308 CheckListBox_Flags.Clear;
309 end;
311 end;
312 end;
314 procedure TForm1.ComboBox_ProgramsListChange(Sender: TObject);
316 ProgramsListSelectedItem:integer;
317 PrefixInt:integer;
318 begin
319 if Mode = false then
320 begin
321 PrefixInt := FindPrefixInt(ComboBox_PreFix.Items.Strings[ComboBox_PreFix.ItemIndex]);
322 EditBox_ProgramPath.Enabled := true;
323 {Plus one to line it up with the grid}
324 ProgramsListSelectedItem := (Data[PrefixInt].Grid.cols[DataNameCol].IndexOf(Data[PrefixInt].Grid.cols[DataNameCol].Strings[ComboBox_ProgramsList.ItemIndex]) +1);
325 {Cells[{Col},{Row}]}
326 EditBox_ProgramPath.Text := Data[PrefixInt].Grid.Cells[DataPathCol, ProgramsListSelectedItem] ;
327 CutUpFlags(Data[PrefixInt].Grid.Cells[DataFlagsCol, ProgramsListSelectedItem]);
329 else
330 begin
331 if CdData.Text <> '' then
332 begin
333 EditBox_ProgramPath.Text := CdData.Strings[CdDataName.IndexOf(ComboBox_ProgramsList.Text)] ;
334 end;
335 end;
336 end;
338 procedure TForm1.ComboBox_WineVersionEditingDone(Sender: TObject);
339 begin
340 OnWineVersionChange();
341 end;
343 procedure TForm1.ComboBox_WineVersionEnter(Sender: TObject);
344 begin
345 FolderScan(ComboBox_WineVersion, PathToWine);
346 OnWineVersionChange();
347 end;
349 procedure TForm1.EditBox_ProgramPathChange(Sender: TObject);
350 begin
351 ColourCheck(EditBox_ProgramPath);
352 end;
354 procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
355 begin
356 SaveLastUsedConfig();
357 end;
360 procedure TForm1.Btn_AboutClick(Sender: TObject);
361 begin
362 UnitAbout.Form3.Show ;
363 end;
365 procedure TForm1.Btn_DebugChannelsConfigClick(Sender: TObject);
366 begin
367 UnitDebugConfig.Form2.Show ;
368 end;
373 initialization
374 {$I UnitMain.lrs}
376 end.