UnitMisc: New function same as DirExistsIfNotMakeIt but takes the whole path in one...
[WineLauncher.git] / Functions / Misc / UnitMisc.pas
blob6cd31dacc4d7a3ccbbfaf64421f9751ad063760c
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 unit UnitMisc;
18 {$mode objfpc}{$H+}
20 interface
22 uses
23 Classes, SysUtils, XMLCfg, strutils, BaseUnix, Process, StdCtrls, FileUtil, Graphics;
25 procedure Log(Level:integer; Channel:string; LogText:string);
26 {$IFDEF LogVar}
27 procedure LogVar(MyVar:string; MyVarName:string);
28 {$ENDIF}
29 procedure SaveLastUsedConfig();
30 procedure LoadLastUsedConfig();
31 procedure RunWineCheck(ProgramNameOverRide:string; ProgramFlagsOverRide:string);
33 function Wrap(Input:string):string; { Makes Paths look better, E.G. " ( Input ) " }
34 function WinToUnixPath(Path:string):string;
35 function UnixToWinPath(Path:string; DriveChar:Char):string;
36 function GetUnixDirPath(FilePath:string):string;
37 function FileExistsAndIsExecutable(FullPath:string; JustCheckExists:boolean): boolean ;
38 function WorkDirTemplate(FolderPath:string):string;
39 function DoesFolderExists(Path:string; FolderName:string): boolean;
40 function DoesFoldersExists(Path:string; FolderNames:Tstrings): boolean;
41 function DirExistsIfNotMakeIt(Path:string; FolderName:string ): boolean;
42 function DirExistsIfNotMakeIt(PathWithFolder:string): boolean;
43 function CheckPaths():boolean;
44 function SetupGit():boolean;
45 function MakeFile(FullPath:string;Data:string):boolean;
46 function SetExecutableFlag(FullPath:string):boolean;
47 function ListProgramsOnDisc(ModeMe:TStrings; DriveChar:char):boolean;
48 function ColourCheck(Input: TEdit):boolean;
49 function CutUpFlags(Flags:string):boolean;
51 var
52 XmlLastUsedConfig:TXMLConfig;
53 Loading:boolean;
54 LastReadLinkPath:string;
55 DiscErrorText:string; {Used for the reporting errors in 'ListProgramsOnDisc'.}
56 OldPath:string;
58 implementation
59 uses UnitMain, UnitSettings, UnitProgramsList;
62 function FileExistsAndIsExecutable(FullPath:string; JustCheckExists:boolean): boolean ;
63 var
64 ChannelLocal:string;
65 begin
66 ChannelLocal := ('FileExistsAndIsExecutable');
68 if JustCheckExists = true then
69 begin
70 if FileExists(FullPath) then
71 begin
72 {$IFDEF MoreTrue }
73 if JustCheckExists = true then Log(3, ChannelLocal, 'File' + Wrap(FullPath) + 'exists.');
74 {$ENDIF}
75 Result := true;
76 end
77 else
78 begin
79 Log(4, ChannelLocal,'File' + Wrap(FullPath) + 'does not exists.');
80 Result := false;
81 end;
82 end
83 else
84 begin
85 if FpAccess(FullPath, X_OK {Exe flag check}) <> 0 then
86 begin
87 Log(4, ChannelLocal,'File' + Wrap(FullPath) + 'is not executable.');
88 Result := false;
89 end
90 else
91 begin
92 {$IFDEF MoreTrue }
93 Log(3, ChannelLocal,'File' + Wrap(FullPath) + 'is executable.');
94 {$ENDIF}
95 Result := true;
96 end;
98 end;
99 end;
101 function Wrap(Input: string):string;
102 begin
103 Result := ( ' ( ' + Input + ' ) ' );
104 end;
106 function DoesFoldersExists(Path:string; FolderNames:Tstrings): boolean;
108 loop:integer;
109 begin
110 Result := true;
111 { Take a path and check to see if the listed folders exists in that path. }
112 { TODO : Add a way to check the result from each one and return it. }
113 for loop := 0 to ( FolderNames.Count - 1 ) do
114 begin
115 if DoesFolderExists(Path, FolderNames[loop]) = false then
116 begin
117 Result := false;
118 Exit;
119 end;
120 end;
121 end;
123 function DoesFolderExists(Path:string; FolderName:string): boolean;
125 ChannelLocal:string;
126 begin
127 ChannelLocal := 'DoesFolderExists';
128 if DirectoryExists(Path + FolderName) = true then
129 begin
130 Result := true ;
131 {$IFDEF MoreTrue }
132 UnitMain.form1.LogWithDebug(3, ChannelLocal, ('Folder' + Wrap(Path + FolderName) + 'exists.'));
133 {$ENDIF}
135 else
136 begin
137 Result := false ;
138 Log(4, ChannelLocal, ('Folder' + Wrap(Path + FolderName) + 'does not exists.'));
139 end;
140 end;
142 procedure Log(Level:integer;Channel:string;LogText:string);
144 LevelString:string;
145 AllFine:boolean;
146 begin
147 AllFine := true;
149 if AllFine = true then
150 begin
151 {Level 0 "Info"}
152 {Level 1 "Error"}
153 {Level 2 "Variable"}
154 {Level 3 "Dev-Info"}
155 {Level 4 "Dev-Error"}
156 {Level 5 is for uses with custom functions.}
157 if Level = 0 then
158 begin
159 LevelString := 'Info';
161 else
162 if Level = 1 then
163 begin
164 LevelString := 'Error';
166 else
167 if Level = 2 then
168 begin
169 LevelString := 'Variable';
171 else
172 if level = 3 then
173 begin
174 LevelString := 'Dev-Info';
176 else
177 if level = 4 then
178 begin
179 LevelString := 'Dev-Error';
181 else
182 if level = 5 then
183 begin
184 WriteLn(LogText);
185 UnitMain.form1.Memo_LogOutPut.Lines.Add(LogText);
186 Exit();
188 else
189 Exit();
192 { Out put }
193 if HideChannel = true then
194 begin
195 WriteLn(LevelString + ': ' + LogText);
196 UnitMain.form1.Memo_LogOutPut.Lines.Add(LevelString + ': ' + LogText);
198 else
199 begin
200 WriteLn(LevelString + ':' + Channel + ': ' + LogText);
201 UnitMain.form1.Memo_LogOutPut.Lines.Add(LevelString + ':' + Channel + ': ' + LogText);
202 end;
203 end;
206 end;
209 procedure SaveLastUsedConfig();
210 begin
211 if Loading = true then exit;
214 XmlLastUsedConfig.SetValue('Version', '2');
215 XmlLastUsedConfig.SetValue('WineVersionInfo/DistributionName', UnitMain.form1.ComboBox_DistributionName.Text );
216 XmlLastUsedConfig.SetValue('WineVersionInfo/DistributionVersion', UnitMain.form1.ComboBox_DistributionVersion.Text );
217 XmlLastUsedConfig.SetValue('WineVersionInfo/Architecture', UnitMain.form1.ComboBox_Architecture.Text );
218 XmlLastUsedConfig.SetValue('WineVersionInfo/WineVersion', UnitMain.form1.ComboBox_WineVersion.Text );
220 XmlLastUsedConfig.SetValue('WineVersionInfo/UsesTerminal', UnitMain.form1.Check_Terminal.Checked );
221 XmlLastUsedConfig.SetValue('WineVersionInfo/UsesSoundWrapper', UnitMain.form1.CheckBox_UseSoundWrapper.Checked );
223 { And Save }
224 XmlLastUsedConfig.Filename := ( ConfigPath + '/LastUsedConfig.xml' );
225 Finally
226 { Clean up }
227 XmlLastUsedConfig.Flush;
228 end;
229 end;
232 procedure LoadLastUsedConfig();
234 LastUsedConfigVersion:string;
235 begin
236 Loading := true;
237 XmlLastUsedConfig:= TXMLConfig.Create(nil);
240 XmlLastUsedConfig.Filename := ( ConfigPath + '/LastUsedConfig.xml' );
242 { Version of Settings }
243 LastUsedConfigVersion := XmlLastUsedConfig.GetValue('Version','');
244 {$IFDEF LogVar}
245 LogVar(LastUsedConfigVersion,'LastUsedConfigVersion');
246 {$ENDIF}
248 { Make sure we can read the file. }
249 if LastUsedConfigVersion = '-1' then
250 begin
251 Log(3, Channel, 'Invalided file version, Never mind we ignore it and wirte over it.');
252 Exit();
253 end;
255 UnitMain.form1.ComboBox_DistributionName.Text := XmlLastUsedConfig.GetValue('WineVersionInfo/DistributionName', '' );
256 UnitMain.form1.ComboBox_DistributionVersion.Text := XmlLastUsedConfig.GetValue('WineVersionInfo/DistributionVersion', '' );
257 UnitMain.form1.ComboBox_Architecture.Text := XmlLastUsedConfig.GetValue('WineVersionInfo/Architecture', '' );
258 UnitMain.form1.ComboBox_WineVersion.Text := XmlLastUsedConfig.GetValue('WineVersionInfo/WineVersion', '' );
260 UnitMain.form1.Check_Terminal.Checked := XmlLastUsedConfig.GetValue('WineVersionInfo/UsesTerminal', false );
261 UnitMain.form1.CheckBox_UseSoundWrapper.Checked := XmlLastUsedConfig.GetValue('WineVersionInfo/UsesSoundWrapper', false );
263 { Clean up }
264 Finally
265 XmlLastUsedConfig.Flush;
266 Loading := false;
267 end;
268 end;
271 function WinToUnixPath(Path:string):string;
273 PathUpToDosdevices:string;
274 DriveNameWithSlash:string;
275 FullUnixPath:string;
276 begin
277 {Get the path up to Dosdevices.}
278 PathUpToDosdevices := (GetEnvironmentVariable('HOME') + '/' + WineUserFolder + '/prefix/' + UnitMain.form1.ComboBox_PreFix.Text + '/dosdevices/' );
279 {Take the DriveName off 'path' and replace '\' with '/'.}
280 DriveNameWithSlash := (AnsiLowerCase( Copy2SymbDel( Path, '\' )) + '/');
281 {Replace all '\' to '/'.}
282 Path := AnsiReplaceText(Path, '\', '/');
283 {Sort then.}
284 FullUnixPath := (PathUpToDosdevices + DriveNameWithSlash + Path);
285 {$IFDEF LogVar}
286 {$IFDEF MOREDEBUG_WinToUnixPath}
287 logVar(PathUpToDosdevices, 'PathUpToDosdevices');
288 logVar(DriveNameWithSlash, 'DriveNameWithSlash');
289 logVar(Path, 'Path');
290 {$ENDIF}
291 logVar(FullUnixPath, 'FullUnixPath');
292 {$ENDIF}
293 Result := FullUnixPath;
295 end;
298 function UnixToWinPath(Path:string; DriveChar:Char):string;
300 WindowsFilePath :string;
301 SmallPath:string;
302 Cleanup:string;
303 begin
304 if Path = '' then
305 begin
306 Result := '';
307 exit;
308 end;
310 Path := AnsiReverseString(Path);
311 SmallPath := Copy2SymbDel(Path, ':');
312 SmallPath := AnsiReverseString(SmallPath);
313 Cleanup := AnsiReplaceText(SmallPath, '/', '\');
314 WindowsFilePath := (DriveChar + ':' + Cleanup);
316 {$IFDEF LogVar}
317 logVar(WindowsFilePath, 'WindowsFilePath');
318 {$ENDIF}
319 Result := WindowsFilePath;
320 end;
323 function GetUnixDirPath(FilePath:string):string;
325 DirPath:string;
326 //LocalChannel:string;
327 begin
328 DirPath := LeftStr(FilePath, (Rpos('/',FilePath) ));
329 //log(0, LocalChannel, ( 'VAR ' + DirPath));
331 Result := DirPath;
332 end;
334 function WorkDirTemplate(FolderPath:string):string;
335 begin
336 Result := ('cd "' + FolderPath + '";' + #10 );
337 end;
339 {$IFDEF LogVar}
340 procedure LogVar(MyVar: string; MyVarName: string);
341 begin
342 Log(2, 'LogVar', ( Wrap( MyVarName ) + 'is' + Wrap( MyVar )) );
343 end;
344 {$ENDIF}
346 function CheckPaths():boolean;
347 begin
349 Result := true;
351 if DirExistsIfNotMakeIt(GetEnvironmentVariable('HOME'), '/.config') <> true then
352 begin
353 Result := false;
354 end;
356 if DirExistsIfNotMakeIt(ConfigPath) <> true then
357 begin
358 Result := false;
359 end;
362 if DirExistsIfNotMakeIt(GetEnvironmentVariable('HOME') + '/' , WineUserFolder) = false then
363 begin
364 Result := false;
365 end;
367 if DirExistsIfNotMakeIt(GetEnvironmentVariable('HOME') + '/' + WineUserFolder + '/', 'prefix') = false then
368 begin
371 else
372 begin
373 if DoesFolderExists(GetEnvironmentVariable('HOME') + '/' + WineUserFolder + '/', 'git') = false then
374 begin
375 SetupGit();
376 end;
377 end;
380 if DirExistsIfNotMakeIt(GetEnvironmentVariable('HOME') + '/' + WineUserFolder + '/', 'wine') = false then
381 begin
382 Result := false;
383 end;
388 end;
391 function SetupGit():boolean;
393 Process:TProcess;
394 script:string;
395 RunYes:boolean;
396 ChannelLocal:string;
397 Terminal:string;
398 begin
399 Process := TProcess.Create(nil);
400 RunYes := true ;
401 ChannelLocal := 'SetupGit';
403 script := '#! /bin/sh' +{linebrake}#10 +
404 'echo This script will fetch Wine and compile it. ;'+{linebrake}#10 +
405 'echo If it fails please install the dependencies and rerun WineLauncher, see http://wiki.winehq.org/Recommended_Packages for more help.' +{linebrake}#10 +
406 'cd ' + GetEnvironmentVariable('HOME') + '/' + WineUserFolder + ' ;' +{linebrake}#10 +
407 'git clone git://source.winehq.org/git/wine.git git ;' +{linebrake}#10 +
408 'cd ./git ;' +{linebrake}#10 +
409 'git checkout -b stable-1.0.1 wine-1.0.1 ;' +{linebrake}#10 +
410 'Dname=`lsb_release -si` ;' +{linebrake}#10 +
411 'Dversion=`lsb_release -sr` ;' +{linebrake}#10 +
412 'Aname=`uname -m` ;' +{linebrake}#10 +
413 './configure --prefix=' + GetEnvironmentVariable('HOME') + '/' + WineUserFolder + '/wine/$Dname/$Dversion/$Aname/stable-1.0.1 ;' +{linebrake}#10 +
414 'make ;' +{linebrake}#10 +
415 'make install;' +{linebrake}#10 +
416 GetEnvironmentVariable('HOME') + '/' + WineUserFolder + '/wine/$Dname/$Dversion/$Aname/stable-1.0.1/bin/wineprefixcreate --prefix "' + GetEnvironmentVariable('HOME') + '/' + WineUserFolder + '/prefix/default/"' +{linebrake}#10 ;
418 {Create Script file}
419 if MakeFile((ConfigPath + '/SetupGit'),script) = true then
420 begin
422 {Set executable flag}
423 if SetExecutableFlag(ConfigPath + '/SetupGit') = false then
424 begin
425 RunYes := False ;
426 end;
428 if FileExistsAndIsExecutable('/usr/bin/gnome-terminal',false) = true then
429 begin
430 Terminal := 'gnome-terminal -x ';
432 else
433 begin
434 if FileExistsAndIsExecutable('/usr/bin/gnome-terminal',false) = true then
435 begin
436 Terminal := '/usr/bin/konsole -x ';
438 else
439 if FileExistsAndIsExecutable('/usr/bin/gnome-terminal',false) = true then
440 begin
441 Terminal := '/usr/bin/xterm ';
442 end;
443 end;
445 {Execute script one}
446 if RunYes = true then
447 begin
448 Log(0, ChannelLocal, 'Script One has being executed.');
449 Process.CommandLine := Terminal + ConfigPath +'/SetupGit';
450 Process.Execute;
451 end;
453 while Process.Running = true do
454 begin
455 sleep(5000);
456 end;
458 Result := Process.WaitOnExit;
460 end;
463 end;
465 function DirExistsIfNotMakeIt(Path:string; FolderName:string ): boolean;
467 LocalChannel:string; {Ignore this for now}
468 begin
469 LocalChannel := '';
471 if FolderName <> '' then
472 begin
473 if DirectoryExists( Path + FolderName ) = true then
474 begin
475 Log(0, LocalChannel, ('Directory' + Wrap( Path + FolderName ) + 'exists.')) ;
476 Result := true;
478 else
479 begin
480 Log(0, LocalChannel, ('Directory' + Wrap( Path + FolderName ) + ' does not exists.')) ;
481 if CreateDir( Path + FolderName ) then
482 begin
483 Log(0, LocalChannel, ('File' + Wrap( Path + FolderName ) + 'has being created.')) ;
484 Result := true;
486 else
487 begin
488 Log(0, LocalChannel, ('File' + Wrap( Path + FolderName ) + 'can not be created.')) ;
489 Result := true;
490 end;
491 end;
494 else
495 begin
496 Result := false;
497 end;
498 end;
500 function DirExistsIfNotMakeIt(PathWithFolder:string): boolean;
502 FolderPath:string;
503 FolderName:string;
504 begin
505 {E.G. PathWithFolder := '/home/test/hello/'.}
507 {If PathWithfolder has '/' at the end remove it.}
508 RemoveTrailingChars(PathWithFolder,['/']);
510 {FolderName := 'hello'.}
511 FolderName := ExtractFileName(PathWithFolder);
513 {FolderPath := '/home/test/'.}
514 FolderPath := ExtractFilePath(PathWithFolder);
516 {$IFDEF LogVar}
517 logVar(FolderName, 'FolderName');
518 logVar(FolderPath, 'FolderPath');
519 {$ENDIF}
521 {Pass the data to real function and get the result back.}
522 if DirExistsIfNotMakeIt(FolderPath, FolderName) = true then Result := true else Result := false;
523 end;
525 function MakeFile(FullPath:string;Data:string):boolean;
527 FD1:Cint;
528 CL:string;
529 begin
530 CL := 'MakeFile';
531 FpUnlink(FullPath);
533 FD1 := fpOpen (FullPath, O_WrOnly or O_Creat);
534 if FD1 > 0 then
535 begin
536 if length(Data)<>fpwrite (FD1,Data[1],Length(Data)) then
537 begin
538 Result := False ;
539 Log(1, CL, ('When writing to' + Wrap(FullPath)) );
541 else
542 begin
543 {$IFDEF MoreTrue }
544 Log(3, CL, ('File' + Wrap(FullPath) + 'has being created'));
545 {$ENDIF}
546 Result := true;
547 end;
548 fpClose(FD1);
549 end;
550 end;
552 function SetExecutableFlag(FullPath:string):boolean;
554 ChannelLocal:string;
555 begin
556 {770 is owner rwx, group rwx, other nothing}
557 if fpChmod (FullPath,&770) <> 0 then {0 = no error}
558 begin
559 Log(1, ChannelLocal, ('Can not set executable flag on' + Wrap(FullPath)) );
560 Result := False;
562 else
563 begin
564 {$IFDEF MoreTrue }
565 Log(0, ChannelLocal, ('Executable flag has being set on' + Wrap(FullPath)) );
566 {$ENDIF}
567 Result := true;
568 end;
569 end;
572 function ListProgramsOnDisc(ModeMe:TStrings; DriveChar:char):boolean;
574 Process:TProcess;
575 TempList:Tstrings;
576 script:string;
577 Path:string;
578 Stop:boolean;
579 Info : TSearchRec;
580 Count : Longint;
581 Running:boolean;
582 begin
583 Path := (GetEnvironmentVariable('HOME') +'/'+ WineUserFolder + '/prefix/' + UnitMain.Form1.ComboBox_PreFix.Text + '/dosdevices/' + AnsiLowerCase(DriveChar));
585 if OldPath <> Path then
586 begin
587 if AsyncProcessScan.Active = false then
588 begin
589 Stop := false;
590 OldPath := Path;
591 ModeMe.Clear;
592 LastReadLinkPath := fpReadLink(Path + ':');
594 if LastReadLinkPath = '' then
595 begin
596 Stop := true;
597 Result := False;
598 log(4, '',('Link ' + Wrap(Path + ':') + 'does not exists.'));
599 LastReadLinkPath := '';
600 DiscErrorText := 'Please map' + wrap(DriveChar + ':') + 'to your cd / dvd drive, You can do that in winecfg.';
601 end;
603 if Stop = false then
604 begin
605 Count := 0;
606 If FindFirst(Path + ':/*',faAnyFile and faDirectory,Info)=0 then
607 begin
608 Repeat
609 Inc(Count);
610 Until FindNext(info)<>0;
611 if Count < 3 then
612 begin
613 log(0,'', Info.Name);
614 DiscErrorText := 'You have no disc in your drive.';
615 Stop := true;
616 Result := False;
617 LastReadLinkPath := '';
618 end;
619 end;
620 FindClose(Info);
621 end;
623 if Stop = false then
624 begin
625 if LastReadLinkPath = '/' then
626 begin
627 DiscErrorText := 'You can not map '+ DriveChar + ': to root.';
628 Stop := true;
629 Result := False;
630 LastReadLinkPath := '';
631 end;
632 end;
634 if Stop = false then
635 begin
636 if LastReadLinkPath = GetEnvironmentVariable('HOME') then
637 begin
638 DiscErrorText := 'You can not map '+ DriveChar + ': to your home folder.';
639 Stop := true;
640 Result := False;
641 LastReadLinkPath := '';
642 end;
643 end;
646 if Stop = false then
647 begin
648 script := '/usr/bin/find -H ' + Path + ': -iname *.exe';
649 Log(0, '', 'Script Scan has being executed.');
650 AsyncProcessScan.CommandLine := script;
651 AsyncProcessScan.Execute;
652 DiscErrorText := 'Scaning';
653 Timer.Enabled := true;
654 end;
656 end;
657 end;
658 end;
661 function ColourCheck(Input: TEdit):boolean;
663 LocalChannel:string;
664 temp:string;
665 begin
666 LocalChannel := 'ColourCheck';
667 {This does a CaseInsensitive check to see if the file exists. Wine does not care about the executable flag. }
668 {I can not find FindDiskFileCaseInsensitive in the doc.}
669 {If it can not find the file it will return nothing and it will clear the string.}
670 temp := WinToUnixPath(Input.Text);
672 if FindDiskFileCaseInsensitive(temp) <> '' then
673 begin
674 {$IFDEF MoreTrue}Log(3, LocalChannel, 'File' + Wrap(temp) + 'exists.');{$ENDIF}
675 Input.Font.Color := clgreen;
676 Result := true;
678 else
679 begin
680 Log(4, LocalChannel,'File' + Wrap(Input.Text) + 'does not exists.');
681 Input.Font.Color := clred;
682 Result := false;
683 end;
684 end;
687 procedure RunWineCheck(ProgramNameOverRide:string; ProgramFlagsOverRide:string);
689 RunYes:Boolean;
690 loop:integer;
691 SoundWrapper:string;
692 temp00:integer;
693 WinePreFixRaw:string;
694 WinePreFix:string;
695 ChannelLocal:string;
696 ProgramFlags:string;
697 ProgramName:string;
698 ProgramDir:string;
699 WorkDir:string;
700 UnixPathWithOutFile:string;
701 begin
702 ChannelLocal := ('RunWineCheck');
703 RunYes := true ;
705 {Get wine version info}
706 if RunYes = true then
707 begin
708 {Check for wine in root}
709 if FileExistsAndIsExecutable( {FullPath:string} WinePath + '/wine', {JustCheckExists:boolean}false) = true then
710 begin
711 wine_version_full := (WinePath + '/wine');
712 {$IFDEF LogVar}
713 LogVar(wine_version_full,'wine_version_full');
714 {$ENDIF}
716 else
717 {Check for wine in "/bin/wine"}
718 if FileExistsAndIsExecutable( {FullPath:string} WinePath + '/bin/wine', {JustCheckExists:boolean}false) = true then
719 begin
720 wine_version_full := (WinePath + '/bin/wine');
721 {$IFDEF LogVar}
722 LogVar(wine_version_full,'wine_version_full');
723 {$ENDIF}
725 else
726 begin
727 {Error Can not find wine}
728 Log(0, ChannelLocal, 'Can not find wine');
729 RunYes := false;
730 end;
731 end;
733 {Get Terminal info}
734 if RunYes = true then
735 begin
736 if UnitMain.form1.Check_Terminal.Checked = true then
737 begin
738 if UnitMain.form1.ComboBox_TerminalName.Text <> '' then
739 begin
740 temp00 := UnitMain.form1.ComboBox_TerminalName.ItemIndex;
741 RunIn := ( UnitSettings.Form4.StringGrid_TerminalSettings.Cells[1,temp00] + ' ' + UnitSettings.Form4.StringGrid_TerminalSettings.Cells[2,temp00] );
742 Log(0, ChannelLocal, ('Using Terminal' + Wrap( RunIn )) );
743 end;
745 else
746 begin
747 { TODO : After the TempProgram is closed the child process is still listed. }
748 RunIn := UnitSettings.Form4.ComboBox_ShellPath.text;
749 Log(0, ChannelLocal, ('Using' + Wrap( RunIn )) );
750 end;
752 end;
755 {PreFix}
756 if RunYes = true then
757 begin
758 WinePreFixRaw := (PreFixList[1].Strings[UnitMain.form1.ComboBox_PreFix.ItemIndex]);
759 WinePreFix := ('env WINEPREFIX="' + WinePreFixRaw + '"');
760 {$IFDEF LogVar}
761 LogVar(WinePreFix,'WinePreFix');
762 {$ENDIF}
763 end;
765 {Sound Wrapper}
766 if RunYes = true then
767 begin
768 if UnitMain.form1.CheckBox_UseSoundWrapper.Checked = true then
769 begin
770 if FileExists( UnitMain.form1.ComboBox_SoundWrapper.Text ) = true then
771 begin
772 SoundWrapper := UnitMain.form1.ComboBox_SoundWrapper.Text + ' ' ;
773 Log(0, ChannelLocal, ( 'File' + Wrap( UnitMain.form1.ComboBox_SoundWrapper.Text ) + 'exists'));
775 else
776 begin
777 RunYes := false ;
778 Log(1, ChannelLocal, ( 'File' + Wrap( UnitMain.form1.ComboBox_SoundWrapper.Text ) + 'does not exists'));
779 end;
781 else
782 begin
783 Log(0, ChannelLocal, ('No sound wrapper will be used'));
784 end;
785 end;
787 if ProgramNameOverRide = '' then
788 begin
789 if RunYes = true then
790 begin
791 if UnitMain.form1.EditBox_ProgramPath.Text <> '' then
792 begin
793 ProgramFlags := '';
794 for loop := 0 to ( UnitMain.form1.CheckListBox_Flags.Items.Count ) do
795 begin
796 if UnitMain.form1.CheckListBox_Flags.Checked[loop] = true then
797 begin
798 ProgramFlags := ( ProgramFlags + ' ' + UnitMain.form1.CheckListBox_Flags.Items.ValueFromIndex[loop] );
800 end;
801 end;
802 {$IFDEF LogVar}
803 LogVar(ProgramFlags,'ProgramFlags' );
804 {$ENDIF}
805 ProgramName := ( ' ' + '"' + UnitMain.form1.EditBox_ProgramPath.Text + '"' + ProgramFlags + ' ' );
807 else
808 begin
809 RunYes := False;
810 Log(1, ChannelLocal, ('Please select a program.'));
811 end;
812 end;
815 else
816 begin
817 ProgramName := ( ' ' + '"' + ProgramNameOverRide + '"' + ProgramFlagsOverRide + ' ' );
818 end;
820 {Set the WorkDir}
821 if RunYes = true then
822 begin
823 UnixPathWithOutFile := ExtractFilePath(WinToUnixPath(UnitMain.form1.EditBox_ProgramPath.Text));
824 if ProgramNameOverRide = '' then
825 begin
826 if DoesFolderExists(ExtractFilePath(UnixPathWithOutFile), ExtractFileName(UnixPathWithOutFile)) then
827 begin
828 WorkDir := WorkDirTemplate( GetUnixDirPath(WinToUnixPath(UnitMain.form1.EditBox_ProgramPath.Text)) );
829 end {DoesFolderExists}
830 else
831 begin
832 WorkDir := WorkDirTemplate(WinePreFixRaw + '/dosdevices/c:/windows');
833 end; {DoesFolderExists}
834 end {ProgramNameOverRide}
835 else
836 begin
837 WorkDir := WorkDirTemplate(WinePreFixRaw + '/dosdevices/c:/windows');
838 end; {ProgramNameOverRide}
839 end;
841 {Settup start_S1}
842 if RunYes = true then
843 begin
844 start_S1 := '#! /bin/sh' + {linebrake}#10 + WorkDir {linebrake} + WinePreFix + SoundWrapper + ' ' + wine_version_full + ' ' + ProgramName + ';' ;
845 {$IFDEF LogVar}
846 LogVar(start_S1,'start_S1');
847 {$ENDIF}
848 end;
850 {Create Script file}
851 if RunYes = true then
852 begin
853 if MakeFile((ConfigPath + '/1'),start_S1) = false then
854 begin
855 RunYes := False ;
856 end;
858 {Set executable flag}
859 if RunYes = true then
860 begin
861 if SetExecutableFlag(ConfigPath + '/1') = false then
862 begin
863 RunYes := false;
864 end;
865 end;
867 {Execute script one}
868 if RunYes = true then
869 begin
870 Log(0, ChannelLocal, ('Script One has being executed.'));
871 AProcess.CommandLine := RunIn + ' ' + ConfigPath +'/1';
872 { TODO : After the TempProgram is closed the child process is still listed. }
873 AProcess.Execute;
875 else
876 begin
877 Log(1, ChannelLocal, ('Somethings Wrong, check your log'));
878 end;
879 end;
880 end;
882 function CutUpFlags(Flags:string):boolean;
884 Loop:integer;
885 Dump:integer;
886 Temp:string;
887 begin
888 UnitMain.form1.CheckListBox_Flags.Items.Clear;
890 for loop := 0 to ( WordCount( Flags, [';'] ) ) do
891 begin
892 Dump := FindPart( ';', Flags );
893 Temp := LeftStr( Flags, Dump - 1);
894 if Temp <> '' then UnitMain.form1.CheckListBox_Flags.Items.Add(Temp);
895 Delete(Flags, 1, (Dump)) ;
896 end;
897 if Flags <> '' then UnitMain.form1.CheckListBox_Flags.Items.Add(Flags);
899 end;
901 end.