UnitMain: Remove dead code.
[WineLauncher.git] / UnitMain.pas
blob04206469b1bbb25c3c75b01324fdfc28ad9fc9b0
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 TogBtn_ListdriveChange(Sender: TObject);
74 procedure TimerOnTimer(Sender: TObject);
76 private { private declarations }
78 public { public declarations }
80 end;
82 var
83 Form1: TForm1;
84 start_S1:string; { Script to write to the file. }
85 wine_version_full:string; { New code uses this to. }
86 RunIn:string; { terminal or shell set here }
87 NoError:Boolean; { Tbh this should not be here but im not sure need to check. }
88 Sh_Path:string; { Path for the shell }
89 GetCurrentDir:string;
90 Channel:string; { Debug channel name }
91 UnixDirPath:string; { Needed for setting the working dir at 'Run'. }
92 Mode:boolean;
93 Timer:TTimer; {The timer is a workaround.}
94 {Frames}
95 FrameCreatePrefix:TFrameCreatePrefix;
96 FrameAbout:TFrameAbout;
98 implementation
99 uses
100 UnitInitialization,
101 UnitMainBackend,
102 UnitMisc,
103 UnitDebugConfig,
104 UnitSettings,
105 UnitProgramsList;
107 procedure TForm1.FormCreate(Sender: TObject);
108 begin
109 {The timer is a workaround.}
110 Timer := TTimer.Create(nil) ;
111 Timer.OnTimer := @TimerOnTimer;
112 Timer.Enabled := false;
113 Timer.Interval := 100;
115 {Scan for wine.}
116 ComboBox_WineVersionEnter(Self);
118 {Select first item.}
119 if ComboBox_SoundWrapper.items.Count <> 0 then ComboBox_SoundWrapper.Text := ComboBox_SoundWrapper.Items[0];
120 if ComboBox_TerminalName.items.Count <> 0 then ComboBox_TerminalName.Text := ComboBox_TerminalName.Items[0];
121 if ComboBox_WineVersion.Items.Count <> 0 then ComboBox_WineVersion.Text := ComboBox_WineVersion.Items[0];
123 {Frame Create prefix.}
124 AddTabToPageControl(PageControl1, 'Create prefix');
125 FrameCreatePrefix := TFrameCreatePrefix.Create(Self);
126 EmbedFrame(FrameCreatePrefix, PageControl1.PageCount -1);
127 {Frame about.}
128 AddTabToPageControl(PageControl1, 'About');
129 FrameAbout := TFrameAbout.Create(Self);
130 EmbedFrame(FrameAbout, PageControl1.PageCount -1);
132 FrameAbout.Memo_About.Lines.Add('');
133 {When the is a new release update the version number in the file called 'VERSION.inc'.}
134 FrameAbout.Memo_About.Lines.Add('WineLauncher Version: ' + WineLauncherVersion);
135 FrameAbout.Memo_About.Lines.Add(BuiltWithFpcVersion);
137 {Load LastUsedConfig.}
138 LoadLastUsedConfig();
140 {$IFDEF GuiTest}
141 Btn_StopScan.Visible := true;
142 {$ENDIF}
143 end;
145 procedure TForm1.TimerOnTimer(Sender: TObject);
147 TempList:Tstrings;
148 begin
149 {We should not use a timer to check this. The is a bug in lazarus, 'OnTerminate' of AsyncProcess never runs.}
150 if AsyncProcessScan.Active = true then
151 begin
152 Timer.Enabled := true;
153 Btn_StopScan.Visible := true;
155 else
156 begin
157 Btn_StopScan.Visible := false;
158 TempList := TStringlist.Create;
159 Timer.Enabled := false;
160 TempList.LoadFromStream(AsyncProcessScan.OutPut);
162 if TempList.Count = 0 then
163 begin
164 DiscErrorText := 'Drive' + wrap('D' + ':') + 'has no executable files.';
165 LastReadLinkPath := '';
167 else
168 begin
169 DiscErrorText := '';
170 end;
172 while TempList.Count <> 0 do
173 begin
174 CdData.Add(UnixToWinPath(TempList.Strings[0],'d'));
175 TempList.Delete(0);
176 end;
178 ComboBox_PreFixChange(self);
179 TempList.Destroy;
181 CheckListBox_Flags.Clear;
182 end;
183 end;
185 procedure TForm1.TogBtn_ListdriveChange(Sender: TObject);
186 begin
187 if Mode = true then
188 begin
189 Mode := false;
190 AsyncProcessScan.Active := false;
191 Btn_StopScan.Visible := false;
192 CheckListBox_Flags.Enabled := true;
193 EditBox_ProgramPath.Clear;
194 ComboBox_PreFixChange(self);
195 ComboBox_ProgramsListChange(self);
197 else
198 begin
199 Mode := true;
200 if CdData = nil then CdData := TStringlist.Create;
201 if CdDataName = nil then CdDataName := TStringlist.Create;
203 log(0,'', LastReadLinkPath);
204 ComboBox_PreFixChange(self);
205 CheckListBox_Flags.Clear;
206 EditBox_ProgramPath.Clear;
207 end;
208 end;
213 procedure TForm1.Btn_RunClick(Sender: TObject);
214 begin
215 RunWineCheck( '', '' );
216 end;
218 procedure TForm1.Btn_SettingsClick(Sender: TObject);
219 begin
220 UnitSettings.Form4.Show ;
221 end;
223 procedure TForm1.Btn_StopScanClick(Sender: TObject);
224 begin
225 AsyncProcessScan.Active := false;
226 end;
228 procedure TForm1.Button_RegeditClick(Sender: TObject);
229 begin
230 RunWineCheck( 'Regedit', '' );
231 end;
233 procedure TForm1.Button_WinecfgClick(Sender: TObject);
234 begin
235 RunWineCheck( 'winecfg', '' );
236 end;
239 procedure TForm1.ComboBox_PreFixChange(Sender: TObject);
241 ChannelLocal:string;
242 myloop:integer;
243 temp:string;
244 PrefixInt:integer;
245 begin
246 ComboBox_ProgramsList.Items.Clear;
248 EditBox_ProgramPath.Enabled := true;
249 ComboBox_ProgramsList.Enabled := true;
251 if Mode = false then
252 begin
253 for myloop := 1 to (Data[ComboBox_PreFix.ItemIndex].Grid.RowCount -1) do
254 begin
255 if Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop] <> '' then
256 begin
257 ComboBox_ProgramsList.Items.Add(Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop]);
259 else
260 begin
261 break;
262 end;
263 end;
265 if ComboBox_ProgramsList.Items.Count <> 0 then
266 begin
267 ComboBox_ProgramsList.ItemIndex := 0;
268 EditBox_ProgramPath.Enabled := true;
269 ComboBox_ProgramsList.Enabled := true;
270 ComboBox_ProgramsListChange(Self);
272 else
273 begin
274 ComboBox_ProgramsList.Text := '';
275 EditBox_ProgramPath.Text := '';
276 EditBox_ProgramPath.Enabled := false;
277 ComboBox_ProgramsList.Enabled := false;
278 end;
281 else
282 begin
283 ListProgramsOnDisc(CdData, 'D');
284 if CdData.Text <> '' then
285 begin
286 CdDataName.Clear;
287 CdDataName.AddStrings(CdData);
289 {Write some code to clean up the names, keep then usefull and unique.}
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_DebugChannelsConfigClick(Sender: TObject);
361 begin
362 UnitDebugConfig.Form2.Show ;
363 end;
368 initialization
369 {$I UnitMain.lrs}
371 end.