mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-23 05:15:34 +00:00
Updates the SDL library to the latest standard bugfix release
This commit is contained in:
parent
cb766f2878
commit
083d2175ea
1280 changed files with 343926 additions and 179615 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -32,22 +32,20 @@
|
|||
#include "SDL_system.h"
|
||||
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
/* The current working directory is / on Android */
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
const char *path = SDL_AndroidGetInternalStoragePath();
|
||||
if (path) {
|
||||
size_t pathlen = SDL_strlen(path)+2;
|
||||
size_t pathlen = SDL_strlen(path) + 2;
|
||||
char *fullpath = (char *)SDL_malloc(pathlen);
|
||||
if (!fullpath) {
|
||||
if (fullpath == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -33,104 +33,106 @@
|
|||
#include "SDL_stdinc.h"
|
||||
#include "SDL_filesystem.h"
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
{ @autoreleasepool
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
const char* baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String];
|
||||
const char *base = NULL;
|
||||
char *retval = NULL;
|
||||
@autoreleasepool {
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
const char *baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String];
|
||||
const char *base = NULL;
|
||||
char *retval = NULL;
|
||||
|
||||
if (baseType == NULL) {
|
||||
baseType = "resource";
|
||||
}
|
||||
if (SDL_strcasecmp(baseType, "bundle")==0) {
|
||||
base = [[bundle bundlePath] fileSystemRepresentation];
|
||||
} else if (SDL_strcasecmp(baseType, "parent")==0) {
|
||||
base = [[[bundle bundlePath] stringByDeletingLastPathComponent] fileSystemRepresentation];
|
||||
} else {
|
||||
/* this returns the exedir for non-bundled and the resourceDir for bundled apps */
|
||||
base = [[bundle resourcePath] fileSystemRepresentation];
|
||||
}
|
||||
|
||||
if (base) {
|
||||
const size_t len = SDL_strlen(base) + 2;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s/", base);
|
||||
if (baseType == NULL) {
|
||||
baseType = "resource";
|
||||
}
|
||||
if (SDL_strcasecmp(baseType, "bundle") == 0) {
|
||||
base = [[bundle bundlePath] fileSystemRepresentation];
|
||||
} else if (SDL_strcasecmp(baseType, "parent") == 0) {
|
||||
base = [[[bundle bundlePath] stringByDeletingLastPathComponent] fileSystemRepresentation];
|
||||
} else {
|
||||
/* this returns the exedir for non-bundled and the resourceDir for bundled apps */
|
||||
base = [[bundle resourcePath] fileSystemRepresentation];
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
{ @autoreleasepool
|
||||
{
|
||||
if (!app) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
char *retval = NULL;
|
||||
#if !TARGET_OS_TV
|
||||
NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||
#else
|
||||
/* tvOS does not have persistent local storage!
|
||||
* The only place on-device where we can store data is
|
||||
* a cache directory that the OS can empty at any time.
|
||||
*
|
||||
* It's therefore very likely that save data will be erased
|
||||
* between sessions. If you want your app's save data to
|
||||
* actually stick around, you'll need to use iCloud storage.
|
||||
*/
|
||||
|
||||
static SDL_bool shown = SDL_FALSE;
|
||||
if (!shown)
|
||||
{
|
||||
shown = SDL_TRUE;
|
||||
SDL_LogCritical(SDL_LOG_CATEGORY_SYSTEM, "tvOS does not have persistent local storage! Use iCloud storage if you want your data to persist between sessions.\n");
|
||||
}
|
||||
|
||||
NSArray *array = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
#endif /* !TARGET_OS_TV */
|
||||
|
||||
if ([array count] > 0) { /* we only want the first item in the list. */
|
||||
NSString *str = [array objectAtIndex:0];
|
||||
const char *base = [str fileSystemRepresentation];
|
||||
if (base) {
|
||||
const size_t len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
const size_t len = SDL_strlen(base) + 2;
|
||||
retval = (char *)SDL_malloc(len);
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
} else {
|
||||
char *ptr;
|
||||
if (*org) {
|
||||
SDL_snprintf(retval, len, "%s/%s/%s/", base, org, app);
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s/%s/", base, app);
|
||||
}
|
||||
for (ptr = retval+1; *ptr; ptr++) {
|
||||
if (*ptr == '/') {
|
||||
*ptr = '\0';
|
||||
mkdir(retval, 0700);
|
||||
*ptr = '/';
|
||||
}
|
||||
}
|
||||
mkdir(retval, 0700);
|
||||
SDL_snprintf(retval, len, "%s/", base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}}
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
@autoreleasepool {
|
||||
char *retval = NULL;
|
||||
NSArray *array;
|
||||
|
||||
if (!app) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||
#else
|
||||
/* tvOS does not have persistent local storage!
|
||||
* The only place on-device where we can store data is
|
||||
* a cache directory that the OS can empty at any time.
|
||||
*
|
||||
* It's therefore very likely that save data will be erased
|
||||
* between sessions. If you want your app's save data to
|
||||
* actually stick around, you'll need to use iCloud storage.
|
||||
*/
|
||||
{
|
||||
static SDL_bool shown = SDL_FALSE;
|
||||
if (!shown) {
|
||||
shown = SDL_TRUE;
|
||||
SDL_LogCritical(SDL_LOG_CATEGORY_SYSTEM, "tvOS does not have persistent local storage! Use iCloud storage if you want your data to persist between sessions.\n");
|
||||
}
|
||||
}
|
||||
|
||||
array = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
#endif /* !TARGET_OS_TV */
|
||||
|
||||
if ([array count] > 0) { /* we only want the first item in the list. */
|
||||
NSString *str = [array objectAtIndex:0];
|
||||
const char *base = [str fileSystemRepresentation];
|
||||
if (base) {
|
||||
const size_t len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
|
||||
retval = (char *)SDL_malloc(len);
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
} else {
|
||||
char *ptr;
|
||||
if (*org) {
|
||||
SDL_snprintf(retval, len, "%s/%s/%s/", base, org, app);
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s/%s/", base, app);
|
||||
}
|
||||
for (ptr = retval + 1; *ptr; ptr++) {
|
||||
if (*ptr == '/') {
|
||||
*ptr = '\0';
|
||||
mkdir(retval, 0700);
|
||||
*ptr = '/';
|
||||
}
|
||||
}
|
||||
mkdir(retval, 0700);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_FILESYSTEM_COCOA */
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -28,15 +28,13 @@
|
|||
#include "SDL_error.h"
|
||||
#include "SDL_filesystem.h"
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -32,32 +32,30 @@
|
|||
|
||||
#include <emscripten/emscripten.h>
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
char *retval = "/";
|
||||
return SDL_strdup(retval);
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
const char *append = "/libsdl/";
|
||||
char *retval;
|
||||
char *ptr = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
len = SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
if (!retval) {
|
||||
retval = (char *)SDL_malloc(len);
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -68,17 +66,18 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
SDL_snprintf(retval, len, "%s%s/", append, app);
|
||||
}
|
||||
|
||||
for (ptr = retval+1; *ptr; ptr++) {
|
||||
for (ptr = retval + 1; *ptr; ptr++) {
|
||||
if (*ptr == '/') {
|
||||
*ptr = '\0';
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST)
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
|
||||
goto error;
|
||||
}
|
||||
*ptr = '/';
|
||||
}
|
||||
}
|
||||
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
|
||||
error:
|
||||
error:
|
||||
SDL_SetError("Couldn't create directory '%s': '%s'", retval, strerror(errno));
|
||||
SDL_free(retval);
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -34,8 +34,7 @@
|
|||
#include "SDL_stdinc.h"
|
||||
#include "SDL_filesystem.h"
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
image_info info;
|
||||
int32 cookie = 0;
|
||||
|
|
@ -57,7 +56,7 @@ SDL_GetBasePath(void)
|
|||
|
||||
const size_t len = SDL_strlen(str);
|
||||
char *retval = (char *) SDL_malloc(len + 2);
|
||||
if (!retval) {
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -69,19 +68,18 @@ SDL_GetBasePath(void)
|
|||
}
|
||||
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
// !!! FIXME: is there a better way to do this?
|
||||
const char *home = SDL_getenv("HOME");
|
||||
const char *append = "/config/settings/";
|
||||
size_t len = SDL_strlen(home);
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +88,7 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
}
|
||||
len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
|
||||
char *retval = (char *) SDL_malloc(len);
|
||||
if (!retval) {
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
} else {
|
||||
if (*org) {
|
||||
|
|
|
|||
89
Engine/lib/sdl/src/filesystem/n3ds/SDL_sysfilesystem.c
Normal file
89
Engine/lib/sdl/src/filesystem/n3ds/SDL_sysfilesystem.c
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifdef SDL_FILESYSTEM_N3DS
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* System dependent filesystem routines */
|
||||
|
||||
#include <3ds.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_filesystem.h"
|
||||
|
||||
SDL_FORCE_INLINE char *MakePrefPath(const char *app);
|
||||
SDL_FORCE_INLINE int CreatePrefPathDir(const char *pref);
|
||||
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
char *base_path = SDL_strdup("romfs:/");
|
||||
return base_path;
|
||||
}
|
||||
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
char *pref_path = NULL;
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pref_path = MakePrefPath(app);
|
||||
if (pref_path == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (CreatePrefPathDir(pref_path) < 0) {
|
||||
SDL_free(pref_path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pref_path;
|
||||
}
|
||||
|
||||
SDL_FORCE_INLINE char *
|
||||
MakePrefPath(const char *app)
|
||||
{
|
||||
char *pref_path;
|
||||
if (SDL_asprintf(&pref_path, "sdmc:/3ds/%s/", app) < 0) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
return pref_path;
|
||||
}
|
||||
|
||||
SDL_FORCE_INLINE int
|
||||
CreatePrefPathDir(const char *pref)
|
||||
{
|
||||
int result = mkdir(pref, 0666);
|
||||
|
||||
if (result == -1 && errno != EEXIST) {
|
||||
return SDL_SetError("Failed to create '%s' (%s)", pref, strerror(errno));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_FILESYSTEM_N3DS */
|
||||
|
||||
/* vi: set sts=4 ts=4 sw=4 expandtab: */
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -24,15 +24,13 @@
|
|||
|
||||
#ifdef SDL_FILESYSTEM_NACL
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -36,8 +36,7 @@
|
|||
#include <os2.h>
|
||||
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
PTIB tib;
|
||||
PPIB pib;
|
||||
|
|
@ -71,8 +70,7 @@ SDL_GetBasePath(void)
|
|||
return OS2_SysToUTF8(acBuf);
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
PSZ pszPath;
|
||||
CHAR acBuf[CCHMAXPATH];
|
||||
|
|
|
|||
110
Engine/lib/sdl/src/filesystem/ps2/SDL_sysfilesystem.c
Normal file
110
Engine/lib/sdl/src/filesystem/ps2/SDL_sysfilesystem.c
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(SDL_FILESYSTEM_PS2)
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* System dependent filesystem routines */
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_filesystem.h"
|
||||
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
char *retval;
|
||||
size_t len;
|
||||
char cwd[FILENAME_MAX];
|
||||
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
len = SDL_strlen(cwd) + 1;
|
||||
retval = (char *)SDL_malloc(len);
|
||||
if (retval) {
|
||||
SDL_memcpy(retval, cwd, len);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Do a recursive mkdir of parents folders */
|
||||
static void recursive_mkdir(const char *dir)
|
||||
{
|
||||
char tmp[FILENAME_MAX];
|
||||
char *base = SDL_GetBasePath();
|
||||
char *p = NULL;
|
||||
size_t len;
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%s", dir);
|
||||
len = strlen(tmp);
|
||||
if (tmp[len - 1] == '/') {
|
||||
tmp[len - 1] = 0;
|
||||
}
|
||||
|
||||
for (p = tmp + 1; *p; p++) {
|
||||
if (*p == '/') {
|
||||
*p = 0;
|
||||
// Just creating subfolders from current path
|
||||
if (strstr(tmp, base) != NULL) {
|
||||
mkdir(tmp, S_IRWXU);
|
||||
}
|
||||
|
||||
*p = '/';
|
||||
}
|
||||
}
|
||||
|
||||
free(base);
|
||||
mkdir(tmp, S_IRWXU);
|
||||
}
|
||||
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
char *retval = NULL;
|
||||
size_t len;
|
||||
char *base = SDL_GetBasePath();
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
|
||||
retval = (char *)SDL_malloc(len);
|
||||
|
||||
if (*org) {
|
||||
SDL_snprintf(retval, len, "%s%s/%s/", base, org, app);
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s%s/", base, app);
|
||||
}
|
||||
free(base);
|
||||
|
||||
recursive_mkdir(retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* SDL_FILESYSTEM_PS2 */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -31,8 +31,7 @@
|
|||
#include "SDL_error.h"
|
||||
#include "SDL_filesystem.h"
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
char *retval = NULL;
|
||||
size_t len;
|
||||
|
|
@ -40,28 +39,27 @@ SDL_GetBasePath(void)
|
|||
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
len = SDL_strlen(cwd) + 2;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
retval = (char *)SDL_malloc(len);
|
||||
SDL_snprintf(retval, len, "%s/", cwd);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
char *retval = NULL;
|
||||
size_t len;
|
||||
char *base = SDL_GetBasePath();
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if(!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
retval = (char *)SDL_malloc(len);
|
||||
|
||||
if (*org) {
|
||||
SDL_snprintf(retval, len, "%s%s/%s/", base, org, app);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -34,27 +34,27 @@
|
|||
#include "SDL_filesystem.h"
|
||||
|
||||
/* Wrapper around __unixify_std that uses SDL's memory allocators */
|
||||
static char *
|
||||
SDL_unixify_std(const char *ro_path, char *buffer, size_t buf_len, int filetype)
|
||||
static char *SDL_unixify_std(const char *ro_path, char *buffer, size_t buf_len, int filetype)
|
||||
{
|
||||
const char *const in_buf = buffer; /* = NULL if we allocate the buffer. */
|
||||
|
||||
if (!buffer) {
|
||||
if (buffer == NULL) {
|
||||
/* This matches the logic in __unixify, with an additional byte for the
|
||||
* extra path separator.
|
||||
*/
|
||||
buf_len = SDL_strlen(ro_path) + 14 + 1;
|
||||
buffer = SDL_malloc(buf_len);
|
||||
|
||||
if (!buffer) {
|
||||
if (buffer == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!__unixify_std(ro_path, buffer, buf_len, filetype)) {
|
||||
if (!in_buf)
|
||||
if (in_buf == NULL) {
|
||||
SDL_free(buffer);
|
||||
}
|
||||
|
||||
SDL_SetError("Could not convert '%s' to a Unix-style path", ro_path);
|
||||
return NULL;
|
||||
|
|
@ -72,8 +72,7 @@ SDL_unixify_std(const char *ro_path, char *buffer, size_t buf_len, int filetype)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
static char *
|
||||
canonicalisePath(const char *path, const char *pathVar)
|
||||
static char *canonicalisePath(const char *path, const char *pathVar)
|
||||
{
|
||||
_kernel_oserror *error;
|
||||
_kernel_swi_regs regs;
|
||||
|
|
@ -93,7 +92,7 @@ canonicalisePath(const char *path, const char *pathVar)
|
|||
|
||||
regs.r[5] = 1 - regs.r[5];
|
||||
buf = SDL_malloc(regs.r[5]);
|
||||
if (!buf) {
|
||||
if (buf == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -108,8 +107,7 @@ canonicalisePath(const char *path, const char *pathVar)
|
|||
return buf;
|
||||
}
|
||||
|
||||
static _kernel_oserror *
|
||||
createDirectoryRecursive(char *path)
|
||||
static _kernel_oserror *createDirectoryRecursive(char *path)
|
||||
{
|
||||
char *ptr = NULL;
|
||||
_kernel_oserror *error;
|
||||
|
|
@ -118,20 +116,20 @@ createDirectoryRecursive(char *path)
|
|||
regs.r[1] = (int)path;
|
||||
regs.r[2] = 0;
|
||||
|
||||
for (ptr = path+1; *ptr; ptr++) {
|
||||
for (ptr = path + 1; *ptr; ptr++) {
|
||||
if (*ptr == '.') {
|
||||
*ptr = '\0';
|
||||
error = _kernel_swi(OS_File, ®s, ®s);
|
||||
*ptr = '.';
|
||||
if (error != NULL)
|
||||
if (error != NULL) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
return _kernel_swi(OS_File, ®s, ®s);
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
_kernel_swi_regs regs;
|
||||
_kernel_oserror *error;
|
||||
|
|
@ -143,43 +141,43 @@ SDL_GetBasePath(void)
|
|||
}
|
||||
|
||||
canon = canonicalisePath((const char *)regs.r[0], "Run$Path");
|
||||
if (!canon) {
|
||||
if (canon == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* chop off filename. */
|
||||
ptr = SDL_strrchr(canon, '.');
|
||||
if (ptr != NULL)
|
||||
if (ptr != NULL) {
|
||||
*ptr = '\0';
|
||||
}
|
||||
|
||||
retval = SDL_unixify_std(canon, NULL, 0, __RISCOSIFY_FILETYPE_NOTSPECIFIED);
|
||||
SDL_free(canon);
|
||||
return retval;
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
char *canon, *dir, *retval;
|
||||
size_t len;
|
||||
_kernel_oserror *error;
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
canon = canonicalisePath("<Choices$Write>", "Run$Path");
|
||||
if (!canon) {
|
||||
if (canon == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = SDL_strlen(canon) + SDL_strlen(org) + SDL_strlen(app) + 4;
|
||||
dir = (char *) SDL_malloc(len);
|
||||
if (!dir) {
|
||||
dir = (char *)SDL_malloc(len);
|
||||
if (dir == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(canon);
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -45,16 +45,14 @@
|
|||
|
||||
/* QNX's /proc/self/exefile is a text file and not a symlink. */
|
||||
#if !defined(__QNXNTO__)
|
||||
static char *
|
||||
readSymLink(const char *path)
|
||||
static char *readSymLink(const char *path)
|
||||
{
|
||||
char *retval = NULL;
|
||||
ssize_t len = 64;
|
||||
ssize_t rc = -1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
char *ptr = (char *) SDL_realloc(retval, (size_t) len);
|
||||
while (1) {
|
||||
char *ptr = (char *)SDL_realloc(retval, (size_t)len);
|
||||
if (ptr == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
break;
|
||||
|
|
@ -64,13 +62,13 @@ readSymLink(const char *path)
|
|||
|
||||
rc = readlink(path, retval, len);
|
||||
if (rc == -1) {
|
||||
break; /* not a symlink, i/o error, etc. */
|
||||
break; /* not a symlink, i/o error, etc. */
|
||||
} else if (rc < len) {
|
||||
retval[rc] = '\0'; /* readlink doesn't null-terminate. */
|
||||
return retval; /* we're good to go. */
|
||||
retval[rc] = '\0'; /* readlink doesn't null-terminate. */
|
||||
return retval; /* we're good to go. */
|
||||
}
|
||||
|
||||
len *= 2; /* grow buffer, try again. */
|
||||
len *= 2; /* grow buffer, try again. */
|
||||
}
|
||||
|
||||
SDL_free(retval);
|
||||
|
|
@ -88,13 +86,13 @@ static char *search_path_for_binary(const char *bin)
|
|||
char *start = envr;
|
||||
char *ptr;
|
||||
|
||||
if (!envr) {
|
||||
if (envr == NULL) {
|
||||
SDL_SetError("No $PATH set");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
envr = SDL_strdup(envr);
|
||||
if (!envr) {
|
||||
if (envr == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -102,10 +100,10 @@ static char *search_path_for_binary(const char *bin)
|
|||
SDL_assert(bin != NULL);
|
||||
|
||||
alloc_size = SDL_strlen(bin) + SDL_strlen(envr) + 2;
|
||||
exe = (char *) SDL_malloc(alloc_size);
|
||||
exe = (char *)SDL_malloc(alloc_size);
|
||||
|
||||
do {
|
||||
ptr = SDL_strchr(start, ':'); /* find next $PATH separator. */
|
||||
ptr = SDL_strchr(start, ':'); /* find next $PATH separator. */
|
||||
if (ptr != start) {
|
||||
if (ptr) {
|
||||
*ptr = '\0';
|
||||
|
|
@ -119,51 +117,48 @@ static char *search_path_for_binary(const char *bin)
|
|||
return exe;
|
||||
}
|
||||
}
|
||||
start = ptr + 1; /* start points to beginning of next element. */
|
||||
start = ptr + 1; /* start points to beginning of next element. */
|
||||
} while (ptr != NULL);
|
||||
|
||||
SDL_free(envr);
|
||||
SDL_free(exe);
|
||||
|
||||
SDL_SetError("Process not found in $PATH");
|
||||
return NULL; /* doesn't exist in path. */
|
||||
return NULL; /* doesn't exist in path. */
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
char *retval = NULL;
|
||||
|
||||
#if defined(__FREEBSD__)
|
||||
char fullpath[PATH_MAX];
|
||||
size_t buflen = sizeof (fullpath);
|
||||
size_t buflen = sizeof(fullpath);
|
||||
const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
|
||||
if (sysctl(mib, SDL_arraysize(mib), fullpath, &buflen, NULL, 0) != -1) {
|
||||
retval = SDL_strdup(fullpath);
|
||||
if (!retval) {
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(__OPENBSD__)
|
||||
/* Please note that this will fail if the process was launched with a relative path and the cwd has changed, or argv is altered. So don't do that. Or add a new sysctl to OpenBSD. */
|
||||
/* Please note that this will fail if the process was launched with a relative path and $PWD + the cwd have changed, or argv is altered. So don't do that. Or add a new sysctl to OpenBSD. */
|
||||
char **cmdline;
|
||||
size_t len;
|
||||
const int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
|
||||
if (sysctl(mib, 4, NULL, &len, NULL, 0) != -1) {
|
||||
char *exe;
|
||||
char *realpathbuf = (char *) SDL_malloc(PATH_MAX + 1);
|
||||
if (!realpathbuf) {
|
||||
char *exe, *pwddst;
|
||||
char *realpathbuf = (char *)SDL_malloc(PATH_MAX + 1);
|
||||
if (realpathbuf == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cmdline = SDL_malloc(len);
|
||||
if (!cmdline) {
|
||||
if (cmdline == NULL) {
|
||||
SDL_free(realpathbuf);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
|
|
@ -172,13 +167,28 @@ SDL_GetBasePath(void)
|
|||
sysctl(mib, 4, cmdline, &len, NULL, 0);
|
||||
|
||||
exe = cmdline[0];
|
||||
if (SDL_strchr(exe, '/') == NULL) { /* not a relative or absolute path, check $PATH for it */
|
||||
pwddst = NULL;
|
||||
if (SDL_strchr(exe, '/') == NULL) { /* not a relative or absolute path, check $PATH for it */
|
||||
exe = search_path_for_binary(cmdline[0]);
|
||||
} else {
|
||||
if (exe && *exe == '.') {
|
||||
const char *pwd = SDL_getenv("PWD");
|
||||
if (pwd && *pwd) {
|
||||
SDL_asprintf(&pwddst, "%s/%s", pwd, exe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (exe) {
|
||||
if (realpath(exe, realpathbuf) != NULL) {
|
||||
retval = realpathbuf;
|
||||
if (pwddst == NULL) {
|
||||
if (realpath(exe, realpathbuf) != NULL) {
|
||||
retval = realpathbuf;
|
||||
}
|
||||
} else {
|
||||
if (realpath(pwddst, realpathbuf) != NULL) {
|
||||
retval = realpathbuf;
|
||||
}
|
||||
SDL_free(pwddst);
|
||||
}
|
||||
|
||||
if (exe != cmdline[0]) {
|
||||
|
|
@ -186,26 +196,16 @@ SDL_GetBasePath(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (!retval) {
|
||||
if (retval == NULL) {
|
||||
SDL_free(realpathbuf);
|
||||
}
|
||||
|
||||
SDL_free(cmdline);
|
||||
}
|
||||
#endif
|
||||
#if defined(__SOLARIS__)
|
||||
const char *path = getexecname();
|
||||
if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
|
||||
retval = SDL_strdup(path);
|
||||
if (!retval) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* is a Linux-style /proc filesystem available? */
|
||||
if (!retval && (access("/proc", F_OK) == 0)) {
|
||||
if (retval == NULL && (access("/proc", F_OK) == 0)) {
|
||||
/* !!! FIXME: after 2.0.6 ships, let's delete this code and just
|
||||
use the /proc/%llu version. There's no reason to have
|
||||
two copies of this plus all the #ifdefs. --ryan. */
|
||||
|
|
@ -213,31 +213,46 @@ SDL_GetBasePath(void)
|
|||
retval = readSymLink("/proc/curproc/file");
|
||||
#elif defined(__NETBSD__)
|
||||
retval = readSymLink("/proc/curproc/exe");
|
||||
#elif defined(__SOLARIS__)
|
||||
retval = readSymLink("/proc/self/path/a.out");
|
||||
#elif defined(__QNXNTO__)
|
||||
retval = SDL_LoadFile("/proc/self/exefile", NULL);
|
||||
#else
|
||||
retval = readSymLink("/proc/self/exe"); /* linux. */
|
||||
retval = readSymLink("/proc/self/exe"); /* linux. */
|
||||
if (retval == NULL) {
|
||||
/* older kernels don't have /proc/self ... try PID version... */
|
||||
char path[64];
|
||||
const int rc = SDL_snprintf(path, sizeof(path),
|
||||
"/proc/%llu/exe",
|
||||
(unsigned long long) getpid());
|
||||
if ( (rc > 0) && (rc < sizeof(path)) ) {
|
||||
"/proc/%llu/exe",
|
||||
(unsigned long long)getpid());
|
||||
if ((rc > 0) && (rc < sizeof(path))) {
|
||||
retval = readSymLink(path);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__SOLARIS__) /* try this as a fallback if /proc didn't pan out */
|
||||
if (!retval) {
|
||||
const char *path = getexecname();
|
||||
if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
|
||||
retval = SDL_strdup(path);
|
||||
if (!retval) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If we had access to argv[0] here, we could check it for a path,
|
||||
or troll through $PATH looking for it, too. */
|
||||
|
||||
if (retval != NULL) { /* chop off filename. */
|
||||
char *ptr = SDL_strrchr(retval, '/');
|
||||
if (ptr != NULL) {
|
||||
*(ptr+1) = '\0';
|
||||
} else { /* shouldn't happen, but just in case... */
|
||||
*(ptr + 1) = '\0';
|
||||
} else { /* shouldn't happen, but just in case... */
|
||||
SDL_free(retval);
|
||||
retval = NULL;
|
||||
}
|
||||
|
|
@ -245,16 +260,16 @@ SDL_GetBasePath(void)
|
|||
|
||||
if (retval != NULL) {
|
||||
/* try to shrink buffer... */
|
||||
char *ptr = (char *) SDL_realloc(retval, SDL_strlen(retval) + 1);
|
||||
if (ptr != NULL)
|
||||
retval = ptr; /* oh well if it failed. */
|
||||
char *ptr = (char *)SDL_realloc(retval, SDL_strlen(retval) + 1);
|
||||
if (ptr != NULL) {
|
||||
retval = ptr; /* oh well if it failed. */
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
/*
|
||||
* We use XDG's base directory spec, even if you're not on Linux.
|
||||
|
|
@ -269,18 +284,18 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
char *ptr = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
if (!envr) {
|
||||
if (envr == NULL) {
|
||||
/* You end up with "$HOME/.local/share/Game Name 2" */
|
||||
envr = SDL_getenv("HOME");
|
||||
if (!envr) {
|
||||
if (envr == NULL) {
|
||||
/* we could take heroic measures with /etc/passwd, but oh well. */
|
||||
SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
|
||||
return NULL;
|
||||
|
|
@ -291,32 +306,34 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
}
|
||||
|
||||
len = SDL_strlen(envr);
|
||||
if (envr[len - 1] == '/')
|
||||
if (envr[len - 1] == '/') {
|
||||
append += 1;
|
||||
}
|
||||
|
||||
len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
if (!retval) {
|
||||
retval = (char *)SDL_malloc(len);
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*org) {
|
||||
SDL_snprintf(retval, len, "%s%s%s/%s/", envr, append, org, app);
|
||||
(void)SDL_snprintf(retval, len, "%s%s%s/%s/", envr, append, org, app);
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s%s%s/", envr, append, app);
|
||||
(void)SDL_snprintf(retval, len, "%s%s%s/", envr, append, app);
|
||||
}
|
||||
|
||||
for (ptr = retval+1; *ptr; ptr++) {
|
||||
for (ptr = retval + 1; *ptr; ptr++) {
|
||||
if (*ptr == '/') {
|
||||
*ptr = '\0';
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST)
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
|
||||
goto error;
|
||||
}
|
||||
*ptr = '/';
|
||||
}
|
||||
}
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
|
||||
error:
|
||||
error:
|
||||
SDL_SetError("Couldn't create directory '%s': '%s'", retval, strerror(errno));
|
||||
SDL_free(retval);
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -39,35 +39,33 @@
|
|||
#include "SDL_filesystem.h"
|
||||
#include "SDL_rwops.h"
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
const char *basepath = "app0:/";
|
||||
char *retval = SDL_strdup(basepath);
|
||||
return retval;
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
const char *envr = "ux0:/data/";
|
||||
char *retval = NULL;
|
||||
char *ptr = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
len = SDL_strlen(envr);
|
||||
|
||||
len += SDL_strlen(org) + SDL_strlen(app) + 3;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
if (!retval) {
|
||||
retval = (char *)SDL_malloc(len);
|
||||
if (retval == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -78,7 +76,7 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
SDL_snprintf(retval, len, "%s%s/", envr, app);
|
||||
}
|
||||
|
||||
for (ptr = retval+1; *ptr; ptr++) {
|
||||
for (ptr = retval + 1; *ptr; ptr++) {
|
||||
if (*ptr == '/') {
|
||||
*ptr = '\0';
|
||||
sceIoMkdir(retval, 0777);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -32,8 +32,7 @@
|
|||
#include "SDL_stdinc.h"
|
||||
#include "SDL_filesystem.h"
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
DWORD buflen = 128;
|
||||
WCHAR *path = NULL;
|
||||
|
|
@ -42,14 +41,14 @@ SDL_GetBasePath(void)
|
|||
int i;
|
||||
|
||||
while (SDL_TRUE) {
|
||||
void *ptr = SDL_realloc(path, buflen * sizeof (WCHAR));
|
||||
if (!ptr) {
|
||||
void *ptr = SDL_realloc(path, buflen * sizeof(WCHAR));
|
||||
if (ptr == NULL) {
|
||||
SDL_free(path);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
path = (WCHAR *) ptr;
|
||||
path = (WCHAR *)ptr;
|
||||
|
||||
len = GetModuleFileNameW(NULL, path, buflen);
|
||||
/* if it truncated, then len >= buflen - 1 */
|
||||
|
|
@ -68,14 +67,14 @@ SDL_GetBasePath(void)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
for (i = len-1; i > 0; i--) {
|
||||
for (i = len - 1; i > 0; i--) {
|
||||
if (path[i] == '\\') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_assert(i > 0); /* Should have been an absolute path. */
|
||||
path[i+1] = '\0'; /* chop off filename. */
|
||||
SDL_assert(i > 0); /* Should have been an absolute path. */
|
||||
path[i + 1] = '\0'; /* chop off filename. */
|
||||
|
||||
retval = WIN_StringToUTF8W(path);
|
||||
SDL_free(path);
|
||||
|
|
@ -83,8 +82,7 @@ SDL_GetBasePath(void)
|
|||
return retval;
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
/*
|
||||
* Vista and later has a new API for this, but SHGetFolderPath works there,
|
||||
|
|
@ -96,16 +94,16 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
|
||||
WCHAR path[MAX_PATH];
|
||||
char *retval = NULL;
|
||||
WCHAR* worg = NULL;
|
||||
WCHAR* wapp = NULL;
|
||||
WCHAR *worg = NULL;
|
||||
WCHAR *wapp = NULL;
|
||||
size_t new_wpath_len = 0;
|
||||
BOOL api_result = FALSE;
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
|
|
@ -172,4 +170,20 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
|
||||
#endif /* SDL_FILESYSTEM_WINDOWS */
|
||||
|
||||
#ifdef SDL_FILESYSTEM_XBOX
|
||||
#include "SDL_filesystem.h"
|
||||
#include "SDL_error.h"
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
}
|
||||
#endif /* SDL_FILESYSTEM_XBOX */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
#include "../../SDL_internal.h"
|
||||
|
||||
/* TODO, WinRT: remove the need to compile this with C++/CX (/ZW) extensions, and if possible, without C++ at all
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifdef __WINRT__
|
||||
|
||||
|
|
@ -44,55 +44,55 @@ extern "C" const wchar_t *
|
|||
SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
|
||||
{
|
||||
switch (pathType) {
|
||||
case SDL_WINRT_PATH_INSTALLED_LOCATION:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
case SDL_WINRT_PATH_INSTALLED_LOCATION:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
#if defined(NTDDI_WIN10_19H1) && (NTDDI_VERSION >= NTDDI_WIN10_19H1) && (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP) /* Only PC supports mods */
|
||||
/* Windows 1903 supports mods, via the EffectiveLocation API */
|
||||
if (Windows::Foundation::Metadata::ApiInformation::IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8, 0)) {
|
||||
path = Windows::ApplicationModel::Package::Current->EffectiveLocation->Path->Data();
|
||||
} else {
|
||||
path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
|
||||
}
|
||||
#else
|
||||
/* Windows 1903 supports mods, via the EffectiveLocation API */
|
||||
if (Windows::Foundation::Metadata::ApiInformation::IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8, 0)) {
|
||||
path = Windows::ApplicationModel::Package::Current->EffectiveLocation->Path->Data();
|
||||
} else {
|
||||
path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
|
||||
}
|
||||
#else
|
||||
path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
|
||||
#endif
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
|
||||
case SDL_WINRT_PATH_LOCAL_FOLDER:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = ApplicationData::Current->LocalFolder->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
case SDL_WINRT_PATH_LOCAL_FOLDER:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = ApplicationData::Current->LocalFolder->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
|
||||
#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (NTDDI_VERSION > NTDDI_WIN8)
|
||||
case SDL_WINRT_PATH_ROAMING_FOLDER:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = ApplicationData::Current->RoamingFolder->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
case SDL_WINRT_PATH_ROAMING_FOLDER:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = ApplicationData::Current->RoamingFolder->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
|
||||
case SDL_WINRT_PATH_TEMP_FOLDER:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = ApplicationData::Current->TemporaryFolder->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
case SDL_WINRT_PATH_TEMP_FOLDER:
|
||||
{
|
||||
static wstring path;
|
||||
if (path.empty()) {
|
||||
path = ApplicationData::Current->TemporaryFolder->Path->Data();
|
||||
}
|
||||
return path.c_str();
|
||||
}
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_Unsupported();
|
||||
|
|
@ -110,12 +110,12 @@ SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
|
|||
return searchResult->second.c_str();
|
||||
}
|
||||
|
||||
const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
|
||||
if (!ucs2Path) {
|
||||
const wchar_t *ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
|
||||
if (ucs2Path == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char * utf8Path = WIN_StringToUTF8(ucs2Path);
|
||||
char *utf8Path = WIN_StringToUTF8(ucs2Path);
|
||||
utf8Paths[pathType] = utf8Path;
|
||||
SDL_free(utf8Path);
|
||||
return utf8Paths[pathType].c_str();
|
||||
|
|
@ -124,18 +124,18 @@ SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
|
|||
extern "C" char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION);
|
||||
const char *srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION);
|
||||
size_t destPathLen;
|
||||
char * destPath = NULL;
|
||||
char *destPath = NULL;
|
||||
|
||||
if (!srcPath) {
|
||||
if (srcPath == NULL) {
|
||||
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
destPathLen = SDL_strlen(srcPath) + 2;
|
||||
destPath = (char *) SDL_malloc(destPathLen);
|
||||
if (!destPath) {
|
||||
destPath = (char *)SDL_malloc(destPathLen);
|
||||
if (destPath == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -153,24 +153,24 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
* without violating Microsoft's app-store requirements.
|
||||
*/
|
||||
|
||||
const WCHAR * srcPath = NULL;
|
||||
const WCHAR *srcPath = NULL;
|
||||
WCHAR path[MAX_PATH];
|
||||
char *retval = NULL;
|
||||
WCHAR* worg = NULL;
|
||||
WCHAR* wapp = NULL;
|
||||
WCHAR *worg = NULL;
|
||||
WCHAR *wapp = NULL;
|
||||
size_t new_wpath_len = 0;
|
||||
BOOL api_result = FALSE;
|
||||
|
||||
if (!app) {
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if (!org) {
|
||||
if (org == NULL) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
srcPath = SDL_WinRTGetFSPathUNICODE(SDL_WINRT_PATH_LOCAL_FOLDER);
|
||||
if ( ! srcPath) {
|
||||
if (srcPath == NULL) {
|
||||
SDL_SetError("Unable to find a source path");
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue