taisei/src/vfs/platform_paths/resroot_sdl.c
Andrei Alexeyev a8d8bbf2bc vfs: try to put cache in platform-appropriate locations
Windows: %LOCALAPPDATA%\taisei\cache
Linux and *BSD: $XDG_CACHE_HOME/taisei (xdg basedir spec); usually
~/.cache/taisei
macOS: NSCachesDirectory; probably ~/Library/Caches/taisei
Fallback: $storage/cache (old behavior)

This commit also introduces a more modular and buildsystem-driven
approach to specifying those paths, and makes vfs initialization more
resilient. The game will try to create missing directories recursively,
and will not crash if storage or cache can not be mounted.

Co-authored-by: Alice D <alice@starwitch.productions>
2020-12-07 22:36:35 +02:00

33 lines
695 B
C

/*
* This software is licensed under the terms of the MIT License.
* See COPYING for further information.
* ---
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
*/
#include "taisei.h"
#include "platform_paths.h"
#include "util.h"
#include "../syspath_public.h"
#include <SDL.h>
const char *vfs_platformpath_resroot(void) {
static char *cached;
if(!cached) {
char *basepath = SDL_GetBasePath();
if(!basepath) {
log_sdl_error(LOG_FATAL, "SDL_GetBasePath");
return NULL;
}
cached = vfs_syspath_join_alloc(basepath, TAISEI_BUILDCONF_DATA_PATH);
SDL_free(basepath);
}
return cached;
}