From 7a01b05b3861a667eb32ce2e0fc88ff3bacb99ae Mon Sep 17 00:00:00 2001 From: mogguh Date: Tue, 2 Sep 2008 17:25:26 +0000 Subject: Moved: The folder classes has been renamed to base Updated: ultrastardx.dpr has been changed accordingly git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1339 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/UPlatformWindows.pas | 236 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 src/base/UPlatformWindows.pas (limited to 'src/base/UPlatformWindows.pas') diff --git a/src/base/UPlatformWindows.pas b/src/base/UPlatformWindows.pas new file mode 100644 index 00000000..029e8d33 --- /dev/null +++ b/src/base/UPlatformWindows.pas @@ -0,0 +1,236 @@ +unit UPlatformWindows; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +{$I switches.inc} + +// turn off messages for platform specific symbols +{$WARN SYMBOL_PLATFORM OFF} + +uses + Classes, + UPlatform; + +type + TPlatformWindows = class(TPlatform) + private + function GetSpecialPath(CSIDL: integer): WideString; + public + function DirectoryFindFiles(Dir, Filter: WideString; ReturnAllSubDirs: Boolean): TDirectoryEntryArray; override; + function TerminateIfAlreadyRunning(var WndTitle: String): Boolean; override; + + function GetLogPath: WideString; override; + function GetGameSharedPath: WideString; override; + function GetGameUserPath: WideString; override; + + function CopyFile(const Source, Target: WideString; FailIfExists: boolean): boolean; override; + end; + +implementation + +uses + SysUtils, + ShlObj, + Windows, + UConfig; + +type + TSearchRecW = record + Time: Integer; + Size: Integer; + Attr: Integer; + Name: WideString; + ExcludeAttr: Integer; + FindHandle: THandle; + 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 + 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); + if Result <> 0 then FindCloseW(F); + end else + Result := GetLastError; +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; +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 +{$IFDEF Delphi} + if not FindNextFileW(FindHandle, FindData) then +{$ELSE} + if not FindNextFileW(FindHandle, @FindData) then +{$ENDIF} + 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; + +//------------------------------ +//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; + Attrib : Integer; +begin + i := 0; + Filter := LowerCase(Filter); + + if FindFirstW(Dir + '*', faAnyFile or faDirectory, SR) = 0 then + repeat + if (SR.Name <> '.') and (SR.Name <> '..') then + begin + Attrib := FileGetAttr(Dir + SR.name); + if ReturnAllSubDirs and ((Attrib and faDirectory) <> 0) then + begin + SetLength( Result, i + 1); + 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; + end; + until FindNextW(SR) <> 0; + FindCloseW(SR); +end; + +(** + * Returns the path of a special folder. + * + * Some Folder IDs: + * CSIDL_APPDATA (e.g. C:\Documents and Settings\username\Application Data) + * CSIDL_LOCAL_APPDATA (e.g. C:\Documents and Settings\username\Local Settings\Application Data) + * CSIDL_PROFILE (e.g. C:\Documents and Settings\username) + * CSIDL_PERSONAL (e.g. C:\Documents and Settings\username\My Documents) + * CSIDL_MYMUSIC (e.g. C:\Documents and Settings\username\My Documents\My Music) + *) +function TPlatformWindows.GetSpecialPath(CSIDL: integer): WideString; +var + Buffer: array [0..MAX_PATH-1] of WideChar; +begin +{$IF Defined(Delphi) or (FPC_VERSION_INT >= 2002002)} // >= 2.2.2 + if (SHGetSpecialFolderPathW(0, @Buffer, CSIDL, false)) then + Result := Buffer + else +{$IFEND} + Result := ''; +end; + +function TPlatformWindows.GetLogPath: WideString; +begin + Result := GetExecutionDir(); +end; + +function TPlatformWindows.GetGameSharedPath: WideString; +begin + Result := GetExecutionDir(); +end; + +function TPlatformWindows.GetGameUserPath: WideString; +begin + //Result := GetSpecialPath(CSIDL_APPDATA) + PathDelim + 'UltraStarDX' + PathDelim; + Result := GetExecutionDir(); +end; + +function TPlatformWindows.CopyFile(const Source, Target: WideString; FailIfExists: boolean): boolean; +begin + Result := Windows.CopyFileW(PWideChar(Source), PWideChar(Target), FailIfExists); +end; + +end. -- cgit v1.2.3 From dbf39d5bfc56c24a67d481187c619dc84828221f Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Tue, 23 Sep 2008 21:17:22 +0000 Subject: gpl header added and property svn:header set to "HeadURL Id" git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1403 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/UPlatformWindows.pas | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/base/UPlatformWindows.pas') diff --git a/src/base/UPlatformWindows.pas b/src/base/UPlatformWindows.pas index 029e8d33..e198958a 100644 --- a/src/base/UPlatformWindows.pas +++ b/src/base/UPlatformWindows.pas @@ -1,3 +1,28 @@ +{* UltraStar Deluxe - Karaoke Game + * + * UltraStar Deluxe is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + *} + unit UPlatformWindows; interface -- cgit v1.2.3 From 917901e8e33438c425aef50a0a7417f32d77b760 Mon Sep 17 00:00:00 2001 From: s_alexander Date: Mon, 9 Nov 2009 00:27:55 +0000 Subject: merged unicode branch (r1931) into trunk git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1939 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/UPlatformWindows.pas | 159 ++++-------------------------------------- 1 file changed, 13 insertions(+), 146 deletions(-) (limited to 'src/base/UPlatformWindows.pas') diff --git a/src/base/UPlatformWindows.pas b/src/base/UPlatformWindows.pas index e198958a..a0372dad 100644 --- a/src/base/UPlatformWindows.pas +++ b/src/base/UPlatformWindows.pas @@ -38,21 +38,19 @@ interface uses Classes, - UPlatform; + UPlatform, + UPath; type TPlatformWindows = class(TPlatform) private - function GetSpecialPath(CSIDL: integer): WideString; + function GetSpecialPath(CSIDL: integer): IPath; public - function DirectoryFindFiles(Dir, Filter: WideString; ReturnAllSubDirs: Boolean): TDirectoryEntryArray; override; function TerminateIfAlreadyRunning(var WndTitle: String): Boolean; override; - function GetLogPath: WideString; override; - function GetGameSharedPath: WideString; override; - function GetGameUserPath: WideString; override; - - function CopyFile(const Source, Target: WideString; FailIfExists: boolean): boolean; override; + function GetLogPath: IPath; override; + function GetGameSharedPath: IPath; override; + function GetGameUserPath: IPath; override; end; implementation @@ -63,95 +61,6 @@ uses Windows, UConfig; -type - TSearchRecW = record - Time: Integer; - Size: Integer; - Attr: Integer; - Name: WideString; - ExcludeAttr: Integer; - FindHandle: THandle; - 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 - 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); - if Result <> 0 then FindCloseW(F); - end else - Result := GetLastError; -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; -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 -{$IFDEF Delphi} - if not FindNextFileW(FindHandle, FindData) then -{$ELSE} - if not FindNextFileW(FindHandle, @FindData) then -{$ENDIF} - 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; - //------------------------------ //Start more than One Time Prevention //------------------------------ @@ -180,41 +89,6 @@ begin end; end; -function TPlatformWindows.DirectoryFindFiles(Dir, Filter: WideString; ReturnAllSubDirs: Boolean): TDirectoryEntryArray; -var - i : Integer; - SR : TSearchRecW; - Attrib : Integer; -begin - i := 0; - Filter := LowerCase(Filter); - - if FindFirstW(Dir + '*', faAnyFile or faDirectory, SR) = 0 then - repeat - if (SR.Name <> '.') and (SR.Name <> '..') then - begin - Attrib := FileGetAttr(Dir + SR.name); - if ReturnAllSubDirs and ((Attrib and faDirectory) <> 0) then - begin - SetLength( Result, i + 1); - 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; - end; - until FindNextW(SR) <> 0; - FindCloseW(SR); -end; - (** * Returns the path of a special folder. * @@ -225,37 +99,30 @@ end; * CSIDL_PERSONAL (e.g. C:\Documents and Settings\username\My Documents) * CSIDL_MYMUSIC (e.g. C:\Documents and Settings\username\My Documents\My Music) *) -function TPlatformWindows.GetSpecialPath(CSIDL: integer): WideString; +function TPlatformWindows.GetSpecialPath(CSIDL: integer): IPath; var Buffer: array [0..MAX_PATH-1] of WideChar; begin -{$IF Defined(Delphi) or (FPC_VERSION_INT >= 2002002)} // >= 2.2.2 if (SHGetSpecialFolderPathW(0, @Buffer, CSIDL, false)) then - Result := Buffer + Result := Path(Buffer) else -{$IFEND} - Result := ''; + Result := PATH_NONE; end; -function TPlatformWindows.GetLogPath: WideString; +function TPlatformWindows.GetLogPath: IPath; begin Result := GetExecutionDir(); end; -function TPlatformWindows.GetGameSharedPath: WideString; +function TPlatformWindows.GetGameSharedPath: IPath; begin Result := GetExecutionDir(); end; -function TPlatformWindows.GetGameUserPath: WideString; +function TPlatformWindows.GetGameUserPath: IPath; begin - //Result := GetSpecialPath(CSIDL_APPDATA) + PathDelim + 'UltraStarDX' + PathDelim; + //Result := GetSpecialPath(CSIDL_APPDATA).Append('UltraStarDX', pdAppend); Result := GetExecutionDir(); end; -function TPlatformWindows.CopyFile(const Source, Target: WideString; FailIfExists: boolean): boolean; -begin - Result := Windows.CopyFileW(PWideChar(Source), PWideChar(Target), FailIfExists); -end; - end. -- cgit v1.2.3 From 4788a676e9275e9e6da128ad3a070a80311bd012 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Mon, 25 Jan 2010 19:43:36 +0000 Subject: use APPDATA\ultrastardx to store config files on windows a portable installation (old behaviour; all config files stored in the directory of the executable) is also available detection works as follows: if a config.ini file is detected in the executable dir -> portable installation otherwise -> new behaviour only tested on Windows XP, please test on Vista and Seven. It should work there as well. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2094 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/UPlatformWindows.pas | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src/base/UPlatformWindows.pas') diff --git a/src/base/UPlatformWindows.pas b/src/base/UPlatformWindows.pas index a0372dad..102ae67a 100644 --- a/src/base/UPlatformWindows.pas +++ b/src/base/UPlatformWindows.pas @@ -44,8 +44,12 @@ uses type TPlatformWindows = class(TPlatform) private + UseLocalDirs: boolean; + function GetSpecialPath(CSIDL: integer): IPath; + procedure DetectLocalExecution(); public + procedure Init; override; function TerminateIfAlreadyRunning(var WndTitle: String): Boolean; override; function GetLogPath: IPath; override; @@ -61,6 +65,12 @@ uses Windows, UConfig; +procedure TPlatformWindows.Init; +begin + inherited Init(); + DetectLocalExecution(); +end; + //------------------------------ //Start more than One Time Prevention //------------------------------ @@ -109,6 +119,33 @@ begin Result := PATH_NONE; end; +{** + * Detects whether the game was executed locally or globally. + * - It is local if a config.ini exists in the directory of the + * executable. In config files like config.ini or score db + * reside in the directory of the executable. This is useful + * to enable windows users to have a portable installation + * e.g. on an external hdd. This is also the default behaviour + * of usdx prior to version 1.1 + * - It is global if no config.ini exists in the directory of the + * executable the config files are in a separate folder + * (e.g. APPDATA\ultrastardx) + * On windows resources (themes, language-files) + * reside in the directory of the executable in every case + * + * Sets UseLocalDirs to true if the game is executed locally, false otherwise. + *} +procedure TPlatformWindows.DetectLocalExecution(); +var + LocalDir, ConfigIni: IPath; +begin + // we just check if the 'languages' folder exists in the + // directory of the executable. If so -> local execution. + LocalDir := GetExecutionDir(); + ConfigIni := LocalDir.Append('config.ini'); + UseLocalDirs := (ConfigIni.IsFile and ConfigIni.Exists); +end; + function TPlatformWindows.GetLogPath: IPath; begin Result := GetExecutionDir(); @@ -121,8 +158,10 @@ end; function TPlatformWindows.GetGameUserPath: IPath; begin - //Result := GetSpecialPath(CSIDL_APPDATA).Append('UltraStarDX', pdAppend); - Result := GetExecutionDir(); + if UseLocalDirs then + Result := GetExecutionDir() + else + Result := GetSpecialPath(CSIDL_APPDATA).Append('ultrastardx', pdAppend); end; end. -- cgit v1.2.3 From ca4174bf978fc74150b6b619bbb68ae3d53e4f2c Mon Sep 17 00:00:00 2001 From: canni0 Date: Tue, 26 Jan 2010 02:03:18 +0000 Subject: - added windows version check in addition to commit #2094 Behaviour changes as follows: Use local path (old behaviour) if ... - ... config.ini is detected -> use local path (old behaviour) Use global path (%APPDATA%/ultrastardx) if ... - ... no config.ini is present (allows portable installations) - ... user is running Vista or later git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2097 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/UPlatformWindows.pas | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/base/UPlatformWindows.pas') diff --git a/src/base/UPlatformWindows.pas b/src/base/UPlatformWindows.pas index 102ae67a..cf69a359 100644 --- a/src/base/UPlatformWindows.pas +++ b/src/base/UPlatformWindows.pas @@ -129,7 +129,7 @@ end; * of usdx prior to version 1.1 * - It is global if no config.ini exists in the directory of the * executable the config files are in a separate folder - * (e.g. APPDATA\ultrastardx) + * (e.g. %APPDATA%\ultrastardx) * On windows resources (themes, language-files) * reside in the directory of the executable in every case * @@ -138,12 +138,15 @@ end; procedure TPlatformWindows.DetectLocalExecution(); var LocalDir, ConfigIni: IPath; + OSVerInfo: TOSVersionInfo; begin - // we just check if the 'languages' folder exists in the - // directory of the executable. If so -> local execution. + // we just check if 'config.ini' exists in the + // directory of the executable or if windows version + // is less than Windows Vista (major version = 6). + // If so -> local execution. LocalDir := GetExecutionDir(); ConfigIni := LocalDir.Append('config.ini'); - UseLocalDirs := (ConfigIni.IsFile and ConfigIni.Exists); + UseLocalDirs := ((ConfigIni.IsFile and ConfigIni.Exists) and (OSVerInfo.dwMajorVersion < 6)); end; function TPlatformWindows.GetLogPath: IPath; -- cgit v1.2.3 From 69d6fc57ff2cf57a3f8fe67e82ff8f900436c873 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Tue, 6 Apr 2010 16:29:29 +0000 Subject: change of version check and comments upgrade. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2217 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/UPlatformWindows.pas | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/base/UPlatformWindows.pas') diff --git a/src/base/UPlatformWindows.pas b/src/base/UPlatformWindows.pas index cf69a359..30bad264 100644 --- a/src/base/UPlatformWindows.pas +++ b/src/base/UPlatformWindows.pas @@ -121,32 +121,31 @@ end; {** * Detects whether the game was executed locally or globally. - * - It is local if a config.ini exists in the directory of the - * executable. In config files like config.ini or score db + * - It is local if config.ini exists in the directory of the + * executable. Config files like config.ini or score db * reside in the directory of the executable. This is useful * to enable windows users to have a portable installation * e.g. on an external hdd. This is also the default behaviour * of usdx prior to version 1.1 * - It is global if no config.ini exists in the directory of the - * executable the config files are in a separate folder + * executable. The config files are in a separate folder * (e.g. %APPDATA%\ultrastardx) - * On windows resources (themes, language-files) - * reside in the directory of the executable in every case + * On windows, resources (themes, language-files) + * reside in the directory of the executable in any case * * Sets UseLocalDirs to true if the game is executed locally, false otherwise. *} procedure TPlatformWindows.DetectLocalExecution(); var LocalDir, ConfigIni: IPath; - OSVerInfo: TOSVersionInfo; begin // we just check if 'config.ini' exists in the - // directory of the executable or if windows version + // directory of the executable or if the windows version // is less than Windows Vista (major version = 6). // If so -> local execution. LocalDir := GetExecutionDir(); ConfigIni := LocalDir.Append('config.ini'); - UseLocalDirs := ((ConfigIni.IsFile and ConfigIni.Exists) and (OSVerInfo.dwMajorVersion < 6)); + UseLocalDirs := (ConfigIni.IsFile and ConfigIni.Exists and (Win32MajorVersion < 6)); end; function TPlatformWindows.GetLogPath: IPath; -- cgit v1.2.3 From 8a3039ff7c074fe7d2491b765156f56f3c1940b8 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Wed, 7 Apr 2010 12:22:27 +0000 Subject: write log files to writable user directory git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2223 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/UPlatformWindows.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/base/UPlatformWindows.pas') diff --git a/src/base/UPlatformWindows.pas b/src/base/UPlatformWindows.pas index 30bad264..8c4469cf 100644 --- a/src/base/UPlatformWindows.pas +++ b/src/base/UPlatformWindows.pas @@ -150,7 +150,7 @@ end; function TPlatformWindows.GetLogPath: IPath; begin - Result := GetExecutionDir(); + Result := GetGameUserPath; end; function TPlatformWindows.GetGameSharedPath: IPath; -- cgit v1.2.3 From f59682f2109f72d100234fb65efe225090cd700e Mon Sep 17 00:00:00 2001 From: tobigun Date: Sat, 8 May 2010 15:02:05 +0000 Subject: changed local/global execution detection: * Detects whether the was executed locally or globally. * - Local mode: * - Condition: * - config.ini is writable or creatable in the directory of the executable. * - Examples: * - The USDX zip-archive has been unpacked to a directory with write. * permissions * - XP: USDX was installed to %ProgramFiles% and the user is an admin. * - USDX is started from an external HD- or flash-drive * - Behavior: * Config files like config.ini or score db reside in the directory of the * executable. This is useful to enable windows users to have a portable * installation e.g. on an external hdd. * This is also the default behaviour of usdx prior to version 1.1 * - Global mode: * - Condition: * - config.ini is not writable. * - Examples: * - Vista/7: USDX was installed to %ProgramFiles%. * - XP: USDX was installed to %ProgramFiles% and the user is not an admin. * - USDX is started from CD * - Behavior: * - The config files are in a separate folder (e.g. %APPDATA%\ultrastardx) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2344 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/base/UPlatformWindows.pas | 70 +++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 15 deletions(-) (limited to 'src/base/UPlatformWindows.pas') diff --git a/src/base/UPlatformWindows.pas b/src/base/UPlatformWindows.pas index 8c4469cf..91d3cce6 100644 --- a/src/base/UPlatformWindows.pas +++ b/src/base/UPlatformWindows.pas @@ -120,16 +120,30 @@ begin end; {** - * Detects whether the game was executed locally or globally. - * - It is local if config.ini exists in the directory of the - * executable. Config files like config.ini or score db - * reside in the directory of the executable. This is useful - * to enable windows users to have a portable installation - * e.g. on an external hdd. This is also the default behaviour - * of usdx prior to version 1.1 - * - It is global if no config.ini exists in the directory of the - * executable. The config files are in a separate folder - * (e.g. %APPDATA%\ultrastardx) + * Detects whether the was executed locally or globally. + * - Local mode: + * - Condition: + * - config.ini is writable or creatable in the directory of the executable. + * - Examples: + * - The USDX zip-archive has been unpacked to a directory with write. + * permissions + * - XP: USDX was installed to %ProgramFiles% and the user is an admin. + * - USDX is started from an external HD- or flash-drive + * - Behavior: + * Config files like config.ini or score db reside in the directory of the + * executable. This is useful to enable windows users to have a portable + * installation e.g. on an external hdd. + * This is also the default behaviour of usdx prior to version 1.1 + * - Global mode: + * - Condition: + * - config.ini is not writable. + * - Examples: + * - Vista/7: USDX was installed to %ProgramFiles%. + * - XP: USDX was installed to %ProgramFiles% and the user is not an admin. + * - USDX is started from CD + * - Behavior: + * - The config files are in a separate folder (e.g. %APPDATA%\ultrastardx) + * * On windows, resources (themes, language-files) * reside in the directory of the executable in any case * @@ -138,14 +152,40 @@ end; procedure TPlatformWindows.DetectLocalExecution(); var LocalDir, ConfigIni: IPath; + Handle: TFileHandle; begin - // we just check if 'config.ini' exists in the - // directory of the executable or if the windows version - // is less than Windows Vista (major version = 6). - // If so -> local execution. LocalDir := GetExecutionDir(); ConfigIni := LocalDir.Append('config.ini'); - UseLocalDirs := (ConfigIni.IsFile and ConfigIni.Exists and (Win32MajorVersion < 6)); + + // check if config.ini is writable or creatable, if so use local dirs + UseLocalDirs := false; + if (ConfigIni.Exists()) then + begin + // do not use a read-only config file + if (not ConfigIni.IsReadOnly()) then + begin + // Just open the file in read-write mode to be sure that we have access + // rights for it. + // Note: Do not use IsReadOnly() as it does not check file privileges, so + // a non-read-only file might not be writable for us. + Handle := ConfigIni.Open(fmOpenReadWrite); + if (Handle <> -1) then + begin + FileClose(Handle); + UseLocalDirs := true; + end; + end; + end + else // config.ini does not exist + begin + // try to create config.ini + Handle := ConfigIni.CreateFile(); + if (Handle <> -1) then + begin + FileClose(Handle); + UseLocalDirs := true; + end; + end; end; function TPlatformWindows.GetLogPath: IPath; -- cgit v1.2.3