From a0ff0b75e3562e04f17f11fc41f2e49040d620c5 Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Thu, 8 Nov 2007 21:02:07 +0000 Subject: Added UPlatform.pas. This should be the first step to move the simple platform specific code to one file for each platform to reduce the IFDEFs in the remaining files. The first available function is a unicode capable DirectoryFindFiles. It is now used in the BrowseDir function in file USongs.pas. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@595 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UPlatformMacOSX.pas | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Game/Code/Classes/UPlatformMacOSX.pas (limited to 'Game/Code/Classes/UPlatformMacOSX.pas') diff --git a/Game/Code/Classes/UPlatformMacOSX.pas b/Game/Code/Classes/UPlatformMacOSX.pas new file mode 100644 index 00000000..56469299 --- /dev/null +++ b/Game/Code/Classes/UPlatformMacOSX.pas @@ -0,0 +1,66 @@ +unit UPlatformMacOSX; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +{$I switches.inc} + +uses Classes, UPlatform; + +type + + TPlatform = class(TInterfacedObject, IPlatform) + public + Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; + end; + +implementation + +uses SysUtils, baseunix; + +Function TPlatform.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; +var + i : Integer; + TheDir : pdir; + ADirent : pDirent; + Entry : Longint; + info : stat; + lAttrib : integer; +begin + i := 0; + Filter := LowerCase(Filter); + + TheDir := FPOpenDir(Dir); + if Assigned(TheDir) then + repeat + ADirent := FPReadDir(TheDir); + + If Assigned(ADirent) and (ADirent^.d_name <> '.') and (ADirent^.d_name <> '..') then + begin + lAttrib := FileGetAttr(Dir + ADirent^.d_name); + if ReturnAllSubDirs and ((lAttrib and faDirectory) <> 0) then + begin + SetLength( Result, i + 1); + Result[i].Name := ADirent^.d_name; + Result[i].IsDirectory := true; + Result[i].IsFile := false; + i := i + 1; + end + else if (Length(Filter) = 0) or (Pos( Filter, LowerCase(ADirent^.d_name)) > 0) then + begin + SetLength( Result, i + 1); + Result[i].Name := ADirent^.d_name; + Result[i].IsDirectory := false; + Result[i].IsFile := true; + i := i + 1; + end; + end; + Until ADirent = nil; + + FPCloseDir(TheDir); +end; + +end. -- cgit v1.2.3 From ce484ce148d1db51ddb3cda575786f0871843cb3 Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Tue, 20 Nov 2007 21:02:37 +0000 Subject: Changed Platform from Interface to Class. Added TerminateIfAlreadyRunning and GetGamePath to UPlatform.pas. Fixed a bug in THookManager.Create ("SpacetoAllocate-1"). git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@617 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UPlatformMacOSX.pas | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'Game/Code/Classes/UPlatformMacOSX.pas') diff --git a/Game/Code/Classes/UPlatformMacOSX.pas b/Game/Code/Classes/UPlatformMacOSX.pas index 56469299..4e0c9061 100644 --- a/Game/Code/Classes/UPlatformMacOSX.pas +++ b/Game/Code/Classes/UPlatformMacOSX.pas @@ -12,16 +12,36 @@ uses Classes, UPlatform; type - TPlatform = class(TInterfacedObject, IPlatform) + TPlatformMacOSX = class(TPlatform) + private public - Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; + Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; override; + function GetGamePath: WideString; override; end; implementation uses SysUtils, baseunix; -Function TPlatform.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; +// Mac applications are packaged in directories. +// We have to cut the last two directories +// to get the application directory. +Function TPlatformMacOSX.GetGamePath : WideString; +var + x, + i : integer; +begin + Result := ExtractFilePath(ParamStr(0)); + for x := 0 to 2 do begin + i := Length(Result); + repeat + Delete( Result, i, 1); + i := Length(Result); + until (i = 0) or (Result[i] = '/'); + end; +end; + +Function TPlatformMacOSX.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; var i : Integer; TheDir : pdir; -- cgit v1.2.3 From 49d52afc94a97f808adc246247989244ef2071ff Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Wed, 9 Jan 2008 21:05:38 +0000 Subject: Added the new GetxxxxPath functions for OS X. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@764 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UPlatformMacOSX.pas | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'Game/Code/Classes/UPlatformMacOSX.pas') diff --git a/Game/Code/Classes/UPlatformMacOSX.pas b/Game/Code/Classes/UPlatformMacOSX.pas index 4e0c9061..ff369049 100644 --- a/Game/Code/Classes/UPlatformMacOSX.pas +++ b/Game/Code/Classes/UPlatformMacOSX.pas @@ -16,7 +16,9 @@ type private public Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; override; - function GetGamePath: WideString; override; + function GetLogPath : WideString; override; + function GetGameSharedPath : WideString; override; + function GetGameUserPath : WideString; override; end; implementation @@ -26,7 +28,7 @@ uses SysUtils, baseunix; // Mac applications are packaged in directories. // We have to cut the last two directories // to get the application directory. -Function TPlatformMacOSX.GetGamePath : WideString; +Function GetBundlePath : WideString; var x, i : integer; @@ -41,6 +43,21 @@ begin end; end; +function TPlatformMacOSX.GetLogPath : WideString; +begin + Result := GetBundlePath; +end; + +function TPlatformMacOSX.GetGameSharedPath : WideString; +begin + Result := GetBundlePath; +end; + +function TPlatformMacOSX.GetGameUserPath : WideString; +begin + Result := GetBundlePath; +end; + Function TPlatformMacOSX.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; var i : Integer; -- cgit v1.2.3 From 31195a7ab6e264d325a589b1dd6673d6ba3d0e5a Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Wed, 9 Jan 2008 22:29:28 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@770 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UPlatformMacOSX.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Game/Code/Classes/UPlatformMacOSX.pas') diff --git a/Game/Code/Classes/UPlatformMacOSX.pas b/Game/Code/Classes/UPlatformMacOSX.pas index ff369049..a418919c 100644 --- a/Game/Code/Classes/UPlatformMacOSX.pas +++ b/Game/Code/Classes/UPlatformMacOSX.pas @@ -15,7 +15,7 @@ type TPlatformMacOSX = class(TPlatform) private public - Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; override; + function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; override; function GetLogPath : WideString; override; function GetGameSharedPath : WideString; override; function GetGameUserPath : WideString; override; -- cgit v1.2.3 From e74bd57c12f470257111c1c0530fb38f0fd34414 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Sat, 12 Jan 2008 12:31:43 +0000 Subject: bunch of smaller changes... some changes to song loading... Record global changed to singleton object started implementing mic volume display in Settings-Record hope this dosnt break anything.. :P git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@789 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UPlatformMacOSX.pas | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'Game/Code/Classes/UPlatformMacOSX.pas') diff --git a/Game/Code/Classes/UPlatformMacOSX.pas b/Game/Code/Classes/UPlatformMacOSX.pas index a418919c..97c32fe3 100644 --- a/Game/Code/Classes/UPlatformMacOSX.pas +++ b/Game/Code/Classes/UPlatformMacOSX.pas @@ -12,13 +12,20 @@ uses Classes, UPlatform; type - TPlatformMacOSX = class(TPlatform) + TPlatformMacOSX = class( TInterfacedObject, IPlatform) private public +<<<<<<< .mine + Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; override; + function GetGamePath: WideString; override; + function TerminateIfAlreadyRunning(var WndTitle : String) : Boolean; + procedure halt(); +======= function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; override; function GetLogPath : WideString; override; function GetGameSharedPath : WideString; override; function GetGameUserPath : WideString; override; +>>>>>>> .r788 end; implementation @@ -100,4 +107,15 @@ begin FPCloseDir(TheDir); end; +function TPlatformMacOSX.TerminateIfAlreadyRunning(var WndTitle : String) : Boolean; +begin + result := false; +end; + + +procedure TPlatformMacOSX.halt; +begin + halt; +end; + end. -- cgit v1.2.3 From ceae3d4f3b8d1697ec345787b35064f96fc67e14 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Sat, 12 Jan 2008 12:49:16 +0000 Subject: oops... :) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@791 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UPlatformMacOSX.pas | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'Game/Code/Classes/UPlatformMacOSX.pas') diff --git a/Game/Code/Classes/UPlatformMacOSX.pas b/Game/Code/Classes/UPlatformMacOSX.pas index 97c32fe3..30a2ab47 100644 --- a/Game/Code/Classes/UPlatformMacOSX.pas +++ b/Game/Code/Classes/UPlatformMacOSX.pas @@ -15,17 +15,13 @@ type TPlatformMacOSX = class( TInterfacedObject, IPlatform) private public -<<<<<<< .mine Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; override; function GetGamePath: WideString; override; function TerminateIfAlreadyRunning(var WndTitle : String) : Boolean; procedure halt(); -======= - function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; override; - function GetLogPath : WideString; override; - function GetGameSharedPath : WideString; override; - function GetGameUserPath : WideString; override; ->>>>>>> .r788 + function GetLogPath : WideString; override; + function GetGameSharedPath : WideString; override; + function GetGameUserPath : WideString; override; end; implementation @@ -52,6 +48,7 @@ end; function TPlatformMacOSX.GetLogPath : WideString; begin + // surly logs go in /var/log/ ??? Result := GetBundlePath; end; @@ -62,6 +59,8 @@ end; function TPlatformMacOSX.GetGameUserPath : WideString; begin + // is there no user profile ??? + // like ... /home/user/ that could be used for song locations etc ?? Result := GetBundlePath; end; -- cgit v1.2.3 From fc31e84fe89000bee337983d933539794c7552fd Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Sun, 20 Jan 2008 16:27:17 +0000 Subject: Fixed compilation on the mac. At the moment the project doesn't link on the mac. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@798 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UPlatformMacOSX.pas | 48 +++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'Game/Code/Classes/UPlatformMacOSX.pas') diff --git a/Game/Code/Classes/UPlatformMacOSX.pas b/Game/Code/Classes/UPlatformMacOSX.pas index 30a2ab47..7b081607 100644 --- a/Game/Code/Classes/UPlatformMacOSX.pas +++ b/Game/Code/Classes/UPlatformMacOSX.pas @@ -1,5 +1,18 @@ unit UPlatformMacOSX; +// Note on directories (by eddie): +// We use subfolders of the application directory on tha mac, because: +// 1. Installation on the mac works as follows: Extract and copy an application +// and if you don't like or need the application anymore you move the folder +// to the trash - and you're done. +// 2. If we would use subfolders of the home directory we would have to spread our +// files to many directories - these directories are defined by Apple, but the +// average user doesn't know them, beacuse he or she doesn't need to know them. +// But for UltraStar the user must at least know the songs directory... +// +// Creating a subfolder directly under the home directory is not acceptable. +// + interface {$IFDEF FPC} @@ -13,15 +26,14 @@ uses Classes, UPlatform; type TPlatformMacOSX = class( TInterfacedObject, IPlatform) - private public - Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; override; - function GetGamePath: WideString; override; + Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; function TerminateIfAlreadyRunning(var WndTitle : String) : Boolean; procedure halt(); - function GetLogPath : WideString; override; - function GetGameSharedPath : WideString; override; - function GetGameUserPath : WideString; override; + function GetLogPath : WideString; + function GetGameSharedPath : WideString; + function GetGameUserPath : WideString; + function FindSongFile(Dir, Mask: widestring): widestring; end; implementation @@ -48,19 +60,19 @@ end; function TPlatformMacOSX.GetLogPath : WideString; begin - // surly logs go in /var/log/ ??? - Result := GetBundlePath; + // eddie: Please read the note at the top of this file, why we use the application directory and not the user directory. + Result := GetBundlePath + '/Logs'; end; function TPlatformMacOSX.GetGameSharedPath : WideString; begin + // eddie: Please read the note at the top of this file, why we use the application directory and not the user directory. Result := GetBundlePath; end; function TPlatformMacOSX.GetGameUserPath : WideString; begin - // is there no user profile ??? - // like ... /home/user/ that could be used for song locations etc ?? + // eddie: Please read the note at the top of this file, why we use the application directory and not the user directory. Result := GetBundlePath; end; @@ -69,8 +81,6 @@ var i : Integer; TheDir : pdir; ADirent : pDirent; - Entry : Longint; - info : stat; lAttrib : integer; begin i := 0; @@ -108,7 +118,7 @@ end; function TPlatformMacOSX.TerminateIfAlreadyRunning(var WndTitle : String) : Boolean; begin - result := false; + result := false; end; @@ -117,4 +127,16 @@ begin halt; end; +function TPlatformMacOSX.FindSongFile(Dir, Mask: widestring): widestring; +var + SR: TSearchRec; // for parsing song directory +begin + Result := ''; + if SysUtils.FindFirst(Dir + Mask, faDirectory, SR) = 0 then begin + Result := SR.Name; + end; // if + SysUtils.FindClose(SR); +end; + + end. -- cgit v1.2.3