From 82d89552dd0e3241987ce363b71e83c22be306e1 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Fri, 25 Oct 2019 14:08:16 +0300 Subject: [PATCH] add paths for osx --- src/game/g_main.pas | 97 +++++++++++++++++++++++++++++++++++++++--- src/shared/a_modes.inc | 3 ++ 2 files changed, 93 insertions(+), 7 deletions(-) diff --git a/src/game/g_main.pas b/src/game/g_main.pas index ee0d96e..165a116 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -61,6 +61,9 @@ uses {$IFDEF LINUX} BaseUnix, {$ENDIF} +{$IFDEF DARWIN} + MacOSAll, CocoaAll, +{$ENDIF} {$IFDEF USE_SDL2} SDL2, {$ENDIF} @@ -109,6 +112,27 @@ begin e_LogWriteln(' ' + dir); end; +{$IFDEF DARWIN} + function NSStringToAnsiString (s: NSString): AnsiString; + var i: Integer; + begin + result := ''; + for i := 0 to s.length - 1 do + result := result + AnsiChar(s.characterAtIndex(i)); + end; + + function GetBundlePath (): AnsiString; + var pathRef: CFURLRef; pathCFStr: CFStringRef; pathStr: ShortString; + begin + pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle()); + pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle); + CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding()); + CFRelease(pathRef); + CFRelease(pathCFStr); + Result := pathStr; + end; +{$ENDIF} + procedure InitPath; var i: Integer; rwdir, rodir: AnsiString; rwdirs, rodirs: SSArray; //first: Boolean = true; @@ -189,53 +213,112 @@ procedure InitPath; end; function GetDefaultRODirs (): SSArray; - {$IFDEF UNIX} + {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)} var home: AnsiString; {$ENDIF} + {$IFDEF WINDOWS} + var appdata: AnsiString; + {$ENDIF} + {$IFDEF DARWIN} + var bundle, s: AnsiString; dirArr: NSArray; i: Integer; + {$ENDIF} begin + result := nil; if forceCurrentDir = false then begin {$IFDEF USE_SDL2} AddDir(result, SDL_GetBasePath()); AddDir(result, SDL_GetPrefPath('', 'doom2df')); {$ENDIF} - {$IFDEF UNIX} + {$IFDEF WINDOWS} + appdata := GetEnvironmentVariable('APPDATA') + '\doom2df'; + if appdata <> '' then + AddDir(result, appdata); + {$ENDIF} + {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)} AddDir(result, '/usr/share/doom2df'); AddDir(result, '/usr/local/share/doom2df'); home := GetEnvironmentVariable('HOME'); if home <> '' then AddDir(result, e_CatPath(home, '.doom2df')); {$ENDIF} + {$IFDEF DARWIN} + bundle := GetBundlePath(); + if bundle <> '' then + AddDir(result, e_CatPath(bundle, 'Contents/Resources')); + dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true); + for i := 0 to dirArr.count - 1 do + begin + s := NSStringToAnsiString(dirArr.objectAtIndex(i)); + AddDir(result, e_CatPath(s, 'Doom 2D Forever')) + end; + {$ENDIF} {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)} AddDir(result, SDL_AndroidGetInternalStoragePath()); if SDL_AndroidGetExternalStorageState() <> 0 then AddDir(result, SDL_AndroidGetExternalStoragePath()); {$ENDIF} end; - AddDir(result, '.'); + {$IFNDEF ANDROID} + {$IFDEF DARWIN} + if ExtractFileExt(bundle) <> '.app' then + AddDir(result, ''); + {$ELSE} + AddDir(result, ''); + {$ENDIF} + {$ENDIF} end; function GetDefaultRWDirs (): SSArray; - {$IFDEF UNIX} + {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)} var home: AnsiString; {$ENDIF} + {$IFDEF WINDOWS} + var appdata: AnsiString; + {$ENDIF} + {$IFDEF DARWIN} + var bundle, s: AnsiString; dirArr: NSArray; i: Integer; + {$ENDIF} begin + result := nil; if forceCurrentDir = false then begin - {$IF DEFINED(USE_SDL2)} + {$IFDEF USE_SDL2} AddDir(result, SDL_GetPrefPath('', 'doom2df')); {$ENDIF} - {$IFDEF UNIX} + {$IFDEF WINDOWS} + appdata := GetEnvironmentVariable('APPDATA') + '\doom2df'; + if appdata <> '' then + AddDir(result, appdata); + {$ENDIF} + {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)} home := GetEnvironmentVariable('HOME'); if home <> '' then AddDir(result, e_CatPath(home, '.doom2df')); {$ENDIF} + {$IFDEF DARWIN} + dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true); + for i := 0 to dirArr.count - 1 do + begin + s := NSStringToAnsiString(dirArr.objectAtIndex(i)); + AddDir(result, e_CatPath(s, 'Doom 2D Forever')) + end; + {$ENDIF} {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)} if SDL_AndroidGetExternalStorageState() <> 0 then AddDir(result, SDL_AndroidGetExternalStoragePath()); {$ENDIF} end; - AddDir(result, '.'); + {$IFNDEF ANDROID} + {$IFDEF DARWIN} + bundle := GetBundlePath(); + if ExtractFileExt(bundle) <> '.app' then + if bundle = '' then + AddDir(result, ''); + {$ELSE} + AddDir(result, ''); + {$ENDIF} + {$ENDIF} end; begin diff --git a/src/shared/a_modes.inc b/src/shared/a_modes.inc index 68a0672..9b5d939 100644 --- a/src/shared/a_modes.inc +++ b/src/shared/a_modes.inc @@ -26,6 +26,9 @@ {$MODESWITCH TYPEHELPERS+} // Allow the use of type helpers. {$MODESWITCH UNICODESTRINGS-} +{$IFDEF DARWIN} + {$MODESWITCH OBJECTIVEC1} +{$ENDIF} {$ASSERTIONS ON} {$BITPACKING OFF} -- 2.29.2