mirror of
https://github.com/encounter/SDL.git
synced 2025-12-09 21:47:44 +00:00
Added a README file regarding WinRT support
To note, this file is currently formatted with CRLF line endings, rather than LF, to allow the file to be viewed with Notepad.
This commit is contained in:
105
src/filesystem/cocoa/SDL_sysfilesystem.m
Normal file
105
src/filesystem/cocoa/SDL_sysfilesystem.m
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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_COCOA
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* System dependent filesystem routines */
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_filesystem.h"
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
return retval;
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||
char *retval = NULL;
|
||||
|
||||
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;
|
||||
SDL_snprintf(retval, len, "%s/%s/%s/", base, org, app);
|
||||
for (ptr = retval+1; *ptr; ptr++) {
|
||||
if (*ptr == '/') {
|
||||
*ptr = '\0';
|
||||
mkdir(retval, 0700);
|
||||
*ptr = '/';
|
||||
}
|
||||
}
|
||||
mkdir(retval, 0700);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* SDL_FILESYSTEM_COCOA */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
47
src/filesystem/dummy/SDL_sysfilesystem.c
Normal file
47
src/filesystem/dummy/SDL_sysfilesystem.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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_DUMMY
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* System dependent filesystem routines */
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_filesystem.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_DUMMY */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
93
src/filesystem/haiku/SDL_sysfilesystem.cc
Normal file
93
src/filesystem/haiku/SDL_sysfilesystem.cc
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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_HAIKU
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* System dependent filesystem routines */
|
||||
|
||||
#include <os/kernel/image.h>
|
||||
#include <os/storage/Directory.h>
|
||||
#include <os/storage/Entry.h>
|
||||
#include <os/storage/Path.h>
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_filesystem.h"
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
image_info info;
|
||||
int32 cookie = 0;
|
||||
|
||||
while (get_next_image_info(0, &cookie, &info) == B_OK) {
|
||||
if (info.type == B_APP_IMAGE) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BEntry entry(info.name, true);
|
||||
BPath path;
|
||||
status_t rc = entry.GetPath(&path); /* (path) now has binary's path. */
|
||||
SDL_assert(rc == B_OK);
|
||||
rc = path.GetParent(&path); /* chop filename, keep directory. */
|
||||
SDL_assert(rc == B_OK);
|
||||
const char *str = path.Path();
|
||||
SDL_assert(str != NULL);
|
||||
|
||||
const size_t len = SDL_strlen(str);
|
||||
char *retval = (char *) SDL_malloc(len + 2);
|
||||
if (!retval) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_memcpy(retval, str, len);
|
||||
retval[len] = '/';
|
||||
retval[len+1] = '\0';
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
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/";
|
||||
const size_t len = SDL_strlen(home) + SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
|
||||
char *retval = (char *) SDL_malloc(len);
|
||||
if (!retval) {
|
||||
SDL_OutOfMemory();
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app);
|
||||
create_directory(retval, 0700); // Haiku api: creates missing dirs
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* SDL_FILESYSTEM_HAIKU */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
210
src/filesystem/unix/SDL_sysfilesystem.c
Normal file
210
src/filesystem/unix/SDL_sysfilesystem.c
Normal file
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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_UNIX
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* System dependent filesystem routines */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef __FREEBSD__
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_filesystem.h"
|
||||
|
||||
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);
|
||||
if (ptr == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
break;
|
||||
}
|
||||
|
||||
retval = ptr;
|
||||
|
||||
rc = readlink(path, retval, len);
|
||||
if (rc == -1) {
|
||||
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. */
|
||||
}
|
||||
|
||||
len *= 2; /* grow buffer, try again. */
|
||||
}
|
||||
|
||||
SDL_free(retval);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
char *retval = NULL;
|
||||
|
||||
#if defined(__FREEBSD__)
|
||||
char fullpath[PATH_MAX];
|
||||
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) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#elif 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 defined(__FREEBSD__)
|
||||
retval = readSymLink("/proc/curproc/file");
|
||||
#elif defined(__NETBSD__)
|
||||
retval = readSymLink("/proc/curproc/exe");
|
||||
#else
|
||||
retval = readSymLink("/proc/self/exe"); /* linux. */
|
||||
#endif
|
||||
if (retval == NULL) {
|
||||
/* older kernels don't have /proc/self ... try PID version... */
|
||||
char path[64];
|
||||
const int rc = (int) SDL_snprintf(path, sizeof(path),
|
||||
"/proc/%llu/exe",
|
||||
(unsigned long long) getpid());
|
||||
if ( (rc > 0) && (rc < sizeof(path)) ) {
|
||||
retval = readSymLink(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 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... */
|
||||
SDL_free(retval);
|
||||
retval = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (retval != NULL) {
|
||||
/* try to shrink buffer... */
|
||||
char *ptr = (char *) SDL_realloc(retval, strlen(retval) + 1);
|
||||
if (ptr != NULL)
|
||||
retval = ptr; /* oh well if it failed. */
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
/*
|
||||
* We use XDG's base directory spec, even if you're not on Linux.
|
||||
* This isn't strictly correct, but the results are relatively sane
|
||||
* in any case.
|
||||
*
|
||||
* http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
*/
|
||||
const char *envr = SDL_getenv("XDG_DATA_HOME");
|
||||
const char *append;
|
||||
char *retval = NULL;
|
||||
char *ptr = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
if (!envr) {
|
||||
/* You end up with "$HOME/.local/share/Game Name 2" */
|
||||
envr = SDL_getenv("HOME");
|
||||
if (!envr) {
|
||||
/* we could take heroic measures with /etc/passwd, but oh well. */
|
||||
SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
|
||||
return NULL;
|
||||
}
|
||||
append = "/.local/share/";
|
||||
} else {
|
||||
append = "/";
|
||||
}
|
||||
|
||||
len = SDL_strlen(envr);
|
||||
if (envr[len - 1] == '/')
|
||||
append += 1;
|
||||
|
||||
len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
if (!retval) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_snprintf(retval, len, "%s%s%s/%s/", envr, append, org, app);
|
||||
|
||||
for (ptr = retval+1; *ptr; ptr++) {
|
||||
if (*ptr == '/') {
|
||||
*ptr = '\0';
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST)
|
||||
goto error;
|
||||
*ptr = '/';
|
||||
}
|
||||
}
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
|
||||
error:
|
||||
SDL_SetError("Couldn't create directory '%s': ", retval, strerror(errno));
|
||||
SDL_free(retval);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* SDL_FILESYSTEM_UNIX */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
140
src/filesystem/windows/SDL_sysfilesystem.c
Normal file
140
src/filesystem/windows/SDL_sysfilesystem.c
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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_WINDOWS
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* System dependent filesystem routines */
|
||||
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
#include <shlobj.h>
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_filesystem.h"
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
TCHAR path[MAX_PATH];
|
||||
const DWORD len = GetModuleFileName(NULL, path, SDL_arraysize(path));
|
||||
size_t i;
|
||||
|
||||
SDL_assert(len < SDL_arraysize(path));
|
||||
|
||||
if (len == 0) {
|
||||
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 WIN_StringToUTF8(path);
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
/*
|
||||
* Vista and later has a new API for this, but SHGetFolderPath works there,
|
||||
* and apparently just wraps the new API. This is the new way to do it:
|
||||
*
|
||||
* SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE,
|
||||
* NULL, &wszPath);
|
||||
*/
|
||||
|
||||
WCHAR path[MAX_PATH];
|
||||
char *retval = NULL;
|
||||
WCHAR* worg = NULL;
|
||||
WCHAR* wapp = NULL;
|
||||
size_t new_wpath_len = 0;
|
||||
BOOL api_result = FALSE;
|
||||
|
||||
if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path))) {
|
||||
WIN_SetError("Couldn't locate our prefpath");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
worg = WIN_UTF8ToString(org);
|
||||
if (worg == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wapp = WIN_UTF8ToString(app);
|
||||
if (wapp == NULL) {
|
||||
SDL_free(worg);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new_wpath_len = lstrlenW(worg) + lstrlenW(wapp) + lstrlenW(path) + 3;
|
||||
|
||||
if ((new_wpath_len + 1) > MAX_PATH) {
|
||||
SDL_free(worg);
|
||||
SDL_free(wapp);
|
||||
WIN_SetError("Path too long.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lstrcatW(path, L"\\");
|
||||
lstrcatW(path, worg);
|
||||
SDL_free(worg);
|
||||
|
||||
api_result = CreateDirectoryW(path, NULL);
|
||||
if (api_result == FALSE) {
|
||||
if (GetLastError() != ERROR_ALREADY_EXISTS) {
|
||||
SDL_free(wapp);
|
||||
WIN_SetError("Couldn't create a prefpath.");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
lstrcatW(path, L"\\");
|
||||
lstrcatW(path, wapp);
|
||||
SDL_free(wapp);
|
||||
|
||||
api_result = CreateDirectoryW(path, NULL);
|
||||
if (api_result == FALSE) {
|
||||
if (GetLastError() != ERROR_ALREADY_EXISTS) {
|
||||
WIN_SetError("Couldn't create a prefpath.");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
lstrcatW(path, L"\\");
|
||||
|
||||
retval = WIN_StringToUTF8(path);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* SDL_FILESYSTEM_WINDOWS */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
174
src/filesystem/winrt/SDL_sysfilesystem.cpp
Normal file
174
src/filesystem/winrt/SDL_sysfilesystem.cpp
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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"
|
||||
|
||||
/* TODO, WinRT: include copyright info in SDL_winrtpaths.cpp
|
||||
TODO, WinRT: remove the need to compile this with C++/CX (/ZW) extensions, and if possible, without C++ at all
|
||||
*/
|
||||
|
||||
#ifdef __WINRT__
|
||||
|
||||
extern "C" {
|
||||
#include "SDL_filesystem.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_system.h"
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
}
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
using namespace Windows::Storage;
|
||||
|
||||
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()) {
|
||||
path = Windows::ApplicationModel::Package::Current->InstalledLocation->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
|
||||
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();
|
||||
}
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_Unsupported();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern "C" const char *
|
||||
SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
|
||||
{
|
||||
typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap;
|
||||
static UTF8PathMap utf8Paths;
|
||||
|
||||
UTF8PathMap::iterator searchResult = utf8Paths.find(pathType);
|
||||
if (searchResult != utf8Paths.end()) {
|
||||
return searchResult->second.c_str();
|
||||
}
|
||||
|
||||
const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
|
||||
if (!ucs2Path) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char * utf8Path = WIN_StringToUTF8(ucs2Path);
|
||||
utf8Paths[pathType] = utf8Path;
|
||||
SDL_free(utf8Path);
|
||||
return utf8Paths[pathType].c_str();
|
||||
}
|
||||
|
||||
extern "C" char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION);
|
||||
size_t destPathLen;
|
||||
char * destPath = NULL;
|
||||
|
||||
if (!srcPath) {
|
||||
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
destPathLen = SDL_strlen(srcPath) + 2;
|
||||
destPath = (char *) SDL_malloc(destPathLen);
|
||||
if (!destPath) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_snprintf(destPath, destPathLen, "%s\\", srcPath);
|
||||
return destPath;
|
||||
}
|
||||
|
||||
extern "C" char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
/* WinRT note: The 'SHGetFolderPath' API that is used in Windows 7 and
|
||||
* earlier is not available on WinRT or Windows Phone. WinRT provides
|
||||
* a similar API, but SHGetFolderPath can't be called, at least not
|
||||
* without violating Microsoft's app-store requirements.
|
||||
*/
|
||||
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
/* A 'Roaming' folder is not available in Windows Phone 8, however a 'Local' folder is. */
|
||||
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_LOCAL_FOLDER);
|
||||
#else
|
||||
/* A 'Roaming' folder is available on Windows 8 and 8.1. Use that. */
|
||||
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_ROAMING_FOLDER);
|
||||
#endif
|
||||
|
||||
size_t destPathLen;
|
||||
char * destPath = NULL;
|
||||
|
||||
if (!srcPath) {
|
||||
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
destPathLen = SDL_strlen(srcPath) + SDL_strlen(org) + SDL_strlen(app) + 4;
|
||||
destPath = (char *) SDL_malloc(destPathLen);
|
||||
if (!destPath) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_snprintf(destPath, destPathLen, "%s\\%s\\%s\\", srcPath, org, app);
|
||||
return destPath;
|
||||
}
|
||||
|
||||
#endif /* __WINRT__ */
|
||||
Reference in New Issue
Block a user