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
41
src/engine.c
41
src/engine.c
|
@ -198,36 +198,43 @@ This gets the user's home directory, then creates the config directory.
|
||||||
void engine_setupConfigDirectory()
|
void engine_setupConfigDirectory()
|
||||||
{
|
{
|
||||||
const char *userHome;
|
const char *userHome;
|
||||||
|
const char *subdir;
|
||||||
char dir[PATH_MAX];
|
char dir[PATH_MAX];
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
userHome = ".";
|
subdir = "pr-starfighter-config";
|
||||||
#else
|
|
||||||
if ((userHome = getenv("HOME")) == NULL)
|
|
||||||
userHome = getpwuid(getuid())->pw_dir;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
strcpy(dir, "");
|
if ((userHome = getenv("APPDATA")) == NULL)
|
||||||
|
userHome = ".";
|
||||||
|
|
||||||
snprintf(dir, PATH_MAX, "%s/.config", userHome);
|
snprintf(dir, PATH_MAX, "%s/%s", userHome, subdir);
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
if ((mkdir(dir) != 0) && (errno != EEXIST))
|
if ((mkdir(dir) != 0) && (errno != EEXIST))
|
||||||
engine_showError(2, dir);
|
engine_showError(2, dir);
|
||||||
|
|
||||||
snprintf(dir, PATH_MAX, "%s/.config/starfighter", userHome);
|
snprintf(engine.configDirectory, PATH_MAX, "%s/", dir);
|
||||||
if ((mkdir(dir) != 0) && (errno != EEXIST))
|
|
||||||
engine_showError(2, dir);
|
|
||||||
#else
|
#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;
|
||||||
|
|
||||||
|
snprintf(dir, PATH_MAX, "%s/.config", userHome);
|
||||||
|
if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
|
||||||
|
engine_showError(2, dir);
|
||||||
|
|
||||||
|
snprintf(dir, PATH_MAX, "%s/.config/%s", userHome, subdir);
|
||||||
|
}
|
||||||
|
|
||||||
if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
|
if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
|
||||||
engine_showError(2, dir);
|
engine_showError(2, dir);
|
||||||
|
|
||||||
snprintf(dir, PATH_MAX, "%s/.config/starfighter", userHome);
|
snprintf(engine.configDirectory, PATH_MAX, "%s/", dir);
|
||||||
if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
|
|
||||||
engine_showError(2, dir);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
snprintf(engine.configDirectory, PATH_MAX, "%s/.config/starfighter/", userHome);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue