comparison util.c @ 1058:266dc3f31f35

Use more appropriate paths for save directories and config files on Windows. Got rid of what should be the last vestiges of hard-coded path separators
author Michael Pavone <pavone@retrodev.com>
date Sat, 30 Jul 2016 23:36:02 -0700
parents 86ed81bb574f
children 22e87b739ad6
comparison
equal deleted inserted replaced
1057:ff46d8fc2de8 1058:266dc3f31f35
591 ret = NULL; 591 ret = NULL;
592 } 592 }
593 return ret; 593 return ret;
594 } 594 }
595 595
596
597 #ifdef _WIN32
598 char const *get_save_base_dir()
599 {
600 static char path[MAX_PATH];
601 if (S_OK == SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path))
602 {
603 return path;
604 }
605 return NULL;
606 }
607 #define CONFIG_PREFIX ""
608 #define SAVE_PREFIX ""
609
610 #else
611
612 #define get_save_base_dir get_home_dir
613 #define CONFIG_PREFIX "/.config"
614 #define SAVE_PREFIX "/.local/share"
615
616 #endif
617
596 char const *get_config_dir() 618 char const *get_config_dir()
597 { 619 {
598 static char* confdir; 620 static char* confdir;
599 if (!confdir) { 621 if (!confdir) {
600 char *homedir = get_home_dir(); 622 char const *base = get_save_base_dir();
601 if (homedir) { 623 if (base) {
602 confdir = alloc_concat(homedir, "/.config/blastem"); 624 confdir = alloc_concat(base, CONFIG_PREFIX PATH_SEP "blastem");
603 } 625 }
604 } 626 }
605 return confdir; 627 return confdir;
606 } 628 }
607 629
608 char const *get_save_dir() 630 char const *get_save_dir()
609 { 631 {
610 static char* savedir; 632 static char* savedir;
611 if (!savedir) { 633 if (!savedir) {
612 char *homedir = get_home_dir(); 634 char const *base = get_save_base_dir();
613 if (homedir) { 635 if (base) {
614 savedir = alloc_concat(homedir, "/.local/share/blastem"); 636 savedir = alloc_concat(base, SAVE_PREFIX PATH_SEP "blastem");
615 } 637 }
616 } 638 }
617 return savedir; 639 return savedir;
618 } 640 }
619 641