From: Holger Schemel Date: Sun, 8 Jan 2017 12:57:17 +0000 (+0100) Subject: changed program main data path (for compatibility with macOS 10.12 Sierra) X-Git-Tag: 4.0.0.1~4 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=56fe208c3f5ededc520ee0d76ad2fb72146e3dc9;p=rocksndiamonds.git changed program main data path (for compatibility with macOS 10.12 Sierra) --- diff --git a/src/libgame/macosx.h b/src/libgame/macosx.h index 2235b88d..236beccf 100644 --- a/src/libgame/macosx.h +++ b/src/libgame/macosx.h @@ -16,6 +16,7 @@ /* define some Mac OS X specific paths */ #define MAC_APP_BINARY_SUBDIR "Contents/MacOS" +#define MAC_APP_FILES_SUBDIR "Contents/Resources" /* some symbols are already defined on Mac OS X */ diff --git a/src/libgame/misc.c b/src/libgame/misc.c index bf40ca9b..4ffb51c7 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -682,6 +682,7 @@ static char *getProgramMainDataPath() #if defined(PLATFORM_MACOSX) static char *main_data_binary_subdir = NULL; + static char *main_data_files_subdir = NULL; if (main_data_binary_subdir == NULL) { @@ -693,18 +694,29 @@ static char *getProgramMainDataPath() program.program_title, MAC_APP_BINARY_SUBDIR); } - // cut relative path to Mac OS X application binary directory from path + if (main_data_files_subdir == NULL) + { + main_data_files_subdir = checked_malloc(strlen(program.program_title) + 1 + + strlen("app") + 1 + + strlen(MAC_APP_FILES_SUBDIR) + 1); + + sprintf(main_data_files_subdir, "%s.app/%s", + program.program_title, MAC_APP_FILES_SUBDIR); + } + if (strSuffix(main_data_path, main_data_binary_subdir)) - main_data_path[strlen(main_data_path) - - strlen(main_data_binary_subdir)] = '\0'; + { + char *main_data_path_old = main_data_path; + + // cut relative path to Mac OS X application binary directory from path + main_data_path_old[strlen(main_data_path_old) - + strlen(main_data_binary_subdir)] = '\0'; - // cut trailing path separator from path (but not if path is root directory) - if (strSuffix(main_data_path, "/") && !strEqual(main_data_path, "/")) - main_data_path[strlen(main_data_path) - 1] = '\0'; + // add relative path to Mac OS X application resources directory to path + main_data_path = getPath2(main_data_path_old, main_data_files_subdir); - // replace empty path with current directory - if (strEqual(main_data_path, "")) - main_data_path = "."; + free(main_data_path_old); + } #endif return main_data_path;