From 7f37eccf619e600a60d5b4bd18bd28a5cfdec925 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Tue, 13 Dec 2022 21:28:26 -0500 Subject: [PATCH] Extend Sys_DefaultBasePath() to check IDE build path for linux and macOS --- neo/sys/posix/posix_main.cpp | 52 +++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/neo/sys/posix/posix_main.cpp b/neo/sys/posix/posix_main.cpp index 254bd450..c66656bf 100644 --- a/neo/sys/posix/posix_main.cpp +++ b/neo/sys/posix/posix_main.cpp @@ -101,6 +101,7 @@ const char* Sys_DefaultSavePath() if( base_path ) { savepath = SDL_strdup( base_path ); + savepath.StripTrailing( '/' ); SDL_free( base_path ); } #else @@ -410,8 +411,9 @@ Sys_DefaultBasePath Get the default base path - binary image path -- MacOS app bundle resources directory path // SRS - Added MacOS app bundle resources path - current directory +- build directory path // SRS - added build directory path +- macOS app bundle resources directory path // SRS - added macOS app bundle resources path - hardcoded Try to be intelligent: if there is no BASE_GAMEDIR, try the next path ================ @@ -419,11 +421,12 @@ Try to be intelligent: if there is no BASE_GAMEDIR, try the next path const char* Sys_DefaultBasePath() { struct stat st; - idStr testbase; + idStr testbase, exepath = {}; basepath = Sys_EXEPath(); if( basepath.Length() ) { basepath.StripFilename(); + exepath = basepath; testbase = basepath; testbase += "/"; testbase += BASE_GAMEDIR; @@ -435,20 +438,6 @@ const char* Sys_DefaultBasePath() { common->Printf( "no '%s' directory in exe path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() ); } -#if defined(__APPLE__) // SRS - - Added check for MacOS app bundle resources path - basepath += "/../Resources"; - testbase = basepath; - testbase += "/"; - testbase += BASE_GAMEDIR; - if( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) - { - return basepath.c_str(); - } - else - { - common->Printf( "no '%s' directory in MacOS app bundle resources path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() ); - } -#endif } if( basepath != Posix_Cwd() ) { @@ -465,6 +454,37 @@ const char* Sys_DefaultBasePath() common->Printf( "no '%s' directory in cwd path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() ); } } + if( exepath.Length() ) + { + // SRS - Check for linux/macOS build path (standard IDE structure with build dir and config suffixes) + basepath = exepath + "/../.."; + testbase = basepath; + testbase += "/"; + testbase += BASE_GAMEDIR; + if( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) + { + return basepath.c_str(); + } + else + { + common->Printf( "no '%s' directory in build path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() ); + } +#if defined(__APPLE__) + // SRS - Check for macOS app bundle resources path + basepath = exepath + "/../Resources"; + testbase = basepath; + testbase += "/"; + testbase += BASE_GAMEDIR; + if( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) + { + return basepath.c_str(); + } + else + { + common->Printf( "no '%s' directory in macOS app bundle resources path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() ); + } +#endif + } common->Printf( "WARNING: using hardcoded default base path %s\n", DEFAULT_BASEPATH ); return DEFAULT_BASEPATH; }