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 fixes branch. }
26 Classes
, SysUtils
, LResources
, Forms
, Controls
, Graphics
, Dialogs
, StdCtrls
,
27 DbCtrls
, strutils
, BaseUnix
, Process
, CheckLst
, AsyncProcess
, ExtCtrls
, Math
;
35 Btn_DebugChannelsConfig
: 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_ProgramsList
: TComboBox
;
46 ComboBox_Architecture
: TComboBox
;
47 ComboBox_DistributionVersion
: TComboBox
;
48 ComboBox_DistributionName
: TComboBox
;
49 ComboBox_PreFix
: TComboBox
;
50 ComboBox_SoundWrapper
: TComboBox
;
51 ComboBox_TerminalName
: TComboBox
;
52 ComboBox_WineVersion
: TComboBox
;
53 EditBox_ProgramPath
: TEdit
;
54 Label_WineVersion
: TLabel
;
56 Label_ProgramPath
: TLabel
;
57 Label_ProgramsList
: TLabel
;
58 Label_WinePreFix
: TLabel
;
59 Label_DistributionName
: TLabel
;
60 Label_DistributionVersion
: TLabel
;
61 Label_Architecture
: TLabel
;
62 Memo_LogOutPut
: TMemo
;
63 TogBtn_Listdrive
: TToggleBox
;
65 procedure Btn_AboutClick(Sender
: TObject
);
66 procedure Btn_DebugChannelsConfigClick(Sender
: TObject
);
67 procedure Btn_RunClick(Sender
: TObject
);
68 procedure Btn_SettingsClick(Sender
: TObject
);
69 procedure Btn_StopScanClick(Sender
: TObject
);
70 procedure Button_RegeditClick(Sender
: TObject
);
71 procedure Button_WinecfgClick(Sender
: TObject
);
72 procedure CheckBox_UseSoundWrapperChange(Sender
: TObject
);
73 procedure Check_TerminalChange(Sender
: TObject
);
74 procedure ComboBox_ArchitectureChange(Sender
: TObject
);
75 procedure ComboBox_DistributionNameEditingDone(Sender
: TObject
);
76 procedure ComboBox_DistributionVersionEditingDone(Sender
: TObject
);
77 procedure ComboBox_PreFixChange(Sender
: TObject
);
78 procedure ComboBox_ProgramsListChange(Sender
: TObject
);
79 procedure ComboBox_WineVersionEditingDone(Sender
: TObject
);
80 procedure EditBox_ProgramPathChange(Sender
: TObject
);
81 procedure FormCreate(Sender
: TObject
);
82 procedure FormResize(Sender
: TObject
);
83 procedure TogBtn_ListdriveChange(Sender
: TObject
);
84 procedure TimerOnTimer(Sender
: TObject
);
86 private { private declarations }
87 procedure CheckWineVersion();
89 function Isblocked(Path
:string): longint ;
91 public { public declarations }
92 procedure ListFileDir({0} Path
: string; {1} FileList
: TStrings
; {2} GroupList
: TStrings
; {3} DirListClean
: TStrings
; {4} DirListPath
: TStrings
; {5} isFileList
: Boolean );
97 start_S1
:string; { Script to write to the file. }
98 wine_version_full
:string; { New code uses this to. }
99 RunIn
:string; { terminal or shell set here }
100 NoError
:Boolean; { Tbh this should not be here but im not sure need to check. }
102 Sh_Path
:string; { Path for the shell }
103 GetCurrentDir
:string;
105 Channel
:string; { Debug channel name }
106 HideChannel
:boolean; { Cut down on the spam }
107 IgnoreChannelList
:Tstrings
;
108 WinePath
:string; { New var for "~/[wine-stuff]/wine/[OS name]/[OS version]/[Architecture] }
109 WineUserFolder
:string; { E.G. "wine-stuff" }
110 UnixDirPath
:string; { Needed for setting the working dir at 'Run'. }
112 AsyncProcessScan
:TAsyncProcess
;
116 uses UnitMisc
, UnitDebugConfig
, UnitAbout
, UnitSettings
, UnitProgramsList
;
120 function TForm1
.Isblocked(Path
:string): longint ;
126 { Checks to see string is backup "~" or / and hided "." }
127 if AnsiStartsText( '.', Path
) = true then
129 log( 1, CL
, 'This can not be hided');
138 if AnsiEndsText( '~', Path
) = true then
140 log( 1, CL
, 'This can not be a backup file');
151 procedure TForm1
.ListFileDir({0} Path
: string; {1} FileList
: TStrings
; {2} GroupList
: TStrings
; {3} DirListClean
: TStrings
; {4} DirListPath
: TStrings
; {5} isFileList
: Boolean );
156 if FindFirst(Path
+ '*', faAnyFile
, SR
) = 0 then
159 if ((SR
.Attr
and faDirectory
= 0) = isFileList
) then
161 { removes folders called "." & ".." }
162 if SR
.Name
<> '.' then if SR
.Name
<> '..' then
164 if ( DirListPath
<> nil) then
165 DirListPath
.Add( (path
+ SR
.Name
+ '/') );
167 if ( FileList
<> nil) then
168 FileList
.Add(SR
.Name
);
171 until FindNext(SR
) <> 0;
181 procedure TForm1
.CheckWineVersion();
185 { TODO : Add better filtering. }
187 {Get Distribution name. }
188 WineCheck
:= ( GetEnvironmentVariable('HOME') + '/' + WineUserFolder
+ '/wine/' );
189 ComboBox_DistributionName
.Items
.Clear
;
190 ListFileDir( {0} WineCheck
, {1} ComboBox_DistributionName
.Items
, {2} nil , {3} nil , {4} nil , {5} false );
192 { Get Distribution version. }
193 if DoesFolderExists( WineCheck
, ComboBox_DistributionName
.Text ) = true then
195 ComboBox_DistributionVersion
.Items
.Clear
;
196 ListFileDir( {0} ( WineCheck
+ ComboBox_DistributionName
.Text + '/' ) , {1} ComboBox_DistributionVersion
.Items
, {2} nil , {3} nil , {4} nil , {5} false );
199 { Get Architecture. }
200 WineCheck
:= ( WineCheck
+ ComboBox_DistributionName
.Text );
201 if DoesFolderExists( WineCheck
, ( '/' + ComboBox_DistributionVersion
.Text )) = true then
203 ComboBox_Architecture
.Items
.Clear
;
204 ListFileDir( {0} ( WineCheck
+ '/' + ComboBox_DistributionVersion
.Text + '/' ) , {1} ComboBox_Architecture
.Items
, {2} nil , {3} nil , {4} nil , {5} false );
207 { Get Wine version. }
208 WineCheck
:= ( WineCheck
+ '/' + ComboBox_DistributionVersion
.Text + '/' + ComboBox_Architecture
.Text );
209 ComboBox_WineVersion
.Items
.Clear
;
210 ListFileDir( {0} WineCheck
+ '/' , {1} ComboBox_WineVersion
.Items
, {2} nil , {3} nil , {4} nil , {5} false );
212 WineCheck
:= ( WineCheck
+ '/' + ComboBox_WineVersion
.Text );
214 WinePath
:= WineCheck
;
217 SaveLastUsedConfig();
221 procedure TForm1
.FormCreate(Sender
: TObject
);
223 { TODO : Change all code to uses this var. }
224 WineUserFolder
:= 'wine-stuff';
225 Channel
:= (Form1
.Name
+'.FormCreate');
226 HideChannel
:= true; {Cut down on the logging spam.}
227 ConfigPath
:= (GetEnvironmentVariable('HOME') + '/.config/WineLauncher');
228 AProcess
:= TProcess
.Create(nil); {Used in RunWineCheck.}
230 {Check all the files and folders this program needs to access.}
231 if CheckPaths() <> true then halt();
234 if ComboBox_SoundWrapper
.items
.Count
<> 0 then ComboBox_SoundWrapper
.Text := ComboBox_SoundWrapper
.Items
[0];
235 if ComboBox_TerminalName
.items
.Count
<> 0 then ComboBox_TerminalName
.Text := ComboBox_TerminalName
.Items
[0];
237 {Load LastUsedConfig.}
238 LoadLastUsedConfig();
240 {Get Wine path info.}
244 AsyncProcessScan
:= TAsyncProcess
.Create(nil) ;
245 AsyncProcessScan
.Options
:= AsyncProcessScan
.Options
+ [poUsePipes
,poStderrToOutPut
,poNoconsole
,poNewProcessGroup
];
246 Timer
:= TTimer
.Create(nil) ;
247 Timer
.OnTimer
:= @TimerOnTimer
;
248 Timer
.Enabled
:= false;
249 Timer
.Interval
:= 100;
252 Btn_StopScan
.Visible
:= true;
256 procedure TForm1
.FormResize(Sender
: TObject
);
258 Btn_StopScan
.Left
:= (floor(form1
.Width
/ 2) - floor(Btn_StopScan
.Width
/ 2));
261 procedure TForm1
.TimerOnTimer(Sender
: TObject
);
265 { We should not use a timer to check this. The is a bug in lazarus, 'OnTerminate' of AsyncProcess never runs.}
266 if AsyncProcessScan
.Active
= true then
268 Timer
.Enabled
:= true;
269 Btn_StopScan
.Visible
:= true;
273 Btn_StopScan
.Visible
:= false;
274 TempList
:= TStringlist
.Create
;
275 Timer
.Enabled
:= false;
276 TempList
.LoadFromStream(AsyncProcessScan
.OutPut
);
278 if TempList
.Count
= 0 then
280 DiscErrorText
:= 'Drive' + wrap('D' + ':') + 'has no executable files.';
281 LastReadLinkPath
:= '';
288 while TempList
.Count
<> 0 do
290 CdData
.Add(UnixToWinPath(TempList
.Strings
[0],'d'));
294 ComboBox_PreFixChange(self
);
297 CheckListBox_Flags
.Clear
;
301 procedure TForm1
.TogBtn_ListdriveChange(Sender
: TObject
);
306 AsyncProcessScan
.Active
:= false;
307 Btn_StopScan
.Visible
:= false;
308 CheckListBox_Flags
.Enabled
:= true;
309 EditBox_ProgramPath
.Clear
;
310 ComboBox_PreFixChange(self
);
311 ComboBox_ProgramsListChange(self
);
316 if CdData
= nil then CdData
:= TStringlist
.Create
;
317 if CdDataName
= nil then CdDataName
:= TStringlist
.Create
;
319 log(0,'', LastReadLinkPath
);
320 ComboBox_PreFixChange(self
);
321 CheckListBox_Flags
.Clear
;
322 EditBox_ProgramPath
.Clear
;
329 procedure TForm1
.Btn_RunClick(Sender
: TObject
);
331 RunWineCheck( '', '' );
334 procedure TForm1
.Btn_SettingsClick(Sender
: TObject
);
336 UnitSettings
.Form4
.Show
;
339 procedure TForm1
.Btn_StopScanClick(Sender
: TObject
);
341 AsyncProcessScan
.Active
:= false;
344 procedure TForm1
.Button_RegeditClick(Sender
: TObject
);
346 RunWineCheck( 'Regedit', '' );
349 procedure TForm1
.Button_WinecfgClick(Sender
: TObject
);
351 RunWineCheck( 'winecfg', '' );
354 procedure TForm1
.CheckBox_UseSoundWrapperChange(Sender
: TObject
);
356 SaveLastUsedConfig();
359 procedure TForm1
.Check_TerminalChange(Sender
: TObject
);
361 SaveLastUsedConfig();
364 procedure TForm1
.ComboBox_ArchitectureChange(Sender
: TObject
);
369 procedure TForm1
.ComboBox_DistributionNameEditingDone(Sender
: TObject
);
374 procedure TForm1
.ComboBox_DistributionVersionEditingDone(Sender
: TObject
);
379 procedure TForm1
.ComboBox_PreFixChange(Sender
: TObject
);
387 ComboBox_ProgramsList
.Items
.Clear
;
391 EditBox_ProgramPath
.Enabled
:= true;
392 ComboBox_ProgramsList
.Enabled
:= true;
398 if Data
[ComboBox_PreFix
.ItemIndex
].Grid
.Cells
[DataNameCol
, myloop
] <> '' then
400 ComboBox_ProgramsList
.Items
.Add(Data
[ComboBox_PreFix
.ItemIndex
].Grid
.Cells
[DataNameCol
, myloop
]);
409 if ComboBox_ProgramsList
.Items
.Count
<> 0 then
411 ComboBox_ProgramsList
.Text := ComboBox_ProgramsList
.Items
[0];
412 ComboBox_ProgramsListChange(Self
);
413 EditBox_ProgramPath
.Enabled
:= true;
414 ComboBox_ProgramsList
.Enabled
:= true;
418 ComboBox_ProgramsList
.Text := '';
419 EditBox_ProgramPath
.Text := '';
420 EditBox_ProgramPath
.Enabled
:= false;
421 ComboBox_ProgramsList
.Enabled
:= false;
427 ListProgramsOnDisc(CdData
, 'D');
428 if CdData
.Text <> '' then
431 CdDataName
.AddStrings(CdData
);
433 for myloop
:= 0 to CdDataName
.Count
-1 do
435 temp
:= CdDataName
.Strings
[myloop
];
436 temp
:= AnsiReverseString(temp
);
437 temp
:= Copy2Symb(temp
, '\');
438 Copy2SymbDel(temp
, '.');
439 temp
:= AnsiReverseString(temp
);
441 CdDataName
.Strings
[myloop
] := temp
;
443 ComboBox_ProgramsList
.Items
:= CdDataName
;
444 if ComboBox_ProgramsList
.Items
.Count
<> 0 then
446 ComboBox_ProgramsList
.Text := ComboBox_ProgramsList
.Items
[0];
447 EditBox_ProgramPath
.Enabled
:= true;
448 ComboBox_ProgramsList
.Enabled
:= true;
449 ComboBox_ProgramsListChange(self
);
455 ComboBox_ProgramsList
.Text := DiscErrorText
;
456 EditBox_ProgramPath
.Text := '';
457 EditBox_ProgramPath
.Enabled
:= false;
458 ComboBox_ProgramsList
.Enabled
:= false;
459 CheckListBox_Flags
.Clear
;
465 procedure TForm1
.ComboBox_ProgramsListChange(Sender
: TObject
);
467 ProgramsListSelectedItem
:integer;
472 PrefixInt
:= FindPrefixInt(ComboBox_PreFix
.Items
.Strings
[ComboBox_PreFix
.ItemIndex
]);
473 EditBox_ProgramPath
.Enabled
:= true;
474 {Plus one to line it up with the grid}
475 ProgramsListSelectedItem
:= (Data
[PrefixInt
].Grid
.cols
[DataNameCol
].IndexOf(Data
[PrefixInt
].Grid
.cols
[DataNameCol
].Strings
[ComboBox_ProgramsList
.ItemIndex
]) +1);
477 EditBox_ProgramPath
.Text := Data
[PrefixInt
].Grid
.Cells
[DataPathCol
, ProgramsListSelectedItem
] ;
478 CutUpFlags(Data
[PrefixInt
].Grid
.Cells
[DataFlagsCol
, ProgramsListSelectedItem
]);
483 if CdData
.Text <> '' then
485 EditBox_ProgramPath
.Text := CdData
.Strings
[CdDataName
.IndexOf(ComboBox_ProgramsList
.Text)] ;
490 procedure TForm1
.ComboBox_WineVersionEditingDone(Sender
: TObject
);
495 procedure TForm1
.EditBox_ProgramPathChange(Sender
: TObject
);
497 ColourCheck(EditBox_ProgramPath
);
501 procedure TForm1
.Btn_AboutClick(Sender
: TObject
);
503 UnitAbout
.Form3
.Show
;
506 procedure TForm1
.Btn_DebugChannelsConfigClick(Sender
: TObject
);
508 UnitDebugConfig
.Form2
.Show
;