UnitInitialization: Set the folder with the wine prefixes in, by using WINELAUNCHER_W...
[WineLauncher.git] / UnitMain.pas
blobe742ebde716ac0fd05373336e338c11383d911ca
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, either version 3 of the License, or
6 (at your option) any later version.
8 WineLauncher is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with WineLauncher. If not, see <http://www.gnu.org/licenses/>.
17 {Made with Lazarus 0.9.28.2 fixes branch.}
18 {Free Pascal Compiler version 2.2.5.}
20 unit UnitMain;
22 {$mode objfpc}{$H+}
24 interface
26 uses
27 Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
28 DbCtrls, BaseUnix, Process, CheckLst, ExtCtrls, ComCtrls, UnitCreatePrefix, UnitAbout, Errors;
30 type
32 { TForm1 }
34 TForm1 = class(TForm)
35 Btn_Run: TButton;
36 Btn_Settings: TButton;
37 Btn_StopScan: TButton;
38 Button_Regedit: TButton;
39 Button_Winecfg: TButton;
40 CheckBox_UseSoundWrapper: TCheckBox;
41 CheckListBox_Flags: TCheckListBox;
42 Check_Terminal: TCheckBox;
43 ComboBox_WineVersion: TComboBox;
44 ComboBox_ProgramsList: TComboBox;
45 ComboBox_PreFix: TComboBox;
46 ComboBox_SoundWrapper: TComboBox;
47 ComboBox_TerminalName: TComboBox;
48 EditBox_ProgramPath: TEdit;
49 Label_WineVersion: TLabel;
50 Label_Flags: TLabel;
51 Label_ProgramPath: TLabel;
52 Label_ProgramsList: TLabel;
53 Label_WinePreFix: TLabel;
54 Memo_LogOutPut: TMemo;
55 PageControl1: TPageControl;
56 Tab_Log: TTabSheet;
57 TogBtn_Listdrive: TToggleBox;
59 procedure Btn_RunClick(Sender: TObject);
60 procedure Btn_SettingsClick(Sender: TObject);
61 procedure Btn_StopScanClick(Sender: TObject);
62 procedure Button_RegeditClick(Sender: TObject);
63 procedure Button_WinecfgClick(Sender: TObject);
64 procedure ComboBox_PreFixChange(Sender: TObject);
65 procedure ComboBox_ProgramsListChange(Sender: TObject);
66 procedure ComboBox_WineVersionEditingDone(Sender: TObject);
67 procedure ComboBox_WineVersionEnter(Sender: TObject);
68 procedure EditBox_ProgramPathChange(Sender: TObject);
69 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
70 procedure FormCreate(Sender: TObject);
71 procedure FormDestroy(Sender: TObject);
72 procedure TogBtn_ListdriveChange(Sender: TObject);
73 procedure TimerOnTimer(Sender: TObject);
75 private { private declarations }
77 public { public declarations }
79 end;
81 var
82 Form1: TForm1;
83 NoError:Boolean; { Tbh this should not be here but im not sure need to check. }
84 Sh_Path:string; { Path for the shell }
85 GetCurrentDir:string;
86 Channel:string; { Debug channel name }
87 UnixDirPath:string; { Needed for setting the working dir at 'Run'. }
88 Mode:boolean;
89 Timer:TTimer; {The timer is a workaround.}
90 {Frames}
91 FrameCreatePrefix:TFrameCreatePrefix;
92 FrameAbout:TFrameAbout;
94 implementation
95 uses
96 UnitInitialization,
97 UnitMainBackend,
98 UnitMisc,
99 UnitSettings,
100 UnitProgramsList;
102 procedure TForm1.FormCreate(Sender: TObject);
103 begin
104 {The timer is a workaround.}
105 Timer := TTimer.Create(nil) ;
106 Timer.OnTimer := @TimerOnTimer;
107 Timer.Enabled := false;
108 Timer.Interval := 100;
110 {Scan for wine.}
111 ComboBox_WineVersionEnter(Self);
113 {Select first item.}
114 if ComboBox_SoundWrapper.items.Count <> 0 then ComboBox_SoundWrapper.Text := ComboBox_SoundWrapper.Items[0];
115 if ComboBox_TerminalName.items.Count <> 0 then ComboBox_TerminalName.Text := ComboBox_TerminalName.Items[0];
116 if ComboBox_WineVersion.Items.Count <> 0 then ComboBox_WineVersion.Text := ComboBox_WineVersion.Items[0];
118 {Frame Create prefix.}
119 AddTabToPageControl(PageControl1, 'Create prefix');
120 FrameCreatePrefix := TFrameCreatePrefix.Create(Self);
121 EmbedFrame(FrameCreatePrefix, PageControl1.PageCount -1);
122 {Frame about.}
123 AddTabToPageControl(PageControl1, 'About');
124 FrameAbout := TFrameAbout.Create(Self);
125 EmbedFrame(FrameAbout, PageControl1.PageCount -1);
127 FrameAbout.Memo_About.Lines.Add('');
128 {When the is a new release update the version number in the file called 'VERSION.inc'.}
129 FrameAbout.Memo_About.Lines.Add('WineLauncher Version: ' + WineLauncherVersion);
130 FrameAbout.Memo_About.Lines.Add(BuiltWithLazarusVersion);
131 FrameAbout.Memo_About.Lines.Add(BuiltWithFpcVersion);
133 {Load LastUsedConfig.}
134 LoadLastUsedConfig();
136 {$IFDEF GuiTest}
137 Btn_StopScan.Visible := true;
138 {$ENDIF}
139 end;
141 procedure TForm1.FormDestroy(Sender: TObject);
142 begin
143 Timer.Destroy;
144 XmlLastUsedConfig.Destroy;
145 SetLength(TabSheets, 0);
146 SetLength(Data, 0);
147 FreeAndNil(CdData);
148 FreeAndNil(CdDataName);
150 {stuff configed in UnitInitialization.}
151 AProcess.Destroy;
152 CreatePrefixProcess.Destroy;
153 AsyncProcessScan.Destroy;
154 end;
156 procedure TForm1.TimerOnTimer(Sender: TObject);
158 TempList:Tstrings;
159 begin
160 {We should not use a timer to check this. The is a bug in lazarus, 'OnTerminate' of AsyncProcess never runs.}
161 if AsyncProcessScan.Active = true then
162 begin
163 Timer.Enabled := true;
164 Btn_StopScan.Visible := true;
166 else
167 begin
168 Btn_StopScan.Visible := false;
169 TempList := TStringlist.Create;
170 Timer.Enabled := false;
171 TempList.LoadFromStream(AsyncProcessScan.OutPut);
173 if TempList.Count = 0 then
174 begin
175 DiscErrorText := 'Drive' + wrap('D' + ':') + 'has no executable files.';
176 LastReadLinkPath := '';
178 else
179 begin
180 DiscErrorText := '';
181 end;
183 while TempList.Count <> 0 do
184 begin
185 CdData.Add(UnixToWinPath(TempList.Strings[0],'d'));
186 TempList.Delete(0);
187 end;
189 ComboBox_PreFixChange(self);
190 TempList.Destroy;
192 CheckListBox_Flags.Clear;
193 end;
194 end;
196 procedure TForm1.TogBtn_ListdriveChange(Sender: TObject);
197 begin
198 if Mode = true then
199 begin
200 Mode := false;
201 AsyncProcessScan.Active := false;
202 Btn_StopScan.Visible := false;
203 CheckListBox_Flags.Enabled := true;
204 EditBox_ProgramPath.Clear;
206 FreeAndNil(CdData);
207 FreeAndNil(CdDataName);
209 ComboBox_PreFixChange(self);
210 ComboBox_ProgramsListChange(self);
212 else
213 begin
214 Mode := true;
215 CdData := TStringlist.Create;
216 CdDataName := TStringlist.Create;
218 log(0,'', LastReadLinkPath);
219 ComboBox_PreFixChange(self);
220 CheckListBox_Flags.Clear;
221 EditBox_ProgramPath.Clear;
222 end;
223 end;
228 procedure TForm1.Btn_RunClick(Sender: TObject);
229 begin
230 RunWineCheck( '', '' );
231 end;
233 procedure TForm1.Btn_SettingsClick(Sender: TObject);
234 begin
235 UnitSettings.Form4.Show ;
236 end;
238 procedure TForm1.Btn_StopScanClick(Sender: TObject);
239 begin
240 AsyncProcessScan.Active := false;
241 end;
243 procedure TForm1.Button_RegeditClick(Sender: TObject);
244 begin
245 RunWineCheck( 'Regedit', '' );
246 end;
248 procedure TForm1.Button_WinecfgClick(Sender: TObject);
249 begin
250 RunWineCheck( 'winecfg', '' );
251 end;
254 procedure TForm1.ComboBox_PreFixChange(Sender: TObject);
256 myloop:integer;
257 begin
258 ComboBox_ProgramsList.Items.Clear;
260 EditBox_ProgramPath.Enabled := true;
261 ComboBox_ProgramsList.Enabled := true;
263 if Mode = false then
264 begin
265 for myloop := 1 to (Data[ComboBox_PreFix.ItemIndex].Grid.RowCount -1) do
266 begin
267 if Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop] <> '' then
268 begin
269 ComboBox_ProgramsList.Items.Add(Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop]);
271 else
272 begin
273 break;
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 {Write some code to clean up the names, keep then usefull and unique.}
303 ComboBox_ProgramsList.Items := CdDataName;
304 if ComboBox_ProgramsList.Items.Count <> 0 then
305 begin
306 ComboBox_ProgramsList.Text := ComboBox_ProgramsList.Items[0];
307 EditBox_ProgramPath.Enabled := true;
308 ComboBox_ProgramsList.Enabled := true;
309 ComboBox_ProgramsListChange(self);
310 end;
313 else
314 begin
315 ComboBox_ProgramsList.Items.Add(DiscErrorText);
316 ComboBox_ProgramsList.ItemIndex := 0;
317 EditBox_ProgramPath.Text := '';
318 EditBox_ProgramPath.Enabled := false;
319 ComboBox_ProgramsList.Enabled := false;
320 CheckListBox_Flags.Clear;
321 end;
323 end;
324 end;
326 procedure TForm1.ComboBox_ProgramsListChange(Sender: TObject);
328 ProgramsListSelectedItem:integer;
329 PrefixInt:integer;
330 begin
331 if Mode = false then
332 begin
333 PrefixInt := FindPrefixInt(ComboBox_PreFix.Items.Strings[ComboBox_PreFix.ItemIndex]);
334 EditBox_ProgramPath.Enabled := true;
335 {Plus one to line it up with the grid}
336 ProgramsListSelectedItem := (Data[PrefixInt].Grid.cols[DataNameCol].IndexOf(Data[PrefixInt].Grid.cols[DataNameCol].Strings[ComboBox_ProgramsList.ItemIndex]) +1);
337 {Cells[Col, Row]}
338 EditBox_ProgramPath.Text := Data[PrefixInt].Grid.Cells[DataPathCol, ProgramsListSelectedItem] ;
339 CutUpFlags(Data[PrefixInt].Grid.Cells[DataFlagsCol, ProgramsListSelectedItem]);
341 else
342 begin
343 if CdData.Text <> '' then
344 begin
345 EditBox_ProgramPath.Text := CdData.Strings[CdDataName.IndexOf(ComboBox_ProgramsList.Text)] ;
346 end;
347 end;
348 end;
350 procedure TForm1.ComboBox_WineVersionEditingDone(Sender: TObject);
351 begin
352 OnWineVersionChange();
353 end;
355 procedure TForm1.ComboBox_WineVersionEnter(Sender: TObject);
357 a:string;
358 SystemSidePath:string;
359 begin
360 {Note FpSymLink does not have a string version with fpc 2.2.5.}
361 {This is not best way adding the system side wine but it works.}
362 SystemSidePath := PathToWine + '/System Side Wine';
363 {link wine.}
364 a := SearchForBin('wine');
365 if SearchForBin(a) <> '' then
366 begin
367 if DirExistsIfNotMakeIt(SystemSidePath) = true then
368 begin
369 if DirExistsIfNotMakeIt(SystemSidePath + '/bin') = true then
370 begin
371 SystemSidePath := (SystemSidePath + '/bin');
372 FpUnlink(SystemSidePath + '/wine');
373 if FpSymLink(PChar(a), PChar(SystemSidePath + '/wine') ) <> 0 then
374 begin
375 log(1,'','Can not create symlink: ' + StrError(fpgeterrno));
376 end;
377 {link wineprefixcreate.}
378 a := SearchForBin('wineprefixcreate');
379 if SearchForBin(a) <> '' then
380 begin
381 FpUnlink(SystemSidePath + '/wineprefixcreate');
382 if FpSymLink(PChar(a), PChar(SystemSidePath + '/wineprefixcreate') ) <> 0 then
383 begin
384 log(1,'','Can not create symlink: ' + StrError(fpgeterrno));
385 end;
386 end;
387 end;
388 end;
389 end;
391 FolderScan(ComboBox_WineVersion, PathToWine);
392 OnWineVersionChange();
393 end;
395 procedure TForm1.EditBox_ProgramPathChange(Sender: TObject);
396 begin
397 ColourCheck(EditBox_ProgramPath);
398 end;
400 procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
401 begin
402 SaveLastUsedConfig();
403 end;
405 initialization
406 {$I UnitMain.lrs}
408 end.