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