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() 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
if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) subdir = "starfighter";
engine_showError(2, dir);
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)) if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
engine_showError(2, dir); engine_showError(2, dir);
snprintf(engine.configDirectory, PATH_MAX, "%s/", dir);
#endif #endif
snprintf(engine.configDirectory, PATH_MAX, "%s/.config/starfighter/", userHome);
} }
/* /*