Add basic XDG support

Fixes #1504
This commit is contained in:
Lucki 2018-06-08 20:51:48 +02:00
parent 16d5c5234d
commit 74db619a4e
No known key found for this signature in database
GPG key ID: 50358A70D9213FF3

View file

@ -1476,19 +1476,46 @@ int fs_storage_path(const char *appname, char *path, int max)
return 0;
#else
char *home = getenv("HOME");
#if !defined(CONF_PLATFORM_MACOSX)
int i;
#endif
if(!home)
return -1;
#if defined(CONF_PLATFORM_MACOSX)
snprintf(path, max, "%s/Library/Application Support/%s", home, appname);
#else
return 0;
#endif
int i;
char *xdgdatahome = getenv("XDG_DATA_HOME");
char xdgpath[max];
/* old folder location */
snprintf(path, max, "%s/.%s", home, appname);
for(i = strlen(home)+2; path[i]; i++)
path[i] = tolower(path[i]);
#endif
if(!xdgdatahome)
{
/* use default location */
snprintf(xdgpath, max, "%s/.local/share/%s", home, appname);
for(i = strlen(home)+14; xdgpath[i]; i++)
xdgpath[i] = tolower(xdgpath[i]);
}
else
{
snprintf(xdgpath, max, "%s/%s", xdgdatahome, appname);
for(i = strlen(xdgdatahome)+1; xdgpath[i]; i++)
xdgpath[i] = tolower(xdgpath[i]);
}
/* check for old location / backward compatibility */
if(fs_is_dir(path))
{
/* use old folder path */
/* for backward compatibility */
return 0;
}
snprintf(path, max, "%s", xdgpath);
return 0;
#endif