Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect the XDG base directory specification #50

Merged
merged 2 commits into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion sdl2/Makefile.gcw0
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,3 @@ buildopk:

uninstall:
rm /usr/local/bin/$(TARGET)
rm -rf -p $(HOME)/.config/np2kai
3 changes: 0 additions & 3 deletions sdl2/Makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ clean:
install:
strip $(TARGET)
cp $(TARGET) /usr/local/bin/
mkdir -p $(HOME)/.config/np2kai
chown $(SUDO_USER) $(HOME)/.config/np2kai


uninstall:
rm /usr/local/bin/$(TARGET)
rm -rf -p $(HOME)/.config/np2kai

3 changes: 0 additions & 3 deletions sdl2/Makefile.win
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ clean:
install:
strip $(TARGET)
cp $(TARGET) /usr/local/bin/
mkdir -p $(HOME)/.config/np2kai
chown $(SUDO_USER) $(HOME)/.config/np2kai


uninstall:
rm /usr/local/bin/$(TARGET)
rm -rf -p $(HOME)/.config/np2kai

3 changes: 0 additions & 3 deletions sdl2/Makefile21.unix
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ clean:
install:
strip $(TARGET)
cp $(TARGET) /usr/local/bin/
mkdir -p $(HOME)/.config/np2kai
chown $(SUDO_USER) $(HOME)/.config/np2kai


uninstall:
rm /usr/local/bin/$(TARGET)
rm -rf -p $(HOME)/.config/np2kai

3 changes: 0 additions & 3 deletions sdl2/Makefile21.win
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@ clean:
install:
strip $(TARGET)
cp $(TARGET) /usr/local/bin/
mkdir -p $(HOME)/.config/np2kai
chown $(SUDO_USER) $(HOME)/.config/np2kai


uninstall:
rm /usr/local/bin/$(TARGET)
rm -rf -p $(HOME)/.config/np2kai

16 changes: 14 additions & 2 deletions sdl2/np2.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,20 @@ int np2_main(int argc, char *argv[]) {
}

#if !defined(__LIBRETRO__)
strcpy(np2cfg.biospath, getenv("HOME"));
strcat(np2cfg.biospath, "/.config/np2kai/");
char *config_home = getenv("XDG_CONFIG_HOME");
char *home = getenv("HOME");
if (config_home && config_home[0] == '/') {
/* base dir */
milstr_ncpy(np2cfg.biospath, config_home, sizeof(np2cfg.biospath));
milstr_ncat(np2cfg.biospath, "/np2kai/", sizeof(np2cfg.biospath));
} else if (home) {
/* base dir */
milstr_ncpy(np2cfg.biospath, home, sizeof(np2cfg.biospath));
milstr_ncat(np2cfg.biospath, "/.config/np2kai/", sizeof(np2cfg.biospath));
} else {
printf("$HOME isn't defined.\n");
goto np2main_err1;
}
file_setcd(np2cfg.biospath);
#endif /* __LIBRETRO__ */

Expand Down
27 changes: 18 additions & 9 deletions x11/gtk2/gtk_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,30 @@ BRESULT
gui_gtk_arginit(int *argcp, char ***argvp)
{
char buf[MAX_PATH];
char *homeenv;

gtk_set_locale();
gtk_init(argcp, argvp);

homeenv = getenv("HOME");
if (homeenv) {
g_snprintf(buf, sizeof(buf), "%s/.config/xnp2kai/gtkrc", homeenv);
gtk_rc_add_default_file(buf);

g_snprintf(buf, sizeof(buf), "%s/.config/xnp2kai/accels", homeenv);
if (g_file_test(buf, G_FILE_TEST_IS_REGULAR))
gtk_accel_map_load(buf);
char *config_home = getenv("XDG_CONFIG_HOME");
char *home = getenv("HOME");
if (config_home && config_home[0] == '/') {
/* base dir */
g_snprintf(buf, sizeof(buf), "%s/xnp2kai/", config_home);
} else if (home) {
/* base dir */
g_snprintf(buf, sizeof(buf), "%s/.config/xnp2kai/", home);
} else {
g_printerr("$HOME isn't defined.\n");
exit(1);
}

g_strlcat(buf, "gtkrc", sizeof(buf));
gtk_rc_add_default_file(buf);

g_strlcat(buf, "accels", sizeof(buf));
if (g_file_test(buf, G_FILE_TEST_IS_REGULAR))
gtk_accel_map_load(buf);

return SUCCESS;
}

Expand Down
46 changes: 27 additions & 19 deletions x11/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,30 +188,38 @@ main(int argc, char *argv[])
argv += optind;

if (modulefile[0] == '\0') {
char *env = getenv("HOME");
if (env) {
char *config_home = getenv("XDG_CONFIG_HOME");
char *home = getenv("HOME");
if (config_home && config_home[0] == '/') {
/* base dir */
g_snprintf(modulefile, sizeof(modulefile),
"%s/.config/xnp2kai/", env);
if (stat(modulefile, &sb) < 0) {
if (mkdir(modulefile, 0700) < 0) {
perror(modulefile);
exit(1);
}
} else if (!S_ISDIR(sb.st_mode)) {
g_printerr("%s isn't directory.\n",
modulefile);
"%s/xnp2kai/", config_home);
} else if (home) {
/* base dir */
g_snprintf(modulefile, sizeof(modulefile),
"%s/.config/xnp2kai/", home);
} else {
g_printerr("$HOME isn't defined.\n");
exit(1);
}
if (stat(modulefile, &sb) < 0) {
if (mkdir(modulefile, 0700) < 0) {
perror(modulefile);
exit(1);
}
} else if (!S_ISDIR(sb.st_mode)) {
g_printerr("%s isn't directory.\n",
modulefile);
exit(1);
}

/* config file */
milstr_ncat(modulefile, appname, sizeof(modulefile));
milstr_ncat(modulefile, "rc", sizeof(modulefile));
if ((stat(modulefile, &sb) >= 0)
&& !S_ISREG(sb.st_mode)) {
g_printerr("%s isn't regular file.\n",
modulefile);
}
/* config file */
milstr_ncat(modulefile, appname, sizeof(modulefile));
milstr_ncat(modulefile, "rc", sizeof(modulefile));
if ((stat(modulefile, &sb) >= 0)
&& !S_ISREG(sb.st_mode)) {
g_printerr("%s isn't regular file.\n",
modulefile);
}
}
if (modulefile[0] != '\0') {
Expand Down