forked from Green-Sky/tomato
update sdl Merge commit '644725478f4de0f074a6834e8423ac36dce3974f'
This commit is contained in:
140
external/sdl/SDL/src/filesystem/gdk/SDL_sysfilesystem.cpp
vendored
Normal file
140
external/sdl/SDL/src/filesystem/gdk/SDL_sysfilesystem.cpp
vendored
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
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_XBOX
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* System dependent filesystem routines */
|
||||
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_system.h"
|
||||
#include "SDL_filesystem.h"
|
||||
#include <XGameSaveFiles.h>
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
/* NOTE: This function is a UTF8 version of the Win32 SDL_GetBasePath()!
|
||||
* The GDK actually _recommends_ the 'A' functions over the 'W' functions :o
|
||||
*/
|
||||
DWORD buflen = 128;
|
||||
CHAR *path = NULL;
|
||||
DWORD len = 0;
|
||||
int i;
|
||||
|
||||
while (SDL_TRUE) {
|
||||
void *ptr = SDL_realloc(path, buflen * sizeof(CHAR));
|
||||
if (ptr == NULL) {
|
||||
SDL_free(path);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
path = (CHAR *)ptr;
|
||||
|
||||
len = GetModuleFileNameA(NULL, path, buflen);
|
||||
/* if it truncated, then len >= buflen - 1 */
|
||||
/* if there was enough room (or failure), len < buflen - 1 */
|
||||
if (len < buflen - 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* buffer too small? Try again. */
|
||||
buflen *= 2;
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
SDL_free(path);
|
||||
WIN_SetError("Couldn't locate our .exe");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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. */
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
XUserHandle user = NULL;
|
||||
XAsyncBlock block = { 0 };
|
||||
char *folderPath;
|
||||
HRESULT result;
|
||||
const char *csid = SDL_GetHint("SDL_GDK_SERVICE_CONFIGURATION_ID");
|
||||
|
||||
if (app == NULL) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* This should be set before calling SDL_GetPrefPath! */
|
||||
if (csid == NULL) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_SYSTEM, "Set SDL_GDK_SERVICE_CONFIGURATION_ID before calling SDL_GetPrefPath!");
|
||||
return SDL_strdup("T:\\");
|
||||
}
|
||||
|
||||
if (SDL_GDKGetDefaultUser(&user) < 0) {
|
||||
/* Error already set, just return */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (FAILED(result = XGameSaveFilesGetFolderWithUiAsync(user, csid, &block))) {
|
||||
WIN_SetErrorFromHRESULT("XGameSaveFilesGetFolderWithUiAsync", result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
folderPath = (char*) SDL_malloc(MAX_PATH);
|
||||
do {
|
||||
result = XGameSaveFilesGetFolderWithUiResult(&block, MAX_PATH, folderPath);
|
||||
} while (result == E_PENDING);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT("XGameSaveFilesGetFolderWithUiResult", result);
|
||||
SDL_free(folderPath);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* We aren't using 'app' here because the container rules are a lot more
|
||||
* strict than the NTFS rules, so it will most likely be invalid :(
|
||||
*/
|
||||
SDL_strlcat(folderPath, "\\SDLPrefPath\\", MAX_PATH);
|
||||
if (CreateDirectoryA(folderPath, NULL) == FALSE) {
|
||||
if (GetLastError() != ERROR_ALREADY_EXISTS) {
|
||||
WIN_SetError("CreateDirectoryA");
|
||||
SDL_free(folderPath);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return folderPath;
|
||||
}
|
||||
|
||||
#endif /* SDL_FILESYSTEM_XBOX */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
@ -332,23 +332,3 @@ done:
|
||||
return retval;
|
||||
}
|
||||
#endif /* SDL_FILESYSTEM_WINDOWS */
|
||||
|
||||
#ifdef SDL_FILESYSTEM_XBOX
|
||||
char *SDL_GetBasePath(void)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *SDL_GetUserFolder(SDL_Folder folder)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
}
|
||||
#endif /* SDL_FILESYSTEM_XBOX */
|
||||
|
Reference in New Issue
Block a user