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
;
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;
33 XmlLastUsedConfig
:TXMLConfig
;
34 LastUsedConfigLoading
:boolean;
36 {The next three are used by ListProgramsOnDisc.}
37 LastReadLinkPath
:string;
49 procedure SaveLastUsedConfig();
51 if LastUsedConfigLoading
= true then exit
;
54 XmlLastUsedConfig
.SetValue('Version', '2');
55 {Was WineVersionInfo/DistributionName,DistributionVersion,Architecture.}
56 XmlLastUsedConfig
.SetValue('WineVersionInfo/WineVersion', UnitMain
.form1
.ComboBox_WineVersion
.Text);
58 XmlLastUsedConfig
.SetValue('WineVersionInfo/UsesTerminal', UnitMain
.form1
.Check_Terminal
.Checked
);
59 XmlLastUsedConfig
.SetValue('WineVersionInfo/UsesSoundWrapper', UnitMain
.form1
.CheckBox_UseSoundWrapper
.Checked
);
62 XmlLastUsedConfig
.Filename
:= (ConfigPath
+ '/LastUsedConfig.xml');
65 XmlLastUsedConfig
.Flush
;
69 procedure LoadLastUsedConfig();
71 LastUsedConfigVersion
:string;
73 {Only run this ones wine has being scanned for.}
74 LastUsedConfigLoading
:= true;
75 XmlLastUsedConfig
:= TXMLConfig
.Create(nil);
78 XmlLastUsedConfig
.Filename
:= (ConfigPath
+ '/LastUsedConfig.xml');
79 {Get the version of the config file.}
80 LastUsedConfigVersion
:= XmlLastUsedConfig
.GetValue('Version','');
82 LogVar(LastUsedConfigVersion
,'LastUsedConfigVersion');
85 {Make sure the version value exists.}
86 if LastUsedConfigVersion
= '-1' then
88 Log(3, Channel
, 'Invalided file version, never mind we ignore it and wirte over it.');
92 {Setting ItemIndex does not trigger OnEditingDone.}
93 {So we run Enter to update the list then we run EditingDone to check it}
95 SelectItem(UnitMain
.form1
.ComboBox_WineVersion
, XmlLastUsedConfig
.GetValue('WineVersionInfo/WineVersion', ''));
96 UnitMain
.form1
.ComboBox_WineVersionEnter(form1
);
97 UnitMain
.form1
.ComboBox_WineVersionEditingDone(form1
);
100 UnitMain
.form1
.Check_Terminal
.Checked
:= XmlLastUsedConfig
.GetValue('WineVersionInfo/UsesTerminal', false);
101 UnitMain
.form1
.CheckBox_UseSoundWrapper
.Checked
:= XmlLastUsedConfig
.GetValue('WineVersionInfo/UsesSoundWrapper', false);
104 XmlLastUsedConfig
.Flush
;
105 LastUsedConfigLoading
:= false;
109 function RunWineCheck(ProgramNameOverRide
:string; ProgramFlagsOverRide
:string):boolean;
114 WinePreFixRaw
:string;
120 UnixPathWithOutFile
:string;
121 WinePath
:string; {~/.local/wine/[Wine Version]"}
123 ChannelLocal
:= ('RunWineCheck');
125 WinePath
:= (PathToWine
+ UnitMain
.form1
.ComboBox_WineVersion
.Text);
127 {Get wine version info}
128 if FileExistsAndIsExecutable((WinePath
+ '/wine'), false) = true then
130 wine_version_full
:= (WinePath
+ '/wine');
132 LogVar(wine_version_full
, 'wine_version_full');
136 if FileExistsAndIsExecutable((WinePath
+ '/bin/wine'), false) = true then
138 wine_version_full
:= (WinePath
+ '/bin/wine');
140 LogVar(wine_version_full
, 'wine_version_full');
145 Log(0, ChannelLocal
, 'Can not find wine');
150 if UnitMain
.form1
.Check_Terminal
.Checked
= true then
152 if UnitMain
.form1
.ComboBox_TerminalName
.Text <> '' then
154 temp00
:= UnitMain
.form1
.ComboBox_TerminalName
.ItemIndex
;
155 RunIn
:= (UnitSettings
.Form4
.StringGrid_TerminalSettings
.Cells
[1,temp00
] + ' ' + UnitSettings
.Form4
.StringGrid_TerminalSettings
.Cells
[2,temp00
]);
156 Log(0, ChannelLocal
, ('Using Terminal' + Wrap(RunIn
)) );
161 {After the Program is closed the child process is still listed.}
162 RunIn
:= UnitSettings
.Form4
.ComboBox_ShellPath
.text;
163 Log(0, ChannelLocal
, ('Using' + Wrap(RunIn
)) );
167 WinePreFixRaw
:= (PreFixList
[1].Strings
[UnitMain
.form1
.ComboBox_PreFix
.ItemIndex
]);
168 WinePreFix
:= ('env WINEPREFIX="' + WinePreFixRaw
+ '"');
170 LogVar(WinePreFix
, 'WinePreFix');
175 if UnitMain
.form1
.CheckBox_UseSoundWrapper
.Checked
= true then
177 if FileExists(UnitMain
.form1
.ComboBox_SoundWrapper
.Text) = true then
179 SoundWrapper
:= (UnitMain
.form1
.ComboBox_SoundWrapper
.Text + ' ');
180 Log(0, ChannelLocal
, ('File' + Wrap(UnitMain
.form1
.ComboBox_SoundWrapper
.Text) + 'exists'));
184 Log(1, ChannelLocal
, ('File' + Wrap(UnitMain
.form1
.ComboBox_SoundWrapper
.Text) + 'does not exists'));
190 Log(0, ChannelLocal
, ('No sound wrapper will be used'));
194 if ProgramNameOverRide
= '' then
196 if UnitMain
.form1
.EditBox_ProgramPath
.Text <> '' then
199 for loop
:= 0 to (UnitMain
.form1
.CheckListBox_Flags
.Items
.Count
) do
201 if UnitMain
.form1
.CheckListBox_Flags
.Checked
[loop
] = true then
203 ProgramFlags
:= (ProgramFlags
+ ' ' + UnitMain
.form1
.CheckListBox_Flags
.Items
.ValueFromIndex
[loop
]);
207 LogVar(ProgramFlags
, 'ProgramFlags' );
209 ProgramName
:= (' ' + '"' + UnitMain
.form1
.EditBox_ProgramPath
.Text + '"' + ProgramFlags
+ ' ');
213 Log(1, ChannelLocal
, ('Please select a program.'));
219 ProgramName
:= (' ' + '"' + ProgramNameOverRide
+ '"' + ProgramFlagsOverRide
+ ' ');
223 UnixPathWithOutFile
:= ExtractFilePath(WinToUnixPath(UnitMain
.form1
.EditBox_ProgramPath
.Text));
224 if ProgramNameOverRide
= '' then
226 if DoesFolderExists(ExtractFilePath(UnixPathWithOutFile
), ExtractFileName(UnixPathWithOutFile
)) then
228 WorkDir
:= WorkDirTemplate(GetUnixDirPath(WinToUnixPath(UnitMain
.form1
.EditBox_ProgramPath
.Text)) );
232 WorkDir
:= WorkDirTemplate(WinePreFixRaw
+ '/dosdevices/c:/windows');
237 WorkDir
:= WorkDirTemplate(WinePreFixRaw
+ '/dosdevices/c:/windows');
241 start_S1
:= ('#! /bin/sh' + {linebrake}#10 + WorkDir
{Line brake done in template.} + WinePreFix
+ SoundWrapper
+ ' ' + wine_version_full
+ ' ' + ProgramName
+ ';');
243 LogVar(start_S1
, 'start_S1');
247 if MakeFile((ConfigPath
+ '/1'), start_S1
) = false then
249 log(1, ChannelLocal
, ('Can not make file' + wrap(ConfigPath
+ '/1')) );
253 {Set executable flag}
254 if SetExecutableFlag(ConfigPath
+ '/1') = false then
256 log(1, ChannelLocal
, ('Can not set executable flag on file'+ wrap(ConfigPath
+ '/1')) );
261 Log(0, ChannelLocal
, ('Script One has being executed.'));
262 AProcess
.CommandLine
:= (RunIn
+ ' ' + ConfigPath
+'/1');
263 {After the Program is closed the child process is still listed.}
268 function ListProgramsOnDisc(ModeMe
:TStrings
; DriveChar
:char):boolean;
276 {TODO : This function needs to check the drive not just the folders.}
277 Path
:= (PathToPrefix
+ UnitMain
.Form1
.ComboBox_PreFix
.Text + '/dosdevices/' + AnsiLowerCase(DriveChar
));
279 {Do not rescan if the path is the same as the last one.}
280 {Note if you change disks it will not rescan it.}
281 if OldPath
= Path
then exit(false);
283 if AsyncProcessScan
.Active
= false then
287 LastReadLinkPath
:= fpReadLink(Path
+ ':');
291 if LastReadLinkPath
= '' then
293 log(4, '',('Link ' + Wrap(Path
+ ':') + 'does not exists.'));
294 LastReadLinkPath
:= '';
295 DiscErrorText
:= 'Please map' + wrap(DriveChar
+ ':') + 'to your cd / dvd drive, You can do that in winecfg.';
301 if FindFirst((Path
+ ':/*'), faAnyFile
and faDirectory
, Info
) = 0 then
305 Until FindNext(info
) <> 0;
308 log(0,'', Info
.Name
);
309 DiscErrorText
:= 'You have no disc in your drive.';
310 LastReadLinkPath
:= '';
316 if LastReadLinkPath
= '/' then
318 DiscErrorText
:= 'You can not map '+ DriveChar
+ ': to root.';
319 LastReadLinkPath
:= '';
323 if LastReadLinkPath
= GetEnvironmentVariable('HOME') then
325 DiscErrorText
:= 'You can not map '+ DriveChar
+ ': to your home folder.';
326 LastReadLinkPath
:= '';
330 FindPath
:= SearchForBin('find');
331 if FindPath
= '' then
333 DiscErrorText
:= ('Can not find the program called' + Wrap('find'));
334 LastReadLinkPath
:= '';
338 script
:= (FindPath
+ ' -H ' + Path
+ ': -iname *.exe');
339 Log(0, '', 'Script Scan has being executed.');
340 AsyncProcessScan
.CommandLine
:= script
;
341 AsyncProcessScan
.Execute
;
342 DiscErrorText
:= 'Scaning';
343 Timer
.Enabled
:= true;
349 procedure OnWineVersionChange();
351 if UnitMain
.form1
.ComboBox_WineVersion
.Text <> '' then
353 UnitMain
.form1
.Btn_Run
.Enabled
:= true;
356 UnitMain
.form1
.Btn_Run
.Enabled
:= false;