SDL icon indicating copy to clipboard operation
SDL copied to clipboard

SDL_GetPrefPath() without creating directories

Open Sackzement opened this issue 10 months ago • 2 comments

Right now the function SDL_GetPrefPath(org, app) always creates the directories org/app, if they don't exist. It would be useful to have a way to just check, if there are existing files, without creating the directories. It would minimize the clutter from apps, which run for the first time on a system and don't choose to save files yet, but still want to check, if there are any.

Maybe SDL_GetPrefPath() could be replaced with an enum constant in SDL_Folder called SDL_FOLDER_PREF. And if an app wants to save something, it can create the directories with the new SDL_CreateDirectory() function, if there aren't any.

Example on a UNIX system:

SDL_GetUserFolder(SDL_FOLDER_PREF) ==> "/home/a_username/.local/share/"

Sackzement avatar Apr 14 '24 23:04 Sackzement

I described my intention for SDL_GetUserFolder in #8051 and this comment - tl;dr Since application-specific folders have some particularities (app name in the path = dynamically generated), I preferred to limit the folders provided by that function to be user-controlled folders (in opposition to app- or OS-controlled folders), hence why I called it "GetUserFolder". I described the why more in-depth in the linked discussions.

This proposal is about adding just the AppData path, without the app-specific suffix. About the practice itself, I'm not sure if it's a good idea, because an inexperienced or unaware developer might choose a poorly thought folder structure (or even none at all) and make a mess in the AppData folder. Plus, it wouldn't account for platform differences (Windows being org + app, others being just app, etc). I would support providing an easy, ready-made and standard way of obtaining an application-specific folder, to make consistency more accessible for programmers.

Those are just my thoughts, I'm not particularly attached to either option. If it's decided that GetUserFolder should also provide global application and OS folders, it shouldn't be too difficult to implement, and I can volunteer to do it - after I finished modal windows, of course :-) If not, should I clarify the purpose of that function in the docs?

Semphriss avatar Apr 23 '24 01:04 Semphriss

You are absolutely right. My proposal to replace SDL_GetPrefPath(org, app) with an enum constant in SDL_Folder wasn't good. The main point I wanted to make was, that it could be useful to have a way to get the pref-path without directly creating it if non-existent. Maybe some function like this:

char * SDL_GetPrefPathButDontCreate(const char *org, const char *app);

This is also just an example. Some way to just check if there are preferences files. If nothing ever gets written to the path returned by SDL_GetPrefPath(org, app), there will still be the directories org/app and no files inside.

Sackzement avatar Apr 23 '24 14:04 Sackzement

I think we're going to pass on this one.

icculus avatar May 26 '24 18:05 icculus