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/>.
23 Classes
, SysUtils
, XMLCfg
, Process
, BaseUnix
, ComCtrls
, Forms
, Controls
;
25 procedure SaveLastUsedConfig();
26 procedure LoadLastUsedConfig();
27 procedure OnWineVersionChange();
29 function RunWineCheck(ProgramNameOverRide
:string; ProgramFlagsOverRide
:string):boolean;
30 function ListProgramsOnDisc(ModeMe
:TStrings
; DriveChar
:char):boolean;
31 function AddTabToPageControl(PageControl
:TPageControl
; caption
:string):boolean;
32 function EmbedFrame(frame
:TFrame
; PageNumber
:integer):boolean;
35 XmlLastUsedConfig
:TXMLConfig
;
36 LastUsedConfigLoading
:boolean;
38 {The next three are used by ListProgramsOnDisc.}
39 LastReadLinkPath
:string;
51 procedure SaveLastUsedConfig();
53 if LastUsedConfigLoading
= true then exit
;
56 XmlLastUsedConfig
.SetValue('Version', '2');
57 {Was WineVersionInfo/DistributionName,DistributionVersion,Architecture.}
58 XmlLastUsedConfig
.SetValue('WineVersionInfo/WineVersion', UnitMain
.form1
.ComboBox_WineVersion
.Text);
60 XmlLastUsedConfig
.SetValue('WineVersionInfo/UsesTerminal', UnitMain
.form1
.Check_Terminal
.Checked
);
61 XmlLastUsedConfig
.SetValue('WineVersionInfo/UsesSoundWrapper', UnitMain
.form1
.CheckBox_UseSoundWrapper
.Checked
);
64 XmlLastUsedConfig
.Filename
:= (ConfigPath
+ '/LastUsedConfig.xml');
67 XmlLastUsedConfig
.Flush
;
71 procedure LoadLastUsedConfig();
73 LastUsedConfigVersion
:string;
75 {Only run this ones wine has being scanned for.}
76 LastUsedConfigLoading
:= true;
77 XmlLastUsedConfig
:= TXMLConfig
.Create(nil);
80 XmlLastUsedConfig
.Filename
:= (ConfigPath
+ '/LastUsedConfig.xml');
81 {Get the version of the config file.}
82 LastUsedConfigVersion
:= XmlLastUsedConfig
.GetValue('Version','');
84 LogVar(LastUsedConfigVersion
,'LastUsedConfigVersion');
87 {Make sure the version value exists.}
88 if LastUsedConfigVersion
= '-1' then
90 Log(3, Channel
, 'Invalided file version, never mind we ignore it and wirte over it.');
94 {Setting ItemIndex does not trigger OnEditingDone.}
95 {So we run Enter to update the list then we run EditingDone to check it}
97 SelectItem(UnitMain
.form1
.ComboBox_WineVersion
, XmlLastUsedConfig
.GetValue('WineVersionInfo/WineVersion', ''));
98 UnitMain
.form1
.ComboBox_WineVersionEnter(form1
);
99 UnitMain
.form1
.ComboBox_WineVersionEditingDone(form1
);
102 UnitMain
.form1
.Check_Terminal
.Checked
:= XmlLastUsedConfig
.GetValue('WineVersionInfo/UsesTerminal', false);
103 UnitMain
.form1
.CheckBox_UseSoundWrapper
.Checked
:= XmlLastUsedConfig
.GetValue('WineVersionInfo/UsesSoundWrapper', false);
106 XmlLastUsedConfig
.Flush
;
107 LastUsedConfigLoading
:= false;
111 function RunWineCheck(ProgramNameOverRide
:string; ProgramFlagsOverRide
:string):boolean;
116 WinePreFixRaw
:string;
122 UnixPathWithOutFile
:string;
123 WinePath
:string; {~/.local/wine/[Wine Version]"}
125 ChannelLocal
:= ('RunWineCheck');
127 WinePath
:= (PathToWine
+ UnitMain
.form1
.ComboBox_WineVersion
.Text);
129 {Get wine version info}
130 wine_version_full
:= FindWine(WinePath
);
131 if wine_version_full
= '' then exit(false);
135 if UnitMain
.form1
.Check_Terminal
.Checked
= true then
137 if UnitMain
.form1
.ComboBox_TerminalName
.Text <> '' then
139 temp00
:= UnitMain
.form1
.ComboBox_TerminalName
.ItemIndex
;
140 RunIn
:= (UnitSettings
.Form4
.StringGrid_TerminalSettings
.Cells
[1,temp00
] + ' ' + UnitSettings
.Form4
.StringGrid_TerminalSettings
.Cells
[2,temp00
]);
141 Log(0, ChannelLocal
, ('Using Terminal' + Wrap(RunIn
)) );
146 {After the Program is closed the child process is still listed.}
147 RunIn
:= UnitSettings
.Form4
.ComboBox_ShellPath
.text;
148 Log(0, ChannelLocal
, ('Using' + Wrap(RunIn
)) );
152 WinePreFixRaw
:= (PreFixList
[1].Strings
[UnitMain
.form1
.ComboBox_PreFix
.ItemIndex
]);
153 WinePreFix
:= ('env WINEPREFIX="' + WinePreFixRaw
+ '"');
155 LogVar(WinePreFix
, 'WinePreFix');
160 if UnitMain
.form1
.CheckBox_UseSoundWrapper
.Checked
= true then
162 if FileExists(UnitMain
.form1
.ComboBox_SoundWrapper
.Text) = true then
164 SoundWrapper
:= (UnitMain
.form1
.ComboBox_SoundWrapper
.Text + ' ');
165 Log(0, ChannelLocal
, ('File' + Wrap(UnitMain
.form1
.ComboBox_SoundWrapper
.Text) + 'exists'));
169 Log(1, ChannelLocal
, ('File' + Wrap(UnitMain
.form1
.ComboBox_SoundWrapper
.Text) + 'does not exists'));
175 Log(0, ChannelLocal
, ('No sound wrapper will be used'));
179 if ProgramNameOverRide
= '' then
181 if UnitMain
.form1
.EditBox_ProgramPath
.Text <> '' then
184 for loop
:= 0 to (UnitMain
.form1
.CheckListBox_Flags
.Items
.Count
) do
186 if UnitMain
.form1
.CheckListBox_Flags
.Checked
[loop
] = true then
188 ProgramFlags
:= (ProgramFlags
+ ' ' + UnitMain
.form1
.CheckListBox_Flags
.Items
.ValueFromIndex
[loop
]);
192 LogVar(ProgramFlags
, 'ProgramFlags' );
194 ProgramName
:= (' ' + '"' + UnitMain
.form1
.EditBox_ProgramPath
.Text + '"' + ProgramFlags
+ ' ');
198 Log(1, ChannelLocal
, ('Please select a program.'));
204 ProgramName
:= (' ' + '"' + ProgramNameOverRide
+ '"' + ProgramFlagsOverRide
+ ' ');
208 UnixPathWithOutFile
:= ExtractFilePath(WinToUnixPath(UnitMain
.form1
.EditBox_ProgramPath
.Text));
209 if ProgramNameOverRide
= '' then
211 if DoesFolderExists(ExtractFilePath(UnixPathWithOutFile
), ExtractFileName(UnixPathWithOutFile
)) then
213 WorkDir
:= WorkDirTemplate(GetUnixDirPath(WinToUnixPath(UnitMain
.form1
.EditBox_ProgramPath
.Text)) );
217 WorkDir
:= WorkDirTemplate(WinePreFixRaw
+ '/dosdevices/c:/windows');
222 WorkDir
:= WorkDirTemplate(WinePreFixRaw
+ '/dosdevices/c:/windows');
226 start_S1
:= ('#! /bin/sh' + {linebrake}#10 + WorkDir
{Line brake done in template.} + WinePreFix
+ SoundWrapper
+ ' "' + wine_version_full
+ '" ' + ProgramName
+ ';');
228 LogVar(start_S1
, 'start_S1');
232 if MakeFile((ConfigPath
+ '/1'), start_S1
) = false then
234 log(1, ChannelLocal
, ('Can not make file' + wrap(ConfigPath
+ '/1')) );
238 {Set executable flag}
239 if SetExecutableFlag(ConfigPath
+ '/1') = false then
241 log(1, ChannelLocal
, ('Can not set executable flag on file'+ wrap(ConfigPath
+ '/1')) );
246 Log(0, ChannelLocal
, ('Script One has being executed.'));
247 AProcess
.CommandLine
:= (RunIn
+ ' ' + ConfigPath
+'/1');
248 {After the Program is closed the child process is still listed.}
253 function ListProgramsOnDisc(ModeMe
:TStrings
; DriveChar
:char):boolean;
261 {TODO : This function needs to check the drive not just the folders.}
262 Path
:= (PathToPrefix
+ UnitMain
.Form1
.ComboBox_PreFix
.Text + '/dosdevices/' + AnsiLowerCase(DriveChar
));
264 {Do not rescan if the path is the same as the last one.}
265 {Note if you change disks it will not rescan it.}
266 if OldPath
= Path
then exit(false);
268 if AsyncProcessScan
.Active
= false then
272 LastReadLinkPath
:= fpReadLink(Path
+ ':');
276 if LastReadLinkPath
= '' then
278 log(4, '',('Link ' + Wrap(Path
+ ':') + 'does not exists.'));
279 LastReadLinkPath
:= '';
280 DiscErrorText
:= 'Please map' + wrap(DriveChar
+ ':') + 'to your cd / dvd drive, You can do that in winecfg.';
286 if FindFirst((Path
+ ':/*'), faAnyFile
and faDirectory
, Info
) = 0 then
290 Until FindNext(info
) <> 0;
293 log(0,'', Info
.Name
);
294 DiscErrorText
:= 'You have no disc in your drive.';
295 LastReadLinkPath
:= '';
301 if LastReadLinkPath
= '/' then
303 DiscErrorText
:= 'You can not map '+ DriveChar
+ ': to root.';
304 LastReadLinkPath
:= '';
308 if LastReadLinkPath
= GetEnvironmentVariable('HOME') then
310 DiscErrorText
:= 'You can not map '+ DriveChar
+ ': to your home folder.';
311 LastReadLinkPath
:= '';
315 FindPath
:= SearchForBin('find');
316 if FindPath
= '' then
318 DiscErrorText
:= ('Can not find the program called' + Wrap('find'));
319 LastReadLinkPath
:= '';
323 script
:= (FindPath
+ ' -H ' + Path
+ ': -iname *.exe');
324 Log(0, '', 'Script Scan has being executed.');
325 AsyncProcessScan
.CommandLine
:= script
;
326 AsyncProcessScan
.Execute
;
327 DiscErrorText
:= 'Scaning';
328 Timer
.Enabled
:= true;
334 procedure OnWineVersionChange();
336 if UnitMain
.form1
.ComboBox_WineVersion
.Text <> '' then
338 UnitMain
.form1
.Btn_Run
.Enabled
:= true;
341 UnitMain
.form1
.Btn_Run
.Enabled
:= false;
344 function AddTabToPageControl(PageControl
:TPageControl
; caption
:string):boolean;
348 Index
:= PageControl
.PageCount
;
349 SetLength(TabSheets
, (Index
+ 1));
352 TabSheets
[Index
] := TTabSheet
.Create(TabSheets
[Index
]);
353 TabSheets
[Index
].Caption
:= caption
;
354 TabSheets
[Index
].PageControl
:= PageControl
;
357 function EmbedFrame(frame
:TFrame
; PageNumber
:integer):boolean;
359 frame
.Parent
:= UnitMain
.form1
.PageControl1
.Page
[PageNumber
];
360 frame
.Align
:= (alclient
);