UnitCreatePrefix: Limit the new prefix name to 40 characters.
[WineLauncher.git] / UnitMain.pas
blob33be37c50cc3888b51d1013d8460a6d248154464
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 TabSheet1:TTabSheet;
95 TabSheet2:TTabSheet;
96 FrameCreatePrefix:TFrameCreatePrefix; {This is FrameCreatePrefix.}
97 FrameAbout:TFrameAbout;
99 implementation
100 uses
101 UnitInitialization,
102 UnitMainBackend,
103 UnitMisc,
104 UnitDebugConfig,
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 {Frame Create prefix.}
125 AddTabToPageControl(PageControl1, 'Create prefix');
126 FrameCreatePrefix := TFrameCreatePrefix.Create(Self);
127 EmbedFrame(FrameCreatePrefix, PageControl1.PageCount -1);
128 {Frame about.}
129 AddTabToPageControl(PageControl1, 'About');
130 FrameAbout := TFrameAbout.Create(Self);
131 EmbedFrame(FrameAbout, PageControl1.PageCount -1);
133 FrameAbout.Memo_About.Lines.Add('');
134 {When the is a new release update the version number in the file called 'VERSION.inc'.}
135 FrameAbout.Memo_About.Lines.Add('WineLauncher Version: ' + WineLauncherVersion);
136 FrameAbout.Memo_About.Lines.Add(BuiltWithFpcVersion);
138 {Load LastUsedConfig.}
139 LoadLastUsedConfig();
141 {$IFDEF GuiTest}
142 Btn_StopScan.Visible := true;
143 {$ENDIF}
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;
156 else
157 begin
158 Btn_StopScan.Visible := false;
159 TempList := TStringlist.Create;
160 Timer.Enabled := false;
161 TempList.LoadFromStream(AsyncProcessScan.OutPut);
163 if TempList.Count = 0 then
164 begin
165 DiscErrorText := 'Drive' + wrap('D' + ':') + 'has no executable files.';
166 LastReadLinkPath := '';
168 else
169 begin
170 DiscErrorText := '';
171 end;
173 while TempList.Count <> 0 do
174 begin
175 CdData.Add(UnixToWinPath(TempList.Strings[0],'d'));
176 TempList.Delete(0);
177 end;
179 ComboBox_PreFixChange(self);
180 TempList.Destroy;
182 CheckListBox_Flags.Clear;
183 end;
184 end;
186 procedure TForm1.TogBtn_ListdriveChange(Sender: TObject);
187 begin
188 if Mode = true then
189 begin
190 Mode := false;
191 AsyncProcessScan.Active := false;
192 Btn_StopScan.Visible := false;
193 CheckListBox_Flags.Enabled := true;
194 EditBox_ProgramPath.Clear;
195 ComboBox_PreFixChange(self);
196 ComboBox_ProgramsListChange(self);
198 else
199 begin
200 Mode := true;
201 if CdData = nil then CdData := TStringlist.Create;
202 if CdDataName = nil then CdDataName := TStringlist.Create;
204 log(0,'', LastReadLinkPath);
205 ComboBox_PreFixChange(self);
206 CheckListBox_Flags.Clear;
207 EditBox_ProgramPath.Clear;
208 end;
209 end;
214 procedure TForm1.Btn_RunClick(Sender: TObject);
215 begin
216 RunWineCheck( '', '' );
217 end;
219 procedure TForm1.Btn_SettingsClick(Sender: TObject);
220 begin
221 UnitSettings.Form4.Show ;
222 end;
224 procedure TForm1.Btn_StopScanClick(Sender: TObject);
225 begin
226 AsyncProcessScan.Active := false;
227 end;
229 procedure TForm1.Button_RegeditClick(Sender: TObject);
230 begin
231 RunWineCheck( 'Regedit', '' );
232 end;
234 procedure TForm1.Button_WinecfgClick(Sender: TObject);
235 begin
236 RunWineCheck( 'winecfg', '' );
237 end;
240 procedure TForm1.ComboBox_PreFixChange(Sender: TObject);
242 ChannelLocal:string;
243 myloop:integer;
244 temp:string;
245 PrefixInt:integer;
246 begin
247 ComboBox_ProgramsList.Items.Clear;
249 EditBox_ProgramPath.Enabled := true;
250 ComboBox_ProgramsList.Enabled := true;
252 if Mode = false then
253 begin
254 for myloop := 1 to (Data[ComboBox_PreFix.ItemIndex].Grid.RowCount -1) do
255 begin
256 if Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop] <> '' then
257 begin
258 ComboBox_ProgramsList.Items.Add(Data[ComboBox_PreFix.ItemIndex].Grid.Cells[DataNameCol, myloop]);
260 else
261 begin
262 break;
263 end;
264 end;
266 if ComboBox_ProgramsList.Items.Count <> 0 then
267 begin
268 ComboBox_ProgramsList.ItemIndex := 0;
269 EditBox_ProgramPath.Enabled := true;
270 ComboBox_ProgramsList.Enabled := true;
271 ComboBox_ProgramsListChange(Self);
273 else
274 begin
275 ComboBox_ProgramsList.Text := '';
276 EditBox_ProgramPath.Text := '';
277 EditBox_ProgramPath.Enabled := false;
278 ComboBox_ProgramsList.Enabled := false;
279 end;
282 else
283 begin
284 ListProgramsOnDisc(CdData, 'D');
285 if CdData.Text <> '' then
286 begin
287 CdDataName.Clear;
288 CdDataName.AddStrings(CdData);
289 {This is buggy each program name needs to be unique.}
290 //for myloop := 0 to CdDataName.Count -1 do
291 //begin
292 {Take path and return the file name only.}
293 //CdDataName.Strings[myloop] := GetWinFileName(CdDataName.Strings[myloop]);
294 //end;
295 ComboBox_ProgramsList.Items := CdDataName;
296 if ComboBox_ProgramsList.Items.Count <> 0 then
297 begin
298 ComboBox_ProgramsList.Text := ComboBox_ProgramsList.Items[0];
299 EditBox_ProgramPath.Enabled := true;
300 ComboBox_ProgramsList.Enabled := true;
301 ComboBox_ProgramsListChange(self);
302 end;
305 else
306 begin
307 ComboBox_ProgramsList.Items.Add(DiscErrorText);
308 ComboBox_ProgramsList.ItemIndex := 0;
309 EditBox_ProgramPath.Text := '';
310 EditBox_ProgramPath.Enabled := false;
311 ComboBox_ProgramsList.Enabled := false;
312 CheckListBox_Flags.Clear;
313 end;
315 end;
316 end;
318 procedure TForm1.ComboBox_ProgramsListChange(Sender: TObject);
320 ProgramsListSelectedItem:integer;
321 PrefixInt:integer;
322 begin
323 if Mode = false then
324 begin
325 PrefixInt := FindPrefixInt(ComboBox_PreFix.Items.Strings[ComboBox_PreFix.ItemIndex]);
326 EditBox_ProgramPath.Enabled := true;
327 {Plus one to line it up with the grid}
328 ProgramsListSelectedItem := (Data[PrefixInt].Grid.cols[DataNameCol].IndexOf(Data[PrefixInt].Grid.cols[DataNameCol].Strings[ComboBox_ProgramsList.ItemIndex]) +1);
329 {Cells[{Col},{Row}]}
330 EditBox_ProgramPath.Text := Data[PrefixInt].Grid.Cells[DataPathCol, ProgramsListSelectedItem] ;
331 CutUpFlags(Data[PrefixInt].Grid.Cells[DataFlagsCol, ProgramsListSelectedItem]);
333 else
334 begin
335 if CdData.Text <> '' then
336 begin
337 EditBox_ProgramPath.Text := CdData.Strings[CdDataName.IndexOf(ComboBox_ProgramsList.Text)] ;
338 end;
339 end;
340 end;
342 procedure TForm1.ComboBox_WineVersionEditingDone(Sender: TObject);
343 begin
344 OnWineVersionChange();
345 end;
347 procedure TForm1.ComboBox_WineVersionEnter(Sender: TObject);
348 begin
349 FolderScan(ComboBox_WineVersion, PathToWine);
350 OnWineVersionChange();
351 end;
353 procedure TForm1.EditBox_ProgramPathChange(Sender: TObject);
354 begin
355 ColourCheck(EditBox_ProgramPath);
356 end;
358 procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
359 begin
360 SaveLastUsedConfig();
361 end;
364 procedure TForm1.Btn_DebugChannelsConfigClick(Sender: TObject);
365 begin
366 UnitDebugConfig.Form2.Show ;
367 end;
372 initialization
373 {$I UnitMain.lrs}
375 end.