Use XDG environment varaible standards, plus Windows env variable for win32
The Windows variable is untested, but hopefully should work and be better than all that Windows API nonsense.
This commit is contained in:
parent
759bed096a
commit
b4ccaf61ab
37
src/engine.c
37
src/engine.c
|
@ -198,36 +198,43 @@ This gets the user's home directory, then creates the config directory.
|
|||
void engine_setupConfigDirectory()
|
||||
{
|
||||
const char *userHome;
|
||||
const char *subdir;
|
||||
char dir[PATH_MAX];
|
||||
|
||||
#ifdef _WIN32
|
||||
subdir = "pr-starfighter-config";
|
||||
|
||||
if ((userHome = getenv("APPDATA")) == NULL)
|
||||
userHome = ".";
|
||||
|
||||
snprintf(dir, PATH_MAX, "%s/%s", userHome, subdir);
|
||||
if ((mkdir(dir) != 0) && (errno != EEXIST))
|
||||
engine_showError(2, dir);
|
||||
|
||||
snprintf(engine.configDirectory, PATH_MAX, "%s/", dir);
|
||||
#else
|
||||
subdir = "starfighter";
|
||||
|
||||
if ((userHome = getenv("XDG_CONFIG_HOME")) != NULL)
|
||||
{
|
||||
snprintf(dir, PATH_MAX, "%s/%s", userHome, subdir);
|
||||
}
|
||||
{
|
||||
if ((userHome = getenv("HOME")) == NULL)
|
||||
userHome = getpwuid(getuid())->pw_dir;
|
||||
#endif
|
||||
|
||||
strcpy(dir, "");
|
||||
|
||||
snprintf(dir, PATH_MAX, "%s/.config", userHome);
|
||||
|
||||
#ifdef _WIN32
|
||||
if ((mkdir(dir) != 0) && (errno != EEXIST))
|
||||
engine_showError(2, dir);
|
||||
|
||||
snprintf(dir, PATH_MAX, "%s/.config/starfighter", userHome);
|
||||
if ((mkdir(dir) != 0) && (errno != EEXIST))
|
||||
engine_showError(2, dir);
|
||||
#else
|
||||
if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
|
||||
engine_showError(2, dir);
|
||||
|
||||
snprintf(dir, PATH_MAX, "%s/.config/starfighter", userHome);
|
||||
snprintf(dir, PATH_MAX, "%s/.config/%s", userHome, subdir);
|
||||
}
|
||||
|
||||
if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
|
||||
engine_showError(2, dir);
|
||||
|
||||
snprintf(engine.configDirectory, PATH_MAX, "%s/", dir);
|
||||
#endif
|
||||
|
||||
snprintf(engine.configDirectory, PATH_MAX, "%s/.config/starfighter/", userHome);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue