Wiki Page Content

Differences between revisions 1 and 2
Revision 1 as of 2013-11-01 14:37:51
Size: 2328
Editor: urkle
Comment: Initial documentation for SDL_GetBasePath
Revision 2 as of 2013-11-01 19:59:50
Size: 2337
Comment: Fixed typos and added a link.
Deletions are marked like this. Additions are marked like this.
Line 18: Line 18:
||'''org'''||The name of your organization||
||'''app'''||The name of your application||
||'''org'''||the name of your organization||
||'''app'''||the name of your application||
Line 23: Line 23:
Returns a UTF-8 string of the user dire in platform-depende3nt notation. NULL if there's a problem (creating directory failed, etc.). Returns a UTF-8 string of the user directory in platform-dependent notation. NULL if there's a problem (creating directory failed, etc.).
Line 25: Line 25:
The return path will be guaranteed to end with a path separator ('\' on Windows, '/' on most other platforms) The return path will be guaranteed to end with a path separator ('\' on Windows, '/' on most other platforms).
Line 46: Line 46:
You should assume the path returned by this function is the only safe place to write files (and that SDL_GetBasePath(), while it might be writable, or even the parent of the returned path, aren't where you should be writing things). You should assume the path returned by this function is the only safe place to write files (and that [[SDL_GetBasePath]](), while it might be writable, or even the parent of the returned path, aren't where you should be writing things).

DRAFT

SDL_GetPrefPath

Use this function to get the "pref dir". This is meant to be where the application can write personal files (Preferences and save games, etc.) that are specific to the application. This directory is unique per user and per application.

Syntax

char* SDL_GetPrefPath(const char* org,
                      const char* app)

Function Parameters

org

the name of your organization

app

the name of your application

Return Value

Returns a UTF-8 string of the user directory in platform-dependent notation. NULL if there's a problem (creating directory failed, etc.).

The return path will be guaranteed to end with a path separator ('\' on Windows, '/' on most other platforms).

The pointer returned is owned by you. Please call SDL_free() on the pointer when you are done with it.

Code Examples

char *pref_path = NULL;

int InitializePrefPath() {
    char *base_path = SDL_GetPrefPathPath("My Company", "My Awesome SDL 2 Game");
    if (base_path) {
        pref_path = SDL_strdup(base_path);
        SDL_free(pref_path);
    } else {
        /* Do something to disable writing in-game */
    }
}

Remarks

You should assume the path returned by this function is the only safe place to write files (and that SDL_GetBasePath(), while it might be writable, or even the parent of the returned path, aren't where you should be writing things).

Both the org and app strings may become part of a directory name, so please follow these rules:

  • Try to use the same org string (including case-sensitivity) for all your applications that use this function.
  • Always use a unique app string for each one, and make sure it never changes for an app once you've decided on it.
  • Unicode characters are legal, as long as it's UTF-8 encoded, but...
  • ...only use letters, numbers, and spaces. Avoid punctuation like "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.

Version

This function is available in SDL 2.0.1


CategoryAPI, CategoryFilesystem

None: SDL_GetPrefPath (last edited 2015-05-08 19:33:13 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit