mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-25 14:09:10 +00:00
filesystem: SDL_GetPrefPath() now follows the SDL_GetStringRule.
Reference Issue #10229.
This commit is contained in:
parent
2321726ff1
commit
52bf7ff42d
20 changed files with 35 additions and 26 deletions
|
@ -116,15 +116,14 @@ extern SDL_DECLSPEC const char *SDLCALL SDL_GetBasePath(void);
|
||||||
* your applications that use this function.
|
* your applications that use this function.
|
||||||
* - Always use a unique app string for each one, and make sure it never
|
* - Always use a unique app string for each one, and make sure it never
|
||||||
* changes for an app once you've decided on it.
|
* changes for an app once you've decided on it.
|
||||||
* - Unicode characters are legal, as long as it's UTF-8 encoded, but...
|
* - Unicode characters are legal, as long as they are UTF-8 encoded, but...
|
||||||
* - ...only use letters, numbers, and spaces. Avoid punctuation like "Game
|
* - ...only use letters, numbers, and spaces. Avoid punctuation like "Game
|
||||||
* Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
|
* Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
|
||||||
*
|
*
|
||||||
* The returned path is guaranteed to end with a path separator ('\\' on
|
* The returned path is guaranteed to end with a path separator ('\\' on
|
||||||
* Windows, '/' on most other platforms).
|
* Windows, '/' on most other platforms).
|
||||||
*
|
*
|
||||||
* The pointer returned is owned by the caller. Please call SDL_free() on the
|
* The returned string follows the SDL_GetStringRule.
|
||||||
* pointer when done with it.
|
|
||||||
*
|
*
|
||||||
* \param org the name of your organization.
|
* \param org the name of your organization.
|
||||||
* \param app the name of your application.
|
* \param app the name of your application.
|
||||||
|
@ -136,7 +135,7 @@ extern SDL_DECLSPEC const char *SDLCALL SDL_GetBasePath(void);
|
||||||
*
|
*
|
||||||
* \sa SDL_GetBasePath
|
* \sa SDL_GetBasePath
|
||||||
*/
|
*/
|
||||||
extern SDL_DECLSPEC char *SDLCALL SDL_GetPrefPath(const char *org, const char *app);
|
extern SDL_DECLSPEC const char *SDLCALL SDL_GetPrefPath(const char *org, const char *app);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of the OS-provided default folder for a specific purpose.
|
* The type of the OS-provided default folder for a specific purpose.
|
||||||
|
|
|
@ -413,7 +413,7 @@ SDL_DYNAPI_PROC(const char*,SDL_GetPixelFormatName,(SDL_PixelFormat a),(a),retur
|
||||||
SDL_DYNAPI_PROC(const char*,SDL_GetPlatform,(void),(),return)
|
SDL_DYNAPI_PROC(const char*,SDL_GetPlatform,(void),(),return)
|
||||||
SDL_DYNAPI_PROC(void*,SDL_GetPointerProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),return)
|
SDL_DYNAPI_PROC(void*,SDL_GetPointerProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),return)
|
||||||
SDL_DYNAPI_PROC(SDL_PowerState,SDL_GetPowerInfo,(int *a, int *b),(a,b),return)
|
SDL_DYNAPI_PROC(SDL_PowerState,SDL_GetPowerInfo,(int *a, int *b),(a,b),return)
|
||||||
SDL_DYNAPI_PROC(char*,SDL_GetPrefPath,(const char *a, const char *b),(a,b),return)
|
SDL_DYNAPI_PROC(const char*,SDL_GetPrefPath,(const char *a, const char *b),(a,b),return)
|
||||||
SDL_DYNAPI_PROC(SDL_Locale*,SDL_GetPreferredLocales,(void),(),return)
|
SDL_DYNAPI_PROC(SDL_Locale*,SDL_GetPreferredLocales,(void),(),return)
|
||||||
SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetPrimaryDisplay,(void),(),return)
|
SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetPrimaryDisplay,(void),(),return)
|
||||||
SDL_DYNAPI_PROC(const char*,SDL_GetPrimarySelectionText,(void),(),return)
|
SDL_DYNAPI_PROC(const char*,SDL_GetPrimarySelectionText,(void),(),return)
|
||||||
|
|
|
@ -429,6 +429,15 @@ const char *SDL_GetUserFolder(SDL_Folder folder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char *SDL_GetPrefPath(const char *org, const char *app)
|
||||||
|
{
|
||||||
|
char *path = SDL_SYS_GetPrefPath(org, app);
|
||||||
|
if (path) {
|
||||||
|
SDL_FreeLater(path);
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SDL_InitFilesystem(void)
|
void SDL_InitFilesystem(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
// return a string that we can SDL_free(). It will be cached at the higher level.
|
// return a string that we can SDL_free(). It will be cached at the higher level.
|
||||||
extern char *SDL_SYS_GetBasePath(void);
|
extern char *SDL_SYS_GetBasePath(void);
|
||||||
|
extern char *SDL_SYS_GetPrefPath(const char *org, const char *app);
|
||||||
extern char *SDL_SYS_GetUserFolder(SDL_Folder folder);
|
extern char *SDL_SYS_GetUserFolder(SDL_Folder folder);
|
||||||
|
|
||||||
int SDL_SYS_EnumerateDirectory(const char *path, const char *dirname, SDL_EnumerateDirectoryCallback cb, void *userdata);
|
int SDL_SYS_EnumerateDirectory(const char *path, const char *dirname, SDL_EnumerateDirectoryCallback cb, void *userdata);
|
||||||
|
|
|
@ -34,7 +34,7 @@ char *SDL_SYS_GetBasePath(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
const char *path = SDL_GetAndroidInternalStoragePath();
|
const char *path = SDL_GetAndroidInternalStoragePath();
|
||||||
if (path) {
|
if (path) {
|
||||||
|
|
|
@ -61,7 +61,7 @@ char *SDL_SYS_GetBasePath(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
char *retval = NULL;
|
char *retval = NULL;
|
||||||
|
|
|
@ -31,7 +31,7 @@ char *SDL_SYS_GetBasePath(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
SDL_Unsupported();
|
SDL_Unsupported();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -34,7 +34,7 @@ char *SDL_SYS_GetBasePath(void)
|
||||||
return SDL_strdup("/");
|
return SDL_strdup("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
const char *append = "/libsdl/";
|
const char *append = "/libsdl/";
|
||||||
char *retval;
|
char *retval;
|
||||||
|
|
|
@ -79,8 +79,7 @@ SDL_SYS_GetBasePath(void)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
SDL_GetPrefPath(const char *org, const char *app)
|
|
||||||
{
|
{
|
||||||
XUserHandle user = NULL;
|
XUserHandle user = NULL;
|
||||||
XAsyncBlock block = { 0 };
|
XAsyncBlock block = { 0 };
|
||||||
|
|
|
@ -65,7 +65,7 @@ char *SDL_SYS_GetBasePath(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
// !!! FIXME: is there a better way to do this?
|
// !!! FIXME: is there a better way to do this?
|
||||||
const char *home = SDL_getenv("HOME");
|
const char *home = SDL_getenv("HOME");
|
||||||
|
|
|
@ -38,7 +38,7 @@ char *SDL_SYS_GetBasePath(void)
|
||||||
return base_path;
|
return base_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
char *pref_path = NULL;
|
char *pref_path = NULL;
|
||||||
if (!app) {
|
if (!app) {
|
||||||
|
|
|
@ -73,7 +73,7 @@ static void recursive_mkdir(const char *dir)
|
||||||
mkdir(tmp, S_IRWXU);
|
mkdir(tmp, S_IRWXU);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
char *retval = NULL;
|
char *retval = NULL;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
|
@ -44,7 +44,7 @@ char *SDL_SYS_GetBasePath(void)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
char *retval = NULL;
|
char *retval = NULL;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
|
@ -150,7 +150,7 @@ char *SDL_SYS_GetBasePath(void)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
char *canon, *dir, *retval;
|
char *canon, *dir, *retval;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
|
@ -253,7 +253,7 @@ char *SDL_SYS_GetBasePath(void)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* We use XDG's base directory spec, even if you're not on Linux.
|
* We use XDG's base directory spec, even if you're not on Linux.
|
||||||
|
|
|
@ -39,7 +39,7 @@ char *SDL_SYS_GetBasePath(void)
|
||||||
return SDL_strdup("app0:/");
|
return SDL_strdup("app0:/");
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
const char *envr = "ux0:/data/";
|
const char *envr = "ux0:/data/";
|
||||||
char *retval = NULL;
|
char *retval = NULL;
|
||||||
|
|
|
@ -90,7 +90,7 @@ char *SDL_SYS_GetBasePath(void)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *SDL_GetPrefPath(const char *org, const char *app)
|
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Vista and later has a new API for this, but SHGetFolderPath works there,
|
* Vista and later has a new API for this, but SHGetFolderPath works there,
|
||||||
|
|
|
@ -137,7 +137,7 @@ extern "C" char *SDL_SYS_GetBasePath(void)
|
||||||
return destPath;
|
return destPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" char *SDL_GetPrefPath(const char *org, const char *app)
|
extern "C" char *SDL_SYS_GetPrefPath(const char *org, const char *app)
|
||||||
{
|
{
|
||||||
/* WinRT note: The 'SHGetFolderPath' API that is used in Windows 7 and
|
/* WinRT note: The 'SHGetFolderPath' API that is used in Windows 7 and
|
||||||
* earlier is not available on WinRT or Windows Phone. WinRT provides
|
* earlier is not available on WinRT or Windows Phone. WinRT provides
|
||||||
|
|
|
@ -225,15 +225,18 @@ static const SDL_StorageInterface GENERIC_user_iface = {
|
||||||
static SDL_Storage *GENERIC_User_Create(const char *org, const char *app, SDL_PropertiesID props)
|
static SDL_Storage *GENERIC_User_Create(const char *org, const char *app, SDL_PropertiesID props)
|
||||||
{
|
{
|
||||||
SDL_Storage *result;
|
SDL_Storage *result;
|
||||||
|
char *prefpath = NULL;
|
||||||
char *prefpath = SDL_GetPrefPath(org, app);
|
const char *sdlprefpath = SDL_GetPrefPath(org, app);
|
||||||
|
if (sdlprefpath) {
|
||||||
|
prefpath = SDL_strdup(sdlprefpath);
|
||||||
|
}
|
||||||
if (prefpath == NULL) {
|
if (prefpath == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = SDL_OpenStorage(&GENERIC_user_iface, prefpath);
|
result = SDL_OpenStorage(&GENERIC_user_iface, prefpath);
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
SDL_free(prefpath);
|
SDL_free(prefpath); // otherwise CloseStorage will free it.
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ static int SDLCALL enum_callback(void *userdata, const char *origdir, const char
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
SDLTest_CommonState *state;
|
SDLTest_CommonState *state;
|
||||||
char *pref_path;
|
const char *pref_path;
|
||||||
const char *base_path;
|
const char *base_path;
|
||||||
|
|
||||||
/* Initialize test framework */
|
/* Initialize test framework */
|
||||||
|
@ -97,7 +97,6 @@ int main(int argc, char *argv[])
|
||||||
SDL_GetError());
|
SDL_GetError());
|
||||||
} else {
|
} else {
|
||||||
SDL_Log("pref path: '%s'\n", pref_path);
|
SDL_Log("pref path: '%s'\n", pref_path);
|
||||||
SDL_free(pref_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pref_path = SDL_GetPrefPath(NULL, "test_filesystem");
|
pref_path = SDL_GetPrefPath(NULL, "test_filesystem");
|
||||||
|
@ -106,7 +105,6 @@ int main(int argc, char *argv[])
|
||||||
SDL_GetError());
|
SDL_GetError());
|
||||||
} else {
|
} else {
|
||||||
SDL_Log("pref path: '%s'\n", pref_path);
|
SDL_Log("pref path: '%s'\n", pref_path);
|
||||||
SDL_free(pref_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base_path) {
|
if (base_path) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue