Fixed MacOS Resource Path Location (#617)

* Fixed MacOS resource path

I'm not very good at C coding.

* Fixed formatting and ensured safe return
This commit is contained in:
KirbyKidJ 2025-01-07 13:27:11 -08:00 committed by GitHub
parent 29a8a76586
commit d1d36a1fa2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 30 additions and 6 deletions

2
.gitignore vendored
View file

@ -88,6 +88,6 @@ build-windows-visual-studio/.vs
# misc # misc
todo.txt todo.txt
todo-old.txt todo-old.txt
*.DS_Store
tools/ido5.3_compiler/usr/lib/libc.so.1 tools/ido5.3_compiler/usr/lib/libc.so.1
/.vs /.vs

View file

@ -29,7 +29,7 @@ extern "C" {
#endif #endif
#define DYNOS_VERSION "1.0" #define DYNOS_VERSION "1.0"
#define DYNOS_EXE_FOLDER sys_exe_path_dir() #define DYNOS_EXE_FOLDER sys_resource_path()
#define DYNOS_USER_FOLDER fs_get_write_path("") #define DYNOS_USER_FOLDER fs_get_write_path("")
#define DYNOS_RES_FOLDER "dynos" #define DYNOS_RES_FOLDER "dynos"
#define DYNOS_PACKS_FOLDER DYNOS_RES_FOLDER "/packs" #define DYNOS_PACKS_FOLDER DYNOS_RES_FOLDER "/packs"

View file

@ -19,7 +19,7 @@ bool djui_language_init(char* lang) {
// construct path // construct path
char path[SYS_MAX_PATH] = ""; char path[SYS_MAX_PATH] = "";
if (!lang || lang[0] == '\0') { lang = "English"; } if (!lang || lang[0] == '\0') { lang = "English"; }
snprintf(path, SYS_MAX_PATH, "%s/lang/%s.ini", sys_exe_path_dir(), lang); snprintf(path, SYS_MAX_PATH, "%s/lang/%s.ini", sys_resource_path(), lang);
// load // load
sLang = ini_load(path); sLang = ini_load(path);

View file

@ -94,7 +94,7 @@ void djui_panel_language_create(struct DjuiBase* caller) {
{ {
// construct lang path // construct lang path
char lpath[SYS_MAX_PATH] = ""; char lpath[SYS_MAX_PATH] = "";
snprintf(lpath, SYS_MAX_PATH, "%s/lang", sys_exe_path_dir()); snprintf(lpath, SYS_MAX_PATH, "%s/lang", sys_resource_path());
// open directory // open directory
struct dirent* dir = NULL; struct dirent* dir = NULL;

View file

@ -441,7 +441,7 @@ void djui_panel_player_create(struct DjuiBase* caller) {
djui_selectionbox_create(body, DLANG(PLAYER, MODEL), characterChoices, CT_MAX, &configPlayerModel, djui_panel_player_value_changed); djui_selectionbox_create(body, DLANG(PLAYER, MODEL), characterChoices, CT_MAX, &configPlayerModel, djui_panel_player_value_changed);
player_palettes_reset(); player_palettes_reset();
player_palettes_read(sys_exe_path_dir(), true); player_palettes_read(sys_resource_path(), true);
player_palettes_read(fs_get_write_path(PALETTES_DIRECTORY), false); player_palettes_read(fs_get_write_path(PALETTES_DIRECTORY), false);
char* palettePresets[MAX_PRESET_PALETTES + 1] = { DLANG(PALETTE, CUSTOM) }; char* palettePresets[MAX_PRESET_PALETTES + 1] = { DLANG(PALETTE, CUSTOM) };

View file

@ -301,7 +301,7 @@ void mods_refresh_local(void) {
if (hasUserPath) { mods_load(&gLocalMods, userModPath, true); } if (hasUserPath) { mods_load(&gLocalMods, userModPath, true); }
char defaultModsPath[SYS_MAX_PATH] = { 0 }; char defaultModsPath[SYS_MAX_PATH] = { 0 };
snprintf(defaultModsPath, SYS_MAX_PATH, "%s/%s", sys_exe_path_dir(), MOD_DIRECTORY); snprintf(defaultModsPath, SYS_MAX_PATH, "%s/%s", sys_resource_path(), MOD_DIRECTORY);
mods_load(&gLocalMods, defaultModsPath, false); mods_load(&gLocalMods, defaultModsPath, false);
// sort // sort

View file

@ -252,6 +252,10 @@ const char *sys_user_path(void)
return sys_windows_short_path_from_wcs(shortPath, SYS_MAX_PATH, widePath) ? shortPath : NULL; return sys_windows_short_path_from_wcs(shortPath, SYS_MAX_PATH, widePath) ? shortPath : NULL;
} }
const char *sys_resource_path(void) {
return sys_exe_path_dir();
}
const char *sys_exe_path_dir(void) const char *sys_exe_path_dir(void)
{ {
static char path[SYS_MAX_PATH]; static char path[SYS_MAX_PATH];
@ -326,6 +330,25 @@ const char *sys_user_path(void) {
return path; return path;
} }
const char *sys_resource_path(void)
{
#ifdef __APPLE__ // Kinda lazy, but I don't know how to add CoreFoundation.framework
static char path[SYS_MAX_PATH];
if ('\0' != path[0]) { return path; }
const char *exeDir = sys_exe_path_dir();
char *lastSeparator = strrchr(exeDir, '/');
if (lastSeparator != NULL) {
const char folder[] = "/Resources";
size_t count = (size_t)(lastSeparator - exeDir);
strncpy(path, exeDir, count);
return strncat(path, folder, sizeof(path) - 1 - count);
}
#endif
return sys_exe_path_dir();
}
const char *sys_exe_path_dir(void) { const char *sys_exe_path_dir(void) {
static char path[SYS_MAX_PATH]; static char path[SYS_MAX_PATH];
if ('\0' != path[0]) { return path; } if ('\0' != path[0]) { return path; }

View file

@ -20,6 +20,7 @@ bool sys_windows_short_path_from_wcs(char *destPath, size_t destSize, const wcha
bool sys_windows_short_path_from_mbs(char* destPath, size_t destSize, const char *mbsLongPath); bool sys_windows_short_path_from_mbs(char* destPath, size_t destSize, const char *mbsLongPath);
#endif #endif
const char *sys_user_path(void); const char *sys_user_path(void);
const char *sys_resource_path(void);
const char *sys_exe_path_dir(void); const char *sys_exe_path_dir(void);
const char *sys_exe_path_file(void); const char *sys_exe_path_file(void);
const char *sys_file_extension(const char *fpath); const char *sys_file_extension(const char *fpath);