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
, strutils
, BaseUnix
, Process
;
25 procedure Log(Level
:integer; Channel
:string; LogText
:string);
27 procedure LogVar(MyVar
:string; MyVarName
:string);
29 procedure SaveLastUsedConfig();
30 procedure LoadLastUsedConfig();
32 function Wrap(Input
:string):string; { Makes Paths look better, E.G. " ( Input ) " }
33 function WinToUnixPath(Path
:string):string;
34 function GetUnixDirPath(FilePath
:string):string;
35 function FileExistsAndIsExecutable(FullPath
:string; JustCheckExists
:boolean): boolean ;
36 function WorkDirTemplate(FolderPath
:string):string;
37 function DoesFolderExists(Path
:string; FolderName
:string): boolean;
38 function DoesFoldersExists(Path
:string; FolderNames
:Tstrings
): boolean;
39 function DirExistsIfNotMakeIt(Path
:string; FolderName
:string ): boolean;
40 function CheckPaths():boolean;
41 function SetupGit():boolean;
42 function MakeFile(FullPath
:string;Data
:string):boolean;
43 function SetExecutableFlag(FullPath
:string):boolean;
46 XmlLastUsedConfig
:TXMLConfig
;
53 function FileExistsAndIsExecutable(FullPath
:string; JustCheckExists
:boolean): boolean ;
57 ChannelLocal
:= ('FileExistsAndIsExecutable');
59 if JustCheckExists
= true then
61 if FileExists(FullPath
) then
64 if JustCheckExists
= true then Log(3, ChannelLocal
, 'File' + Wrap(FullPath
) + 'exists.');
70 Log(4, ChannelLocal
,'File' + Wrap(FullPath
) + 'does not exists.');
76 if FpAccess(FullPath
, X_OK
{Exe flag check}) <> 0 then
78 Log(4, ChannelLocal
,'File' + Wrap(FullPath
) + 'is not executable.');
84 Log(3, ChannelLocal
,'File' + Wrap(FullPath
) + 'is executable.');
92 function Wrap(Input
: string):string;
94 Result
:= ( ' ( ' + Input
+ ' ) ' );
97 function DoesFoldersExists(Path
:string; FolderNames
:Tstrings
): boolean;
102 { Take a path and check to see if the listed folders exists in that path. }
103 { TODO : Add a way to check the result from each one and return it. }
104 for loop
:= 0 to ( FolderNames
.Count
- 1 ) do
106 if DoesFolderExists(Path
, FolderNames
[loop
]) = false then
114 function DoesFolderExists(Path
:string; FolderName
:string): boolean;
118 ChannelLocal
:= 'DoesFolderExists';
119 if DirectoryExists(Path
+ FolderName
) = true then
123 UnitMain
.form1
.LogWithDebug(3, ChannelLocal
, ('Folder' + Wrap(Path
+ FolderName
) + 'exists.'));
129 Log(4, ChannelLocal
, ('Folder' + Wrap(Path
+ FolderName
) + 'does not exists.'));
133 procedure Log(Level
:integer;Channel
:string;LogText
:string);
140 if AllFine
= true then
146 {Level 4 "Dev-Error"}
147 {Level 5 is for uses with custom functions.}
150 LevelString
:= 'Info';
155 LevelString
:= 'Error';
160 LevelString
:= 'Variable';
165 LevelString
:= 'Dev-Info';
170 LevelString
:= 'Dev-Error';
176 UnitMain
.form1
.Memo_LogOutPut
.Lines
.Add(LogText
);
184 if HideChannel
= true then
186 WriteLn(LevelString
+ ': ' + LogText
);
187 UnitMain
.form1
.Memo_LogOutPut
.Lines
.Add(LevelString
+ ': ' + LogText
);
191 WriteLn(LevelString
+ ':' + Channel
+ ': ' + LogText
);
192 UnitMain
.form1
.Memo_LogOutPut
.Lines
.Add(LevelString
+ ':' + Channel
+ ': ' + LogText
);
200 procedure SaveLastUsedConfig();
202 if Loading
= true then exit
;
205 XmlLastUsedConfig
.SetValue('Version', '2');
206 XmlLastUsedConfig
.SetValue('WineVersionInfo/DistributionName', UnitMain
.form1
.ComboBox_DistributionName
.Text );
207 XmlLastUsedConfig
.SetValue('WineVersionInfo/DistributionVersion', UnitMain
.form1
.ComboBox_DistributionVersion
.Text );
208 XmlLastUsedConfig
.SetValue('WineVersionInfo/Architecture', UnitMain
.form1
.ComboBox_Architecture
.Text );
209 XmlLastUsedConfig
.SetValue('WineVersionInfo/WineVersion', UnitMain
.form1
.ComboBox_WineVersion
.Text );
211 XmlLastUsedConfig
.SetValue('WineVersionInfo/UsesTerminal', UnitMain
.form1
.Check_Terminal
.Checked
);
212 XmlLastUsedConfig
.SetValue('WineVersionInfo/UsesSoundWrapper', UnitMain
.form1
.CheckBox_UseSoundWrapper
.Checked
);
215 XmlLastUsedConfig
.Filename
:= ( ConfigPath
+ '/LastUsedConfig.xml' );
218 XmlLastUsedConfig
.Flush
;
223 procedure LoadLastUsedConfig();
225 LastUsedConfigVersion
:string;
228 XmlLastUsedConfig
:= TXMLConfig
.Create(nil);
231 XmlLastUsedConfig
.Filename
:= ( ConfigPath
+ '/LastUsedConfig.xml' );
233 { Version of Settings }
234 LastUsedConfigVersion
:= XmlLastUsedConfig
.GetValue('Version','');
236 LogVar(LastUsedConfigVersion
,'LastUsedConfigVersion');
239 { Make sure we can read the file. }
240 if LastUsedConfigVersion
= '-1' then
242 Log(3, Channel
, 'Invalided file version, Never mind we ignore it and wirte over it.');
246 UnitMain
.form1
.ComboBox_DistributionName
.Text := XmlLastUsedConfig
.GetValue('WineVersionInfo/DistributionName', '' );
247 UnitMain
.form1
.ComboBox_DistributionVersion
.Text := XmlLastUsedConfig
.GetValue('WineVersionInfo/DistributionVersion', '' );
248 UnitMain
.form1
.ComboBox_Architecture
.Text := XmlLastUsedConfig
.GetValue('WineVersionInfo/Architecture', '' );
249 UnitMain
.form1
.ComboBox_WineVersion
.Text := XmlLastUsedConfig
.GetValue('WineVersionInfo/WineVersion', '' );
251 UnitMain
.form1
.Check_Terminal
.Checked
:= XmlLastUsedConfig
.GetValue('WineVersionInfo/UsesTerminal', false );
252 UnitMain
.form1
.CheckBox_UseSoundWrapper
.Checked
:= XmlLastUsedConfig
.GetValue('WineVersionInfo/UsesSoundWrapper', false );
256 XmlLastUsedConfig
.Flush
;
262 function WinToUnixPath(Path
:string):string;
264 PathUpToDosdevices
:string;
265 DriveNameWithSlash
:string;
268 {Get the path up to Dosdevices.}
269 PathUpToDosdevices
:= (GetEnvironmentVariable('HOME') + '/' + WineUserFolder
+ '/prefix/' + UnitMain
.form1
.ComboBox_PreFix
.Text + '/dosdevices/' );
270 {Take the DriveName off 'path' and replace '\' with '/'.}
271 DriveNameWithSlash
:= (AnsiLowerCase( Copy2SymbDel( Path
, '\' )) + '/');
272 {Replace all '\' to '/'.}
273 Path
:= AnsiReplaceText(Path
, '\', '/');
275 FullUnixPath
:= (PathUpToDosdevices
+ DriveNameWithSlash
+ Path
);
277 {$IFDEF MOREDEBUG_WinToUnixPath}
278 logVar(PathUpToDosdevices
, 'PathUpToDosdevices');
279 logVar(DriveNameWithSlash
, 'DriveNameWithSlash');
280 logVar(Path
, 'Path');
282 logVar(FullUnixPath
, 'FullUnixPath');
284 Result
:= FullUnixPath
;
288 function GetUnixDirPath(FilePath
:string):string;
291 //LocalChannel:string;
293 DirPath
:= LeftStr(FilePath
, (Rpos('/',FilePath
) ));
294 //log(0, LocalChannel, ( 'VAR ' + DirPath));
299 function WorkDirTemplate(FolderPath
:string):string;
301 Result
:= ('cd "' + FolderPath
+ '";' + #10 );
305 procedure LogVar(MyVar
: string; MyVarName
: string);
307 Log(2, 'LogVar', ( Wrap( MyVarName
) + 'is' + Wrap( MyVar
)) );
311 function CheckPaths():boolean;
316 if DirExistsIfNotMakeIt(GetEnvironmentVariable('HOME'), '/.config') <> true then
321 {This should use ConfigPath but 'DirExistsIfNotMakeIt' passes it in two bits.}
322 if DirExistsIfNotMakeIt(GetEnvironmentVariable('HOME' ) + '/.config/', 'WineLauncher') <> true then
328 if DirExistsIfNotMakeIt(GetEnvironmentVariable('HOME') + '/' , WineUserFolder
) = false then
333 if DirExistsIfNotMakeIt(GetEnvironmentVariable('HOME') + '/' + WineUserFolder
+ '/', 'prefix') = false then
339 if DoesFolderExists(GetEnvironmentVariable('HOME') + '/' + WineUserFolder
+ '/', 'git') = false then
346 if DirExistsIfNotMakeIt(GetEnvironmentVariable('HOME') + '/' + WineUserFolder
+ '/', 'wine') = false then
357 function SetupGit():boolean;
365 Process
:= TProcess
.Create(nil);
367 ChannelLocal
:= 'SetupGit';
369 script
:= '#! /bin/sh' +{linebrake}#10 +
370 'echo This script will fetch Wine and compile it. ;'+{linebrake}#10 +
371 'echo If it fails please install the dependencies and rerun WineLauncher, see http://wiki.winehq.org/Recommended_Packages for more help.' +{linebrake}#10 +
372 'cd ' + GetEnvironmentVariable('HOME') + '/' + WineUserFolder
+ ' ;' +{linebrake}#10 +
373 'git clone git://source.winehq.org/git/wine.git git ;' +{linebrake}#10 +
374 'cd ./git ;' +{linebrake}#10 +
375 'git checkout -b stable-1.0.1 wine-1.0.1 ;' +{linebrake}#10 +
376 'Dname=`lsb_release -si` ;' +{linebrake}#10 +
377 'Dversion=`lsb_release -sr` ;' +{linebrake}#10 +
378 'Aname=`uname -m` ;' +{linebrake}#10 +
379 './configure --prefix=' + GetEnvironmentVariable('HOME') + '/' + WineUserFolder
+ '/wine/$Dname/$Dversion/$Aname/stable-1.0.1 ;' +{linebrake}#10 +
380 'make ;' +{linebrake}#10 +
381 'make install;' +{linebrake}#10 +
382 GetEnvironmentVariable('HOME') + '/' + WineUserFolder
+ '/wine/$Dname/$Dversion/$Aname/stable-1.0.1/bin/wineprefixcreate --prefix "' + GetEnvironmentVariable('HOME') + '/' + WineUserFolder
+ '/prefix/default/"' +{linebrake}#10 ;
385 if MakeFile((ConfigPath
+ '/SetupGit'),script
) = true then
388 {Set executable flag}
389 if SetExecutableFlag(ConfigPath
+ '/1') = false then
394 if FileExistsAndIsExecutable('/usr/bin/gnome-terminal',false) = true then
396 Terminal
:= 'gnome-terminal -x ';
400 if FileExistsAndIsExecutable('/usr/bin/gnome-terminal',false) = true then
402 Terminal
:= '/usr/bin/konsole -x ';
405 if FileExistsAndIsExecutable('/usr/bin/gnome-terminal',false) = true then
407 Terminal
:= '/usr/bin/xterm ';
412 if RunYes
= true then
414 Log(0, ChannelLocal
, 'Script One has being executed.');
415 Process
.CommandLine
:= Terminal
+ ConfigPath
+'/SetupGit';
419 while Process
.Running
= true do
424 Result
:= AProcess
.WaitOnExit
;
431 function DirExistsIfNotMakeIt(Path
:string; FolderName
:string ): boolean;
433 LocalChannel
:string; {Ignore this for now}
437 if FolderName
<> '' then
439 if DirectoryExists( Path
+ FolderName
) = true then
441 Log(0, LocalChannel
, ('Directory' + Wrap( Path
+ FolderName
) + 'exists.')) ;
446 Log(0, LocalChannel
, ('Directory' + Wrap( Path
+ FolderName
) + ' does not exists.')) ;
447 if CreateDir( Path
+ FolderName
) then
449 Log(0, LocalChannel
, ('File' + Wrap( Path
+ FolderName
) + 'has being created.')) ;
454 Log(0, LocalChannel
, ('File' + Wrap( Path
+ FolderName
) + 'can not be created.')) ;
468 function MakeFile(FullPath
:string;Data
:string):boolean;
474 FD1
:= fpOpen (FullPath
, O_WrOnly
or O_Creat
);
477 if length(Data
)<>fpwrite (FD1
,Data
[1],Length(Data
)) then
480 Log(1, CL
, ('When writing to' + Wrap(FullPath
)) );
485 Log(3, CL
, ('File' + Wrap(FullPath
) + 'has being created'));
493 function SetExecutableFlag(FullPath
:string):boolean;
497 {770 is owner rwx, group rwx, other nothing}
498 if fpChmod (FullPath
,&770) <> 0 then {0 = no error}
500 Log(1, ChannelLocal
, ('Can not set executable flag on' + Wrap(FullPath
)) );
506 Log(0, ChannelLocal
, ('Executable flag has being set on' + Wrap(FullPath
)) );