mirror of
https://github.com/0ldsk00l/nestopia.git
synced 2024-06-22 06:02:26 -04:00
Use XDG directories for config and data
This commit is contained in:
parent
59d8a67eb9
commit
d78381198a
|
@ -633,8 +633,26 @@ void nst_set_callbacks() {
|
|||
|
||||
void nst_set_dirs() {
|
||||
// Set up system directories
|
||||
// create system directory if it doesn't exist
|
||||
snprintf(nstpaths.nstdir, sizeof(nstpaths.nstdir), "%s/.nestopia/", getenv("HOME"));
|
||||
// create config directory if it doesn't exist
|
||||
if (getenv("XDG_CONFIG_HOME")) {
|
||||
snprintf(nstpaths.nstconfdir, sizeof(nstpaths.nstconfdir), "%s/nestopia/", getenv("XDG_CONFIG_HOME"));
|
||||
}
|
||||
else {
|
||||
snprintf(nstpaths.nstconfdir, sizeof(nstpaths.nstconfdir), "%s/.config/nestopia/", getenv("HOME"));
|
||||
}
|
||||
|
||||
if (mkdir(nstpaths.nstconfdir, 0755) && errno != EEXIST) {
|
||||
fprintf(stderr, "Failed to create %s: %d\n", nstpaths.nstconfdir, errno);
|
||||
}
|
||||
|
||||
// create data directory if it doesn't exist
|
||||
if (getenv("XDG_DATA_HOME")) {
|
||||
snprintf(nstpaths.nstdir, sizeof(nstpaths.nstdir), "%s/nestopia/", getenv("XDG_DATA_HOME"));
|
||||
}
|
||||
else {
|
||||
snprintf(nstpaths.nstdir, sizeof(nstpaths.nstdir), "%s/.local/share/nestopia/", getenv("HOME"));
|
||||
}
|
||||
|
||||
if (mkdir(nstpaths.nstdir, 0755) && errno != EEXIST) {
|
||||
fprintf(stderr, "Failed to create %s: %d\n", nstpaths.nstdir, errno);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ using namespace Nes::Api;
|
|||
|
||||
typedef struct {
|
||||
char nstdir[256];
|
||||
char nstconfdir[256];
|
||||
char savedir[256];
|
||||
char gamename[256];
|
||||
char savename[512];
|
||||
|
|
|
@ -394,7 +394,7 @@ static int nstsdl_input_config_match(void* user, const char* section, const char
|
|||
|
||||
void nstsdl_input_conf_read() {
|
||||
// Read the input config file
|
||||
snprintf(inputconfpath, sizeof(inputconfpath), "%sinput.conf", nstpaths.nstdir);
|
||||
snprintf(inputconfpath, sizeof(inputconfpath), "%sinput.conf", nstpaths.nstconfdir);
|
||||
|
||||
if (ini_parse(inputconfpath, nstsdl_input_config_match, &inputconf) < 0) {
|
||||
fprintf(stderr, "Failed to load input config file %s: Using defaults.\n", inputconfpath);
|
||||
|
|
|
@ -613,7 +613,7 @@ int main(int argc, char *argv[]) {
|
|||
config_set_default();
|
||||
|
||||
// Read the config file and override defaults
|
||||
config_file_read(nstpaths.nstdir);
|
||||
config_file_read(nstpaths.nstconfdir);
|
||||
|
||||
// Handle command line arguments
|
||||
cli_handle_command(argc, argv);
|
||||
|
@ -685,7 +685,7 @@ int main(int argc, char *argv[]) {
|
|||
gtkui_input_config_write();
|
||||
|
||||
// Write the config file
|
||||
config_file_write(nstpaths.nstdir);
|
||||
config_file_write(nstpaths.nstconfdir);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ void gtkui_input_set_default() {
|
|||
|
||||
void gtkui_input_config_read() {
|
||||
// Read the input config file
|
||||
snprintf(inputconfpath, sizeof(inputconfpath), "%sgtkinput.conf", nstpaths.nstdir);
|
||||
snprintf(inputconfpath, sizeof(inputconfpath), "%sgtkinput.conf", nstpaths.nstconfdir);
|
||||
if (ini_parse(inputconfpath, gtkui_input_config_match, &inputconf) < 0) {
|
||||
fprintf(stderr, "Failed to load input config file %s: Using defaults.\n", inputconfpath);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue