filesystem: SDL_GetBasePath() now follows the SDL_GetStringRule.
It also now caches at the higher level, so the platform-specific bits don't change their interface much. A little code hygiene work was applied to some of the platform bits on top of this. Reference Issue #10229.
This commit is contained in:
parent
d65a8146b9
commit
3bc81a81f5
24 changed files with 137 additions and 69 deletions
|
@ -28,7 +28,7 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* System dependent filesystem routines */
|
||||
|
||||
char *SDL_GetBasePath(void)
|
||||
char *SDL_SYS_GetBasePath(void)
|
||||
{
|
||||
char *retval = NULL;
|
||||
size_t len;
|
||||
|
@ -37,7 +37,9 @@ char *SDL_GetBasePath(void)
|
|||
getcwd(cwd, sizeof(cwd));
|
||||
len = SDL_strlen(cwd) + 2;
|
||||
retval = (char *)SDL_malloc(len);
|
||||
SDL_snprintf(retval, len, "%s/", cwd);
|
||||
if (retval) {
|
||||
SDL_snprintf(retval, len, "%s/", cwd);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
@ -46,7 +48,7 @@ char *SDL_GetBasePath(void)
|
|||
static void recursive_mkdir(const char *dir)
|
||||
{
|
||||
char tmp[FILENAME_MAX];
|
||||
char *base = SDL_GetBasePath();
|
||||
const char *base = SDL_GetBasePath();
|
||||
char *p = NULL;
|
||||
size_t len;
|
||||
|
||||
|
@ -60,7 +62,7 @@ static void recursive_mkdir(const char *dir)
|
|||
if (*p == '/') {
|
||||
*p = 0;
|
||||
// Just creating subfolders from current path
|
||||
if (SDL_strstr(tmp, base) != NULL) {
|
||||
if (base && SDL_strstr(tmp, base) != NULL) {
|
||||
mkdir(tmp, S_IRWXU);
|
||||
}
|
||||
|
||||
|
@ -68,7 +70,6 @@ static void recursive_mkdir(const char *dir)
|
|||
}
|
||||
}
|
||||
|
||||
SDL_free(base);
|
||||
mkdir(tmp, S_IRWXU);
|
||||
}
|
||||
|
||||
|
@ -76,26 +77,32 @@ char *SDL_GetPrefPath(const char *org, const char *app)
|
|||
{
|
||||
char *retval = NULL;
|
||||
size_t len;
|
||||
char *base = SDL_GetBasePath();
|
||||
|
||||
if (!app) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!org) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
const char *base = SDL_GetBasePath();
|
||||
if (!base) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
|
||||
retval = (char *)SDL_malloc(len);
|
||||
if (retval) {
|
||||
if (*org) {
|
||||
SDL_snprintf(retval, len, "%s%s/%s/", base, org, app);
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s%s/", base, app);
|
||||
}
|
||||
|
||||
if (*org) {
|
||||
SDL_snprintf(retval, len, "%s%s/%s/", base, org, app);
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s%s/", base, app);
|
||||
recursive_mkdir(retval);
|
||||
}
|
||||
SDL_free(base);
|
||||
|
||||
recursive_mkdir(retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue