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') 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