UnitMainBackend: New function EmbedFrame.
[WineLauncher.git] / UnitMain.pas
blob4f6e162e4cea779a91a8dab13d3564e48b1de64a
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, UnitCreatePrefix, UnitAbout;
29 type
31 { TForm1 }
33 TForm1 = class(TForm)
34 Btn_Run: TButton;
35 Btn_DebugChannelsConfig: TButton;
36 Btn_Settings: TButton;
37 Btn_StopScan: TButton;
38 Button_Regedit: TButton;
39 Button_Winecfg: TButton;
40 CheckBox_UseSoundWrapper: TCheckBox;
41 CheckBox_DebugChannelUse: TCheckBox;
42 CheckListBox_Flags: TCheckListBox;
43 Check_Terminal: TCheckBox;
44 ComboBox_WineVersion: TComboBox;
45 ComboBox_ProgramsList: TComboBox;
46 ComboBox_PreFix: TComboBox;
47 ComboBox_SoundWrapper: TComboBox;
48 ComboBox_TerminalName: TComboBox;
49 EditBox_ProgramPath: TEdit;
50 Label_WineVersion: TLabel;
51 Label_Flags: TLabel;
52 Label_ProgramPath: TLabel;
53 Label_ProgramsList: TLabel;
54 Label_WinePreFix: TLabel;
55 Memo_LogOutPut: TMemo;
56 PageControl1: TPageControl;
57 Tab_Log: TTabSheet;
58 TogBtn_Listdrive: TToggleBox;
60 procedure Btn_DebugChannelsConfigClick(Sender: TObject);
61 procedure Btn_RunClick(Sender: TObject);
62 procedure Btn_SettingsClick(Sender: TObject);
63 procedure Btn_StopScanClick(Sender: TObject);
64 procedure Button_RegeditClick(Sender: TObject);
65 procedure Button_WinecfgClick(Sender: TObject);
66 procedure ComboBox_PreFixChange(Sender: TObject);
67 procedure ComboBox_ProgramsListChange(Sender: TObject);
68 procedure ComboBox_WineVersionEditingDone(Sender: TObject);
69 procedure ComboBox_WineVersionEnter(Sender: TObject);
70 procedure EditBox_ProgramPathChange(Sender: TObject);
71 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
72 procedure FormCreate(Sender: TObject);
73 procedure FormResize(Sender: TObject);
74 procedure TogBtn_ListdriveChange(Sender: TObject);
75 procedure TimerOnTimer(Sender: TObject);
77 private { private declarations }
79 public { public declarations }
81 end;
83 var
84 Form1: TForm1;
85 start_S1:string; { Script to write to the file. }
86 wine_version_full:string; { New code uses this to. }
87 RunIn:string; { terminal or shell set here }
88 NoError:Boolean; { Tbh this should not be here but im not sure need to check. }
89 Sh_Path:string; { Path for the shell }
90 GetCurrentDir:string;
91 Channel:string; { Debug channel name }
92 UnixDirPath:string; { Needed for setting the working dir at 'Run'. }
93 Mode:boolean;
94 Timer:TTimer; {The timer is a workaround.}
95 TabSheet1:TTabSheet;
96 TabSheet2:TTabSheet;
97 FrameCreatePrefix:TFrameCreatePrefix; {This is FrameCreatePrefix.}
98 FrameAbout:TFrameAbout;
100 implementation
101 uses
102 UnitInitialization,
103 UnitMainBackend,
104 UnitMisc,
105 UnitDebugConfig,
106 UnitSettings,
107 UnitProgramsList;
109 procedure TForm1.FormCreate(Sender: TObject);
110 begin
111 {The timer is a workaround.}
112 Timer := TTimer.Create(nil) ;
113 Timer.OnTimer := @TimerOnTimer;
114 Timer.Enabled := false;
115 Timer.Interval := 100;
117 {Scan for wine.}
118 ComboBox_WineVersionEnter(Self);
120 {Select first item.}
121 if ComboBox_SoundWrapper.items.Count <> 0 then ComboBox_SoundWrapper.Text := ComboBox_SoundWrapper.Items[0];
122 if ComboBox_TerminalName.items.Count <> 0 then ComboBox_TerminalName.Text := ComboBox_TerminalName.Items[0];
123 if ComboBox_WineVersion.Items.Count <> 0 then ComboBox_WineVersion.Text := ComboBox_WineVersion.Items[0];
125 {Frame Create prefix.}
126 AddTabToPageControl(PageControl1, 'Create prefix');
127 FrameCreatePrefix := TFrameCreatePrefix.Create(Self);
128 EmbedFrame(FrameCreatePrefix, PageControl1.PageCount -1);
129 {Frame about.}
130 AddTabToPageControl(PageControl1, 'About');
131 FrameAbout := TFrameAbout.Create(Self);
132 EmbedFrame(FrameAbout, PageControl1.PageCount -1);
134 FrameAbout.Memo_About.Lines.Add('');
135 {When the is a new release update the version number in the file called 'VERSION.inc'.}
136 FrameAbout.Memo_About.Lines.Add('WineLauncher Version: ' + WineLauncherVersion);
137 FrameAbout.Memo_About.Lines.Add(BuiltWithFpcVersion);
139 {Load LastUsedConfig.}
140 LoadLastUsedConfig();
142 {$IFDEF GuiTest}
143 Btn_StopScan.Visible := true;
144 {$ENDIF}
145 end;
147 procedure TForm1.FormResize(Sender: TObject);
148 begin
149 if Btn_StopScan.Visible = true then Btn_StopScan.Left := (floor(form1.Width / 2) - floor(Btn_StopScan.Width / 2));
150 end;
152 procedure TForm1.TimerOnTimer(Sender: TObject);
154 TempList:Tstrings;
155 begin
156 {We should not use a timer to check this. The is a bug in lazarus, 'OnTerminate' of AsyncProcess never runs.}
157 if AsyncProcessScan.Active = true then
158 begin
159 Timer.Enabled := true;
160 Btn_StopScan.Visible := true;
161 FormResize(self);
163 else
164 begin
165 Btn_StopScan.Visible := false;
166 TempList := TStringlist.Create;
167 Timer.Enabled := false;
168 TempList.LoadFromStream(AsyncProcessScan.OutPut);
170 if TempList.Count = 0 then
171 begin
172 DiscErrorText := 'Drive' + wrap('D' + ':') + 'has no executable files.';
173 LastReadLinkPath := '';
175 else
176 begin
177 DiscErrorText := '';
178 end;
180 while TempList.Count <> 0 do
181 begin
182 CdData.Add(UnixToWinPath(TempList.Strings[0],'d'));
183 TempList.Delete(0);
184 end;
186 ComboBox_PreFixChange(self);
187 TempList.Destroy;
189 CheckListBox_Flags.Clear;
190 end;
191 end;
193 procedure TForm1.TogBtn_ListdriveChange(Sender: TObject);
194 begin
195 if Mode = true then
196 begin
197 Mode := false;
198 AsyncProcessScan.Active := false;
199 Btn_StopScan.Visible := false;
200 CheckListBox_Flags.Enabled := true;
201 EditBox_ProgramPath.Clear;
202 ComboBox_PreFixChange(self);
203 ComboBox_ProgramsListChange(self);
205 else
206 begin
207 Mode := true;
208 if CdData = nil then CdData := TStringlist.Create;
209 if CdDataName = nil then CdDataName := TStringlist.Create;
211 log(0,'', LastReadLinkPath);
212 ComboBox_PreFixChange(self);
213 CheckListBox_Flags.Clear;
214 EditBox_ProgramPath.Clear;
215 end;
216 end;
221 procedure TForm1.Btn_RunClick(Sender: TObject);
222 begin
223 RunWineCheck( '', '' );
224 end;
226 procedure TForm1.Btn_SettingsClick(Sender: TObject);
227 begin
228 UnitSettings.Form4.Show ;
229 end;
231 procedure TForm1.Btn_StopScanClick(Sender: TObject);
232 begin
233 AsyncProcessScan.Active := false;
234 end;
236 procedure TForm1.Button_RegeditClick(Sender: TObject);
237 begin
238 RunWineCheck( 'Regedit', '' );
239 end;
241 procedure TForm1.Button_WinecfgClick(Sender: TObject);
242 begin
243 RunWineCheck( 'winecfg', '' );
244 end;
247 procedure TForm1.ComboBox_PreFixChange(Sender: TObject);
249 ChannelLocal:string;
250 myloop:integer;
251 done:boolean;
252 temp:string;
253 PrefixInt:integer;
254 begin
255 ComboBox_ProgramsList.Items.Clear;
256 done := false;
257 myloop := 1;
259 EditBox_ProgramPath.Enabled := true;
260 ComboBox_ProgramsList.Enabled := true;
262 if Mode = false then
263 begin
264 while not done do
265 begin
266 if Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop] <> '' then
267 begin
268 ComboBox_ProgramsList.Items.Add(Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop]);
269 inc(myloop);
271 else
272 begin
273 done := true;
274 end;
275 end;
277 if ComboBox_ProgramsList.Items.Count <> 0 then
278 begin
279 ComboBox_ProgramsList.ItemIndex := 0;
280 EditBox_ProgramPath.Enabled := true;
281 ComboBox_ProgramsList.Enabled := true;
282 ComboBox_ProgramsListChange(Self);
284 else
285 begin
286 ComboBox_ProgramsList.Text := '';
287 EditBox_ProgramPath.Text := '';
288 EditBox_ProgramPath.Enabled := false;
289 ComboBox_ProgramsList.Enabled := false;
290 end;
293 else
294 begin
295 ListProgramsOnDisc(CdData, 'D');
296 if CdData.Text <> '' then
297 begin
298 CdDataName.Clear;
299 CdDataName.AddStrings(CdData);
301 for myloop := 0 to CdDataName.Count -1 do
302 begin
303 {Take path and return the file name only.}
304 CdDataName.Strings[myloop] := GetWinFileName(CdDataName.Strings[myloop]);
305 end;
306 ComboBox_ProgramsList.Items := CdDataName;
307 if ComboBox_ProgramsList.Items.Count <> 0 then
308 begin
309 ComboBox_ProgramsList.Text := ComboBox_ProgramsList.Items[0];
310 EditBox_ProgramPath.Enabled := true;
311 ComboBox_ProgramsList.Enabled := true;
312 ComboBox_ProgramsListChange(self);
313 end;
316 else
317 begin
318 ComboBox_ProgramsList.Items.Add(DiscErrorText);
319 ComboBox_ProgramsList.ItemIndex := 0;
320 EditBox_ProgramPath.Text := '';
321 EditBox_ProgramPath.Enabled := false;
322 ComboBox_ProgramsList.Enabled := false;
323 CheckListBox_Flags.Clear;
324 end;
326 end;
327 end;
329 procedure TForm1.ComboBox_ProgramsListChange(Sender: TObject);
331 ProgramsListSelectedItem:integer;
332 PrefixInt:integer;
333 begin
334 if Mode = false then
335 begin
336 PrefixInt := FindPrefixInt(ComboBox_PreFix.Items.Strings[ComboBox_PreFix.ItemIndex]);
337 EditBox_ProgramPath.Enabled := true;
338 {Plus one to line it up with the grid}
339 ProgramsListSelectedItem := (Data[PrefixInt].Grid.cols[DataNameCol].IndexOf(Data[PrefixInt].Grid.cols[DataNameCol].Strings[ComboBox_ProgramsList.ItemIndex]) +1);
340 {Cells[{Col},{Row}]}
341 EditBox_ProgramPath.Text := Data[PrefixInt].Grid.Cells[DataPathCol, ProgramsListSelectedItem] ;
342 CutUpFlags(Data[PrefixInt].Grid.Cells[DataFlagsCol, ProgramsListSelectedItem]);
344 else
345 begin
346 if CdData.Text <> '' then
347 begin
348 EditBox_ProgramPath.Text := CdData.Strings[CdDataName.IndexOf(ComboBox_ProgramsList.Text)] ;
349 end;
350 end;
351 end;
353 procedure TForm1.ComboBox_WineVersionEditingDone(Sender: TObject);
354 begin
355 OnWineVersionChange();
356 end;
358 procedure TForm1.ComboBox_WineVersionEnter(Sender: TObject);
359 begin
360 FolderScan(ComboBox_WineVersion, PathToWine);
361 OnWineVersionChange();
362 end;
364 procedure TForm1.EditBox_ProgramPathChange(Sender: TObject);
365 begin
366 ColourCheck(EditBox_ProgramPath);
367 end;
369 procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
370 begin
371 SaveLastUsedConfig();
372 end;
375 procedure TForm1.Btn_DebugChannelsConfigClick(Sender: TObject);
376 begin
377 UnitDebugConfig.Form2.Show ;
378 end;
383 initialization
384 {$I UnitMain.lrs}
386 end.