Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Move default data directory to XDG_DATA_HOME on Linux #470

Merged
merged 6 commits into from
Feb 14, 2022
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions prboom2/src/SDL/i_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,22 +344,40 @@ const char* I_GetTempDir(void)
// cph - V.Aguilar (5/30/99) suggested return ~/.lxdoom/, creating
// if non-existant
// cph 2006/07/23 - give prboom+ its own dir
static const char prboom_dir[] = {"/.prboom-plus"}; // Mead rem extra slash 8/21/03
static const char prboom_dir[] = {"prboom-plus"};

const char *I_DoomExeDir(void)
{
static char *base;
struct stat data_dir;

if (!base) // cache multiple requests
{
char *home = getenv("HOME");
char *p_home = strdup(home);
size_t len = strlen(home);
size_t p_len = (len + strlen(prboom_dir) + 3);

base = malloc(len + strlen(prboom_dir) + 1);
strcpy(base, home);
// I've had trouble with trailing slashes before...
if (base[len-1] == '/') base[len-1] = 0;
strcat(base, prboom_dir);
mkdir(base, S_IRUSR | S_IWUSR | S_IXUSR); // Make sure it exists
if (p_home[len-1] == '/') p_home[len-1] = 0;

base = malloc(p_len);
snprintf(base, p_len, "%s/.%s", p_home, prboom_dir);
free(p_home);

stat(base, &data_dir);
if (!S_ISDIR(data_dir.st_mode))
facespkz marked this conversation as resolved.
Show resolved Hide resolved
{
char *prefpath = SDL_GetPrefPath("", prboom_dir);
size_t prefsize = strlen(prefpath);

free(base);
base = strdup(prefpath);
// SDL_GetPrefPath always returns with trailing slash
if (base[prefsize-1] == '/') base[prefsize-1] = 0;
SDL_free(prefpath);
}
facespkz marked this conversation as resolved.
Show resolved Hide resolved
// mkdir(base, S_IRUSR | S_IWUSR | S_IXUSR);
}
return base;
}
Expand Down