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/UPlatformWindows.pas | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Game/Code/Classes/UPlatformWindows.pas (limited to 'Game/Code/Classes/UPlatformWindows.pas') diff --git a/Game/Code/Classes/UPlatformWindows.pas b/Game/Code/Classes/UPlatformWindows.pas new file mode 100644 index 00000000..eb432335 --- /dev/null +++ b/Game/Code/Classes/UPlatformWindows.pas @@ -0,0 +1,58 @@ +unit UPlatformWindows; + +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, Windows; + +Function TPlatform.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; +var + i : Integer; + SR : TSearchRecW; +begin + i := 0; + Filter := LowerCase(Filter); + + if ReturnAllSubDirs then begin + if FindFirstW(Dir + '*', faDirectory, SR) = 0 then + repeat + if (SR.Name <> '.') and (SR.Name <> '..') then + begin + SetLength( Result, i + 1); + Result[i].Name := SR.Name; + Result[i].IsDirectory := true; + Result[i].IsFile := false; + i := i + 1; + end; + until FindNextW(SR) <> 0; + FindCloseW(SR); + end; + + if FindFirstW(Dir + '*' + Filter, 0, SR) = 0 then + repeat + SetLength( Result, i + 1); + Result[i].Name := SR.Name; + Result[i].IsDirectory := true; + Result[i].IsFile := false; + i := i + 1; + until FindNextW(SR) <> 0; + FindCloseW(SR); +end; + +end. -- cgit v1.2.3 From d2254ffc1eb4bfe47ee68311eea21892b1bcc5d9 Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Thu, 8 Nov 2007 21:09:23 +0000 Subject: Added missing functions. I Hope this fixes the build on Windows. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@596 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UPlatformWindows.pas | 70 ++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'Game/Code/Classes/UPlatformWindows.pas') diff --git a/Game/Code/Classes/UPlatformWindows.pas b/Game/Code/Classes/UPlatformWindows.pas index eb432335..c7965761 100644 --- a/Game/Code/Classes/UPlatformWindows.pas +++ b/Game/Code/Classes/UPlatformWindows.pas @@ -11,6 +11,16 @@ interface uses Classes, UPlatform; type + + TSearchRecW = record + Time: Integer; + Size: Integer; + Attr: Integer; + Name: WideString; + ExcludeAttr: Integer; + FindHandle: THandle; + FindData: TWin32FindDataW; + end; TPlatform = class(TInterfacedObject, IPlatform) public @@ -21,6 +31,66 @@ implementation uses SysUtils, Windows; +function FindFirstW(const Path: widestring; Attr: Integer; var F: TSearchRecW): Integer; +const + faSpecial = faHidden or faSysFile or faVolumeID or faDirectory; +begin + F.ExcludeAttr := not Attr and faSpecial; + F.FindHandle := FindFirstFileW(PWideChar(Path), F.FindData); + if F.FindHandle <> INVALID_HANDLE_VALUE then + begin + Result := FindMatchingFileW(F); + if Result <> 0 then FindCloseW(F); + end else + Result := GetLastError; +end; + +function FindNextW(var F: TSearchRecW): Integer; +begin + if FindNextFileW(F.FindHandle, F.FindData) then + Result := FindMatchingFileW(F) + else + Result := GetLastError; +end; + +procedure FindCloseW(var F: TSearchRecW); +begin + if F.FindHandle <> INVALID_HANDLE_VALUE then + begin + Windows.FindClose(F.FindHandle); + F.FindHandle := INVALID_HANDLE_VALUE; + end; +end; + +function FindMatchingFileW(var F: TSearchRecW): Integer; +var + LocalFileTime: TFileTime; +begin + with F do + begin + while FindData.dwFileAttributes and ExcludeAttr <> 0 do + if not FindNextFileW(FindHandle, FindData) then + begin + Result := GetLastError; + Exit; + end; + FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime); + FileTimeToDosDateTime(LocalFileTime, LongRec(Time).Hi, LongRec(Time).Lo); + Size := FindData.nFileSizeLow; + Attr := FindData.dwFileAttributes; + Name := FindData.cFileName; + end; + Result := 0; +end; + +function DirectoryExistsW(const Directory: widestring): Boolean; +var + Code: Integer; +begin + Code := GetFileAttributesW(PWideChar(Directory)); + Result := (Code <> -1) and (FILE_ATTRIBUTE_DIRECTORY and Code <> 0); +end; + Function TPlatform.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; var i : Integer; -- cgit v1.2.3 From b2a203f519a2a4d13ffdad2cedb9fcfa2d07db8b Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Thu, 8 Nov 2007 21:21:20 +0000 Subject: Move the TSearchRecW record to the implementation part. This should fix the compilation error. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@598 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UPlatformWindows.pas | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'Game/Code/Classes/UPlatformWindows.pas') diff --git a/Game/Code/Classes/UPlatformWindows.pas b/Game/Code/Classes/UPlatformWindows.pas index c7965761..1786d6cc 100644 --- a/Game/Code/Classes/UPlatformWindows.pas +++ b/Game/Code/Classes/UPlatformWindows.pas @@ -10,6 +10,17 @@ interface uses Classes, UPlatform; +type + + TPlatform = class(TInterfacedObject, IPlatform) + public + Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; + end; + +implementation + +uses SysUtils, Windows; + type TSearchRecW = record @@ -22,14 +33,6 @@ type FindData: TWin32FindDataW; end; - TPlatform = class(TInterfacedObject, IPlatform) - public - Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; - end; - -implementation - -uses SysUtils, Windows; function FindFirstW(const Path: widestring; Attr: Integer; var F: TSearchRecW): Integer; const -- cgit v1.2.3 From e83126a1e93f274c32e4a243f93d1dc2bcb63c44 Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Thu, 8 Nov 2007 21:25:57 +0000 Subject: Added forward declarations... git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@599 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UPlatformWindows.pas | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Game/Code/Classes/UPlatformWindows.pas') diff --git a/Game/Code/Classes/UPlatformWindows.pas b/Game/Code/Classes/UPlatformWindows.pas index 1786d6cc..f78b87ec 100644 --- a/Game/Code/Classes/UPlatformWindows.pas +++ b/Game/Code/Classes/UPlatformWindows.pas @@ -33,6 +33,11 @@ type FindData: TWin32FindDataW; end; +function FindFirstW(const Path: WideString; Attr: Integer; var F: TSearchRecW): Integer; forward; +function FindNextW(var F: TSearchRecW): Integer; forward; +procedure FindCloseW(var F: TSearchRecW); forward; +function FindMatchingFileW(var F: TSearchRecW): Integer; forward; +function DirectoryExistsW(const Directory: widestring): Boolean; forward; function FindFirstW(const Path: widestring; Attr: Integer; var F: TSearchRecW): Integer; const -- cgit v1.2.3 From fba9a67e3718a65594dc7969dac952ce5cca99d8 Mon Sep 17 00:00:00 2001 From: eddie-0815 Date: Thu, 8 Nov 2007 23:18:12 +0000 Subject: Fixed song loading on Windows. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@601 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UPlatformWindows.pas | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'Game/Code/Classes/UPlatformWindows.pas') diff --git a/Game/Code/Classes/UPlatformWindows.pas b/Game/Code/Classes/UPlatformWindows.pas index f78b87ec..7e65d700 100644 --- a/Game/Code/Classes/UPlatformWindows.pas +++ b/Game/Code/Classes/UPlatformWindows.pas @@ -103,32 +103,33 @@ Function TPlatform.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs var i : Integer; SR : TSearchRecW; + lAttrib : Integer; begin i := 0; Filter := LowerCase(Filter); - if ReturnAllSubDirs then begin - if FindFirstW(Dir + '*', faDirectory, SR) = 0 then - repeat - if (SR.Name <> '.') and (SR.Name <> '..') then + if FindFirstW(Dir + '*', faAnyFile or faDirectory, SR) = 0 then + repeat + if (SR.Name <> '.') and (SR.Name <> '..') then + begin + lAttrib := FileGetAttr(Dir + SR.name); + if ReturnAllSubDirs and ((lAttrib and faDirectory) <> 0) then begin SetLength( Result, i + 1); - Result[i].Name := SR.Name; + Result[i].Name := SR.name; Result[i].IsDirectory := true; Result[i].IsFile := false; i := i + 1; + end + else if (Length(Filter) = 0) or (Pos( Filter, LowerCase(SR.Name)) > 0) then + begin + SetLength( Result, i + 1); + Result[i].Name := SR.Name; + Result[i].IsDirectory := false; + Result[i].IsFile := true; + i := i + 1; end; - until FindNextW(SR) <> 0; - FindCloseW(SR); - end; - - if FindFirstW(Dir + '*' + Filter, 0, SR) = 0 then - repeat - SetLength( Result, i + 1); - Result[i].Name := SR.Name; - Result[i].IsDirectory := true; - Result[i].IsFile := false; - i := i + 1; + end; until FindNextW(SR) <> 0; FindCloseW(SR); 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/UPlatformWindows.pas | 35 +++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'Game/Code/Classes/UPlatformWindows.pas') diff --git a/Game/Code/Classes/UPlatformWindows.pas b/Game/Code/Classes/UPlatformWindows.pas index 7e65d700..afdcebcf 100644 --- a/Game/Code/Classes/UPlatformWindows.pas +++ b/Game/Code/Classes/UPlatformWindows.pas @@ -12,9 +12,10 @@ uses Classes, UPlatform; type - TPlatform = class(TInterfacedObject, IPlatform) + TPlatformWindows = class(TPlatform) public - Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; + Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; override; + function TerminateIfAlreadyRunning(var WndTitle : String) : Boolean; override; end; implementation @@ -99,7 +100,35 @@ begin Result := (Code <> -1) and (FILE_ATTRIBUTE_DIRECTORY and Code <> 0); end; -Function TPlatform.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; +//------------------------------ +//Start more than One Time Prevention +//------------------------------ +function TPlatformWindows.TerminateIfAlreadyRunning(var WndTitle : String) : Boolean; +var + hWnd: THandle; + I: Integer; +begin + Result := false; + hWnd:= FindWindow(nil, PChar(WndTitle)); + //Programm already started + if (hWnd <> 0) then + begin + I := Messagebox(0, PChar('Another Instance of Ultrastar is already running. Continue ?'), PChar(WndTitle), MB_ICONWARNING or MB_YESNO); + if (I = IDYes) then + begin + I := 1; + repeat + Inc(I); + hWnd := FindWindow(nil, PChar(WndTitle + ' Instance ' + InttoStr(I))); + until (hWnd = 0); + WndTitle := WndTitle + ' Instance ' + InttoStr(I); + end + else + Result := true; + end; +end; + +Function TPlatformWindows.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; var i : Integer; SR : TSearchRecW; -- cgit v1.2.3 From 64de8825666fcb234fb31b4c716cf1c9fbcaacfe Mon Sep 17 00:00:00 2001 From: tobigun Date: Wed, 28 Nov 2007 16:35:34 +0000 Subject: fixed lazarus build-error due to differing declarations of FindFirstFileW and FindNextFileW (var vs pointer) in delphi and lazarus git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@655 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UPlatformWindows.pas | 54 +++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'Game/Code/Classes/UPlatformWindows.pas') diff --git a/Game/Code/Classes/UPlatformWindows.pas b/Game/Code/Classes/UPlatformWindows.pas index afdcebcf..93e72e7a 100644 --- a/Game/Code/Classes/UPlatformWindows.pas +++ b/Game/Code/Classes/UPlatformWindows.pas @@ -11,7 +11,7 @@ interface uses Classes, UPlatform; type - + TPlatformWindows = class(TPlatform) public Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; override; @@ -23,7 +23,7 @@ implementation uses SysUtils, Windows; type - + TSearchRecW = record Time: Integer; Size: Integer; @@ -45,7 +45,11 @@ const faSpecial = faHidden or faSysFile or faVolumeID or faDirectory; begin F.ExcludeAttr := not Attr and faSpecial; +{$IFDEF Delphi} F.FindHandle := FindFirstFileW(PWideChar(Path), F.FindData); +{$ELSE} + F.FindHandle := FindFirstFileW(PWideChar(Path), @F.FindData); +{$ENDIF} if F.FindHandle <> INVALID_HANDLE_VALUE then begin Result := FindMatchingFileW(F); @@ -56,7 +60,11 @@ end; function FindNextW(var F: TSearchRecW): Integer; begin +{$IFDEF Delphi} if FindNextFileW(F.FindHandle, F.FindData) then +{$ELSE} + if FindNextFileW(F.FindHandle, @F.FindData) then +{$ENDIF} Result := FindMatchingFileW(F) else Result := GetLastError; @@ -78,7 +86,11 @@ begin with F do begin while FindData.dwFileAttributes and ExcludeAttr <> 0 do +{$IFDEF Delphi} if not FindNextFileW(FindHandle, FindData) then +{$ELSE} + if not FindNextFileW(FindHandle, @FindData) then +{$ENDIF} begin Result := GetLastError; Exit; @@ -101,31 +113,31 @@ begin end; //------------------------------ -//Start more than One Time Prevention -//------------------------------ +//Start more than One Time Prevention +//------------------------------ function TPlatformWindows.TerminateIfAlreadyRunning(var WndTitle : String) : Boolean; var hWnd: THandle; - I: Integer; + I: Integer; begin Result := false; hWnd:= FindWindow(nil, PChar(WndTitle)); - //Programm already started - if (hWnd <> 0) then - begin - I := Messagebox(0, PChar('Another Instance of Ultrastar is already running. Continue ?'), PChar(WndTitle), MB_ICONWARNING or MB_YESNO); - if (I = IDYes) then - begin - I := 1; - repeat - Inc(I); - hWnd := FindWindow(nil, PChar(WndTitle + ' Instance ' + InttoStr(I))); - until (hWnd = 0); - WndTitle := WndTitle + ' Instance ' + InttoStr(I); - end - else - Result := true; - end; + //Programm already started + if (hWnd <> 0) then + begin + I := Messagebox(0, PChar('Another Instance of Ultrastar is already running. Continue ?'), PChar(WndTitle), MB_ICONWARNING or MB_YESNO); + if (I = IDYes) then + begin + I := 1; + repeat + Inc(I); + hWnd := FindWindow(nil, PChar(WndTitle + ' Instance ' + InttoStr(I))); + until (hWnd = 0); + WndTitle := WndTitle + ' Instance ' + InttoStr(I); + end + else + Result := true; + end; end; Function TPlatformWindows.DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; -- 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/UPlatformWindows.pas | 59 +++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 5 deletions(-) (limited to 'Game/Code/Classes/UPlatformWindows.pas') diff --git a/Game/Code/Classes/UPlatformWindows.pas b/Game/Code/Classes/UPlatformWindows.pas index 93e72e7a..d4ba757a 100644 --- a/Game/Code/Classes/UPlatformWindows.pas +++ b/Game/Code/Classes/UPlatformWindows.pas @@ -8,19 +8,30 @@ interface {$I switches.inc} -uses Classes, UPlatform; +uses Classes, + UPlatform; type - TPlatformWindows = class(TPlatform) + TPlatformWindows = class( TInterfacedObject, IPlatform) public - Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; override; - function TerminateIfAlreadyRunning(var WndTitle : String) : Boolean; override; + Function DirectoryFindFiles(Dir, Filter : WideString; ReturnAllSubDirs : Boolean) : TDirectoryEntryArray; + function TerminateIfAlreadyRunning(var WndTitle : String) : Boolean; + function GetGamePath: WideString; + function FindSongFile(Dir, Mask: widestring): widestring; + + procedure halt; + + function GetLogPath : WideString; + function GetGameSharedPath : WideString; + function GetGameUserPath : WideString; end; implementation -uses SysUtils, Windows; +uses SysUtils, + Windows, + Forms; type @@ -175,4 +186,42 @@ begin FindCloseW(SR); end; +function TPlatformWindows.GetGamePath: WideString; +begin + // Windows and Linux use this: + Result := ExtractFilePath(ParamStr(0)); +end; + +procedure TPlatformWindows.halt; +begin + application.terminate; +end; + +function TPlatformWindows.GetLogPath : WideString; +begin + result := ExtractFilePath(ParamStr(0)); +end; + +function TPlatformWindows.GetGameSharedPath : WideString; +begin + result := ExtractFilePath(ParamStr(0)); +end; + +function TPlatformWindows.GetGameUserPath : WideString; +begin + result := ExtractFilePath(ParamStr(0)); +end; + + function TPlatformWindows.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