From 7e9dbffc3bc99162a9c7c8e9d0db1ec27ce1caa0 Mon Sep 17 00:00:00 2001 From: richardg867 Date: Wed, 20 Apr 2022 13:27:57 -0300 Subject: [PATCH] macOS: Change exe_path to be next to the .app bundle --- src/86box.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/86box.c b/src/86box.c index 4b647afed..720e33279 100644 --- a/src/86box.c +++ b/src/86box.c @@ -398,9 +398,6 @@ pc_init(int argc, char *argv[]) { char *ppath = NULL, *rpath = NULL; char *cfg = NULL, *p; -#if !defined(__APPLE__) && !defined(_WIN32) - char *appimage; -#endif char temp[2048]; struct tm *info; time_t now; @@ -413,15 +410,20 @@ pc_init(int argc, char *argv[]) /* Grab the executable's full path. */ plat_get_exe_name(exe_path, sizeof(exe_path)-1); - p = path_get_filename(exe_path); + p = path_get_filename(exe_path); *p = '\0'; - -#if !defined(_WIN32) && !defined(__APPLE__) - /* Grab the actual path if we are an AppImage. */ - appimage = getenv("APPIMAGE"); - if (appimage && (appimage[0] != '\0')) { - path_get_dirname(exe_path, appimage); +#if defined(__APPLE__) + c = strlen(exe_path); + if ((c >= 16) && !strcmp(&exe_path[c - 16], "/Contents/MacOS/")) { + exe_path[c - 16] = '\0'; + p = path_get_filename(exe_path); + *p = '\0'; } +#elif !defined(_WIN32) + /* Grab the actual path if we are an AppImage. */ + p = getenv("APPIMAGE"); + if (p && (p[0] != '\0')) + path_get_dirname(exe_path, p); #endif path_slash(exe_path);