diff options
Diffstat (limited to '')
-rw-r--r-- | src/classes/UCommandLine.pas | 5 | ||||
-rw-r--r-- | src/classes/UPlatform.pas | 9 | ||||
-rw-r--r-- | src/classes/UPlatformLinux.pas | 71 | ||||
-rw-r--r-- | src/classes/UPlatformMacOSX.pas | 2 | ||||
-rw-r--r-- | src/classes/UPlatformWindows.pas | 6 | ||||
-rw-r--r-- | src/config-darwin.inc | 5 | ||||
-rw-r--r-- | src/config.inc.in | 5 |
7 files changed, 59 insertions, 44 deletions
diff --git a/src/classes/UCommandLine.pas b/src/classes/UCommandLine.pas index 3c56c606..8bdc4f5a 100644 --- a/src/classes/UCommandLine.pas +++ b/src/classes/UCommandLine.pas @@ -57,7 +57,6 @@ const cHelp = 'help'; cDebug = 'debug'; cMediaInterfaces = 'showinterfaces'; - cUseLocalPaths = 'localpaths'; implementation @@ -98,11 +97,7 @@ begin writeln( ' '+s( 'Switch' ) +' : Purpose' ); writeln( ' ----------------------------------------------------------' ); writeln( ' '+s( cMediaInterfaces ) + #9 + ' : Show in-use media interfaces' ); - writeln( ' '+s( cUseLocalPaths ) + #9 + ' : Use relative paths' ); writeln( ' '+s( cDebug ) + #9 + ' : Display Debugging info' ); - - - writeln( '' ); platform.halt; diff --git a/src/classes/UPlatform.pas b/src/classes/UPlatform.pas index b71ac1b8..1dcdb5b9 100644 --- a/src/classes/UPlatform.pas +++ b/src/classes/UPlatform.pas @@ -25,6 +25,7 @@ type TDirectoryEntryArray = array of TDirectoryEntry; TPlatform = class + function GetExecutionDir(): string; procedure Init; virtual; function DirectoryFindFiles(Dir, Filter: WideString; ReturnAllSubDirs: boolean): TDirectoryEntryArray; virtual; abstract; function TerminateIfAlreadyRunning(var WndTitle : string): boolean; virtual; @@ -81,6 +82,14 @@ begin System.Halt; end; +{** + * Returns the directory of the executable + *} +function TPlatform.GetExecutionDir(): string; +begin + Result := ExtractFilePath(ParamStr(0)); +end; + (** * Default TerminateIfAlreadyRunning() implementation *) diff --git a/src/classes/UPlatformLinux.pas b/src/classes/UPlatformLinux.pas index 19361a22..3227e4f8 100644 --- a/src/classes/UPlatformLinux.pas +++ b/src/classes/UPlatformLinux.pas @@ -16,8 +16,13 @@ uses type TPlatformLinux = class(TPlatform) private + UseLocalDirs: boolean; + + procedure DetectLocalExecution(); function GetHomeDir(): string; public + procedure Init; override; + function DirectoryFindFiles(Dir, Filter: WideString; ReturnAllSubDirs: Boolean): TDirectoryEntryArray; override; function GetLogPath : WideString; override; @@ -36,6 +41,34 @@ uses SysUtils, ULog; +procedure TPlatformLinux.Init; +begin + inherited Init(); + DetectLocalExecution(); +end; + +{** + * Detects whether the game was executed locally or globally. + * - It is local if it was not installed and directly executed from + * within the game folder. In this case resources (themes, language-files) + * reside in the directory of the executable. + * - It is global if the game was installed (e.g. to /usr/bin) and + * the resources are in a separate folder (e.g. /usr/share/ultrastardx) + * which name is stored in the INSTALL_DATADIR constant in config-linux.inc. + * + * Sets UseLocalDirs to true if the game is executed locally, false otherwise. + *} +procedure TPlatformLinux.DetectLocalExecution(); +var + LocalDir: string; +begin + LocalDir := GetExecutionDir(); + + // we just check if the 'languages' folder exists in the + // directory of the executable. If so -> local execution. + UseLocalDirs := (DirectoryExists(LocalDir + 'languages')); +end; + function TPlatformLinux.DirectoryFindFiles(Dir, Filter: WideString; ReturnAllSubDirs: Boolean): TDirectoryEntryArray; var i: Integer; @@ -81,18 +114,10 @@ end; function TPlatformLinux.GetLogPath: WideString; begin - if FindCmdLineSwitch( cUseLocalPaths ) then - begin - Result := ExtractFilePath(ParamStr(0)); - end + if UseLocalDirs then + Result := GetExecutionDir() else - begin - {$IFDEF UseLocalDirs} - Result := ExtractFilePath(ParamStr(0)); - {$ELSE} - Result := GetGameUserPath() + 'logs/'; - {$ENDIF} - end; + Result := GetGameUserPath() + 'logs/'; // create non-existing directories ForceDirectories(Result); @@ -100,35 +125,23 @@ end; function TPlatformLinux.GetGameSharedPath: WideString; begin - if FindCmdLineSwitch( cUseLocalPaths ) then - Result := ExtractFilePath(ParamStr(0)) + if UseLocalDirs then + Result := GetExecutionDir() else - begin - {$IFDEF UseLocalDirs} - Result := ExtractFilePath(ParamStr(0)); - {$ELSE} Result := IncludeTrailingPathDelimiter(INSTALL_DATADIR); - {$ENDIF} - end; end; function TPlatformLinux.GetGameUserPath: WideString; begin - if FindCmdLineSwitch( cUseLocalPaths ) then - Result := ExtractFilePath(ParamStr(0)) + if UseLocalDirs then + Result := GetExecutionDir() else - begin - {$IFDEF UseLocalDirs} - Result := ExtractFilePath(ParamStr(0)); - {$ELSE} Result := GetHomeDir() + '.ultrastardx/'; - {$ENDIF} - end; end; -(** +{** * Returns the user's home directory terminated by a path delimiter - *) + *} function TPlatformLinux.GetHomeDir(): string; {$IF FPC_VERSION_INT >= 2002002} var diff --git a/src/classes/UPlatformMacOSX.pas b/src/classes/UPlatformMacOSX.pas index 849c354b..2ab2a390 100644 --- a/src/classes/UPlatformMacOSX.pas +++ b/src/classes/UPlatformMacOSX.pas @@ -218,7 +218,7 @@ begin // We have to cut the last two folders // to get the application folder. - Result := ExtractFilePath(ParamStr(0)); + Result := GetExecutionDir(); for i := 1 to 2 do begin pos := Length(Result); diff --git a/src/classes/UPlatformWindows.pas b/src/classes/UPlatformWindows.pas index ee132a7b..029e8d33 100644 --- a/src/classes/UPlatformWindows.pas +++ b/src/classes/UPlatformWindows.pas @@ -214,18 +214,18 @@ end; function TPlatformWindows.GetLogPath: WideString; begin - Result := ExtractFilePath(ParamStr(0)); + Result := GetExecutionDir(); end; function TPlatformWindows.GetGameSharedPath: WideString; begin - Result := ExtractFilePath(ParamStr(0)); + Result := GetExecutionDir(); end; function TPlatformWindows.GetGameUserPath: WideString; begin //Result := GetSpecialPath(CSIDL_APPDATA) + PathDelim + 'UltraStarDX' + PathDelim; - Result := ExtractFilePath(ParamStr(0)); + Result := GetExecutionDir(); end; function TPlatformWindows.CopyFile(const Source, Target: WideString; FailIfExists: boolean): boolean; diff --git a/src/config-darwin.inc b/src/config-darwin.inc index 6e191370..178f9d06 100644 --- a/src/config-darwin.inc +++ b/src/config-darwin.inc @@ -5,10 +5,9 @@ {* Paths *} -{$UNDEF UseLocalDirs} -{$IF (not Defined(UseLocalDirs)) and Defined(IncludeConstants)} +{$IFDEF IncludeConstants} INSTALL_DATADIR = '/usr/local/share/ultrastardx'; -{$IFEND} +{$ENDIF} {* Libraries *} diff --git a/src/config.inc.in b/src/config.inc.in index a9714366..870c35fd 100644 --- a/src/config.inc.in +++ b/src/config.inc.in @@ -5,10 +5,9 @@ {* Paths *} -{$@DEFINE_USE_LOCAL_DIRS@ UseLocalDirs} -{$IF (not Defined(UseLocalDirs)) and Defined(IncludeConstants)} +{$IFDEF IncludeConstants} INSTALL_DATADIR = '@INSTALL_DATADIR@'; -{$IFEND} +{$ENDIF} {* Libraries *} |