mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-14 16:41:13 +00:00
- replaced deprecated macOS functions in paths handling
This commit is contained in:
parent
fc7af31cb9
commit
5c7dd28f7d
4 changed files with 97 additions and 111 deletions
|
@ -34,10 +34,6 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#include <CoreServices/CoreServices.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "gameconfigfile.h"
|
#include "gameconfigfile.h"
|
||||||
#include "c_cvars.h"
|
#include "c_cvars.h"
|
||||||
#include "c_dispatch.h"
|
#include "c_dispatch.h"
|
||||||
|
@ -69,39 +65,9 @@ FGameConfigFile::FGameConfigFile ()
|
||||||
{
|
{
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
FString user_docs, user_app_support, local_app_support;
|
FString user_docs, user_app_support, local_app_support;
|
||||||
{
|
M_GetMacSearchDirectories(user_docs, user_app_support, local_app_support);
|
||||||
char cpath[PATH_MAX];
|
|
||||||
FSRef folder;
|
|
||||||
|
|
||||||
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
|
||||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
|
||||||
{
|
|
||||||
user_docs << cpath << "/" GAME_DIR;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
user_docs = "~/" GAME_DIR;
|
|
||||||
}
|
|
||||||
if (noErr == FSFindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder, &folder) &&
|
|
||||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
|
||||||
{
|
|
||||||
user_app_support << cpath << "/" GAME_DIR;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
user_app_support = "~/Library/Application Support/" GAME_DIR;
|
|
||||||
}
|
|
||||||
if (noErr == FSFindFolder(kLocalDomain, kApplicationSupportFolderType, kCreateFolder, &folder) &&
|
|
||||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
|
||||||
{
|
|
||||||
local_app_support << cpath << "/" GAME_DIR;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
local_app_support = "Library/Application Support/" GAME_DIR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FString pathname;
|
FString pathname;
|
||||||
|
|
||||||
OkayToWrite = false; // Do not allow saving of the config before DoGameSetup()
|
OkayToWrite = false; // Do not allow saving of the config before DoGameSetup()
|
||||||
|
|
|
@ -62,4 +62,9 @@ FString M_GetScreenshotsPath();
|
||||||
FString M_GetSavegamesPath();
|
FString M_GetSavegamesPath();
|
||||||
FString M_GetDocumentsPath();
|
FString M_GetDocumentsPath();
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
FString M_GetMacAppSupportPath(const bool create = true);
|
||||||
|
void M_GetMacSearchDirectories(FString& user_docs, FString& user_app_support, FString& local_app_support);
|
||||||
|
#endif // __APPLE__
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <CoreServices/CoreServices.h>
|
#include "m_misc.h"
|
||||||
#endif // __APPLE__
|
#endif // __APPLE__
|
||||||
|
|
||||||
#include "doomerrors.h"
|
#include "doomerrors.h"
|
||||||
|
@ -172,19 +172,7 @@ TArray<FString> I_GetSteamPath()
|
||||||
// we need to figure out on an app-by-app basis where the game is installed.
|
// we need to figure out on an app-by-app basis where the game is installed.
|
||||||
// To do so, we read the virtual registry.
|
// To do so, we read the virtual registry.
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
FString appSupportPath;
|
const FString appSupportPath = M_GetMacAppSupportPath();
|
||||||
|
|
||||||
{
|
|
||||||
char cpath[PATH_MAX];
|
|
||||||
FSRef folder;
|
|
||||||
|
|
||||||
if (noErr == FSFindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder, &folder) &&
|
|
||||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
|
||||||
{
|
|
||||||
appSupportPath = cpath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FString regPath = appSupportPath + "/Steam/config/config.vdf";
|
FString regPath = appSupportPath + "/Steam/config/config.vdf";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,12 +33,59 @@
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <CoreServices/CoreServices.h>
|
#import <Foundation/NSFileManager.h>
|
||||||
|
|
||||||
#include "cmdlib.h"
|
#include "cmdlib.h"
|
||||||
#include "m_misc.h"
|
#include "m_misc.h"
|
||||||
#include "version.h" // for GAMENAME
|
#include "version.h" // for GAMENAME
|
||||||
|
|
||||||
|
|
||||||
|
static FString GetSpecialPath(const NSSearchPathDirectory kind, const BOOL create = YES, const NSSearchPathDomainMask domain = NSUserDomainMask)
|
||||||
|
{
|
||||||
|
NSURL* url = [[NSFileManager defaultManager] URLForDirectory:kind
|
||||||
|
inDomain:domain
|
||||||
|
appropriateForURL:nil
|
||||||
|
create:create
|
||||||
|
error:nil];
|
||||||
|
char utf8path[PATH_MAX];
|
||||||
|
|
||||||
|
if ([url getFileSystemRepresentation:utf8path
|
||||||
|
maxLength:sizeof utf8path])
|
||||||
|
{
|
||||||
|
return utf8path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FString();
|
||||||
|
}
|
||||||
|
|
||||||
|
FString M_GetMacAppSupportPath(const bool create)
|
||||||
|
{
|
||||||
|
return GetSpecialPath(NSApplicationSupportDirectory, create);
|
||||||
|
}
|
||||||
|
|
||||||
|
void M_GetMacSearchDirectories(FString& user_docs, FString& user_app_support, FString& local_app_support)
|
||||||
|
{
|
||||||
|
FString path = GetSpecialPath(NSDocumentDirectory);
|
||||||
|
user_docs = path.IsEmpty()
|
||||||
|
? "~/" GAME_DIR
|
||||||
|
: (path + "/" GAME_DIR);
|
||||||
|
|
||||||
|
#define LIBRARY_APPSUPPORT "/Library/Application Support/"
|
||||||
|
|
||||||
|
path = M_GetMacAppSupportPath();
|
||||||
|
user_app_support = path.IsEmpty()
|
||||||
|
? "~" LIBRARY_APPSUPPORT GAME_DIR
|
||||||
|
: (path + "/" GAME_DIR);
|
||||||
|
|
||||||
|
path = GetSpecialPath(NSApplicationSupportDirectory, YES, NSLocalDomainMask);
|
||||||
|
local_app_support = path.IsEmpty()
|
||||||
|
? LIBRARY_APPSUPPORT GAME_DIR
|
||||||
|
: (path + "/" GAME_DIR);
|
||||||
|
|
||||||
|
#undef LIBRARY_APPSUPPORT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//
|
//
|
||||||
// M_GetAppDataPath macOS
|
// M_GetAppDataPath macOS
|
||||||
|
@ -49,20 +96,13 @@
|
||||||
|
|
||||||
FString M_GetAppDataPath(bool create)
|
FString M_GetAppDataPath(bool create)
|
||||||
{
|
{
|
||||||
FString path;
|
FString path = M_GetMacAppSupportPath(create);
|
||||||
|
|
||||||
char pathstr[PATH_MAX];
|
if (path.IsEmpty())
|
||||||
FSRef folder;
|
|
||||||
|
|
||||||
if (noErr == FSFindFolder(kUserDomain, kApplicationSupportFolderType, create ? kCreateFolder : 0, &folder) &&
|
|
||||||
noErr == FSRefMakePath(&folder, (UInt8*)pathstr, PATH_MAX))
|
|
||||||
{
|
|
||||||
path = pathstr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
path = progdir;
|
path = progdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
path += "/" GAMENAMELOWERCASE;
|
path += "/" GAMENAMELOWERCASE;
|
||||||
if (create) CreatePath(path);
|
if (create) CreatePath(path);
|
||||||
return path;
|
return path;
|
||||||
|
@ -78,20 +118,13 @@ FString M_GetAppDataPath(bool create)
|
||||||
|
|
||||||
FString M_GetCachePath(bool create)
|
FString M_GetCachePath(bool create)
|
||||||
{
|
{
|
||||||
FString path;
|
FString path = M_GetMacAppSupportPath(create);
|
||||||
|
|
||||||
char pathstr[PATH_MAX];
|
if (path.IsEmpty())
|
||||||
FSRef folder;
|
|
||||||
|
|
||||||
if (noErr == FSFindFolder(kUserDomain, kApplicationSupportFolderType, create ? kCreateFolder : 0, &folder) &&
|
|
||||||
noErr == FSRefMakePath(&folder, (UInt8*)pathstr, PATH_MAX))
|
|
||||||
{
|
|
||||||
path = pathstr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
path = progdir;
|
path = progdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
path += "/zdoom/cache";
|
path += "/zdoom/cache";
|
||||||
if (create) CreatePath(path);
|
if (create) CreatePath(path);
|
||||||
return path;
|
return path;
|
||||||
|
@ -107,16 +140,13 @@ FString M_GetCachePath(bool create)
|
||||||
|
|
||||||
FString M_GetAutoexecPath()
|
FString M_GetAutoexecPath()
|
||||||
{
|
{
|
||||||
FString path;
|
FString path = GetSpecialPath(NSDocumentDirectory);
|
||||||
|
|
||||||
char cpath[PATH_MAX];
|
if (path.IsNotEmpty())
|
||||||
FSRef folder;
|
|
||||||
|
|
||||||
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
|
||||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
|
||||||
{
|
{
|
||||||
path << cpath << "/" GAME_DIR "/autoexec.cfg";
|
path += "/" GAME_DIR "/autoexec.cfg";
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,18 +183,21 @@ FString M_GetCajunPath(const char *botfilename)
|
||||||
|
|
||||||
FString M_GetConfigPath(bool for_reading)
|
FString M_GetConfigPath(bool for_reading)
|
||||||
{
|
{
|
||||||
char cpath[PATH_MAX];
|
FString path = GetSpecialPath(NSLibraryDirectory);
|
||||||
FSRef folder;
|
|
||||||
|
|
||||||
if (noErr == FSFindFolder(kUserDomain, kPreferencesFolderType, kCreateFolder, &folder) &&
|
if (path.IsNotEmpty())
|
||||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
|
||||||
{
|
{
|
||||||
FString path;
|
// There seems to be no way to get Preferences path via NSFileManager
|
||||||
path << cpath << "/" GAMENAMELOWERCASE ".ini";
|
path += "/Preferences/";
|
||||||
return path;
|
CreatePath(path);
|
||||||
|
|
||||||
|
if (!DirExists(path))
|
||||||
|
{
|
||||||
|
path = FString();
|
||||||
}
|
}
|
||||||
// Ungh.
|
}
|
||||||
return GAMENAMELOWERCASE ".ini";
|
|
||||||
|
return path + GAMENAMELOWERCASE ".ini";
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
@ -177,19 +210,17 @@ FString M_GetConfigPath(bool for_reading)
|
||||||
|
|
||||||
FString M_GetScreenshotsPath()
|
FString M_GetScreenshotsPath()
|
||||||
{
|
{
|
||||||
FString path;
|
FString path = GetSpecialPath(NSDocumentDirectory);
|
||||||
char cpath[PATH_MAX];
|
|
||||||
FSRef folder;
|
|
||||||
|
|
||||||
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
if (path.IsEmpty())
|
||||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
|
||||||
{
|
|
||||||
path << cpath << "/" GAME_DIR "/Screenshots/";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
path = "~/";
|
path = "~/";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path += "/" GAME_DIR "/Screenshots/";
|
||||||
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,21 +234,19 @@ FString M_GetScreenshotsPath()
|
||||||
|
|
||||||
FString M_GetSavegamesPath()
|
FString M_GetSavegamesPath()
|
||||||
{
|
{
|
||||||
FString path;
|
FString path = GetSpecialPath(NSDocumentDirectory);
|
||||||
char cpath[PATH_MAX];
|
|
||||||
FSRef folder;
|
|
||||||
|
|
||||||
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
if (path.IsNotEmpty())
|
||||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
|
||||||
{
|
{
|
||||||
path << cpath << "/" GAME_DIR "/Savegames/";
|
path += "/" GAME_DIR "/Savegames/";
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//
|
//
|
||||||
// M_GetDocumentsPath Unix
|
// M_GetDocumentsPath macOS
|
||||||
//
|
//
|
||||||
// Returns the path to the default documents directory.
|
// Returns the path to the default documents directory.
|
||||||
//
|
//
|
||||||
|
@ -225,14 +254,12 @@ FString M_GetSavegamesPath()
|
||||||
|
|
||||||
FString M_GetDocumentsPath()
|
FString M_GetDocumentsPath()
|
||||||
{
|
{
|
||||||
FString path;
|
FString path = GetSpecialPath(NSDocumentDirectory);
|
||||||
char cpath[PATH_MAX];
|
|
||||||
FSRef folder;
|
|
||||||
|
|
||||||
if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
|
if (path.IsNotEmpty())
|
||||||
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
|
|
||||||
{
|
{
|
||||||
path << cpath << "/" GAME_DIR "/";
|
path += "/" GAME_DIR "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue