diff options
author | tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2010-05-08 15:02:05 +0000 |
---|---|---|
committer | tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2010-05-08 15:02:05 +0000 |
commit | f59682f2109f72d100234fb65efe225090cd700e (patch) | |
tree | 0d1f93c0c823c653061da9ccc86c3751c2f3e66b /src | |
parent | a0e97b366ba31bbd15d2b89d989831a1948d3c4c (diff) | |
download | usdx-f59682f2109f72d100234fb65efe225090cd700e.tar.gz usdx-f59682f2109f72d100234fb65efe225090cd700e.tar.xz usdx-f59682f2109f72d100234fb65efe225090cd700e.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/base/UPlatformWindows.pas | 70 |
1 files changed, 55 insertions, 15 deletions
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; |