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:
Julie Marchant 2019-07-03 17:00:46 -04:00
parent 759bed096a
commit b4ccaf61ab
1 changed files with 24 additions and 17 deletions

View File

@ -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
userHome = ".";
#else
if ((userHome = getenv("HOME")) == NULL)
userHome = getpwuid(getuid())->pw_dir;
#endif
subdir = "pr-starfighter-config";
strcpy(dir, "");
if ((userHome = getenv("APPDATA")) == NULL)
userHome = ".";
snprintf(dir, PATH_MAX, "%s/.config", userHome);
#ifdef _WIN32
snprintf(dir, PATH_MAX, "%s/%s", userHome, subdir);
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);
snprintf(engine.configDirectory, PATH_MAX, "%s/", dir);
#else
if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
engine_showError(2, dir);
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);
}
snprintf(dir, PATH_MAX, "%s/.config/starfighter", userHome);
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);
}
/*