diff --git a/CMakeLists.txt b/CMakeLists.txt index ed1229767..4a14b35fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,13 +194,28 @@ find_package(plog REQUIRED) if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") message("Building for Linux") - add_compile_definitions(POSIX __LINUX__ _USE_OGL_ACTIVE_TEXTURES PRIMARY_HOG=\"d3-linux.hog\") + add_compile_definitions(POSIX __LINUX__) + set(D3_PRIMARY_HOG "d3-linux.hog") + set(D3_STANDARD_PATHS + "~/.local/share/Steam/steamapps/common/Descent 3" # Fedora, arch + "~/.steam/debian-installation/steamapps/common/Descent 3" # Debian & derivatives + ) elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") message("Building for macOS") - add_compile_definitions(POSIX MACOSX=1 _USE_OGL_ACTIVE_TEXTURES PRIMARY_HOG=\"d3-osx.hog\") + add_compile_definitions(POSIX MACOSX=1) + set(D3_PRIMARY_HOG "d3-osx.hog") + set(D3_STANDARD_PATHS + "~/Library/Application Support/Steam/steamapps/common/Descent 3/Descent 3.app/Contents/Resources" + ) elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(D3_PRIMARY_HOG "d3-win.hog") + set(D3_STANDARD_PATHS + "C:\\\\Program Files (x86)\\\\Steam\\\\steamapps\\\\common\\\\Descent 3" + "C:\\\\Program Files (x86)\\\\GOG Galaxy\\\\Games\\\\Descent 3" + ) + # Windows.h defines to avoid as many issues as possible. - add_compile_definitions(WIN32_LEAN_AND_MEAN NOMINMAX NODRAWTEXT NOBITMAP NOMCX NOSERVICE PRIMARY_HOG=\"d3-win.hog\" + add_compile_definitions(WIN32_LEAN_AND_MEAN NOMINMAX NODRAWTEXT NOBITMAP NOMCX NOSERVICE #[[NOGDI]] # We need GDI for now, enable when GDI is actually not needed (or when all windows.h mentions are gone) ) @@ -238,6 +253,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") add_compile_options("/MP") # so msbuild builds with multiple processes endif() +string(REPLACE ";" "\", \"" D3_STANDARD_PATHS_CPP "${D3_STANDARD_PATHS}") + add_compile_definitions($<$:RELEASE>) add_compile_definitions($<$:_DEBUG>) diff --git a/Descent3/init.cpp b/Descent3/init.cpp index c719ee373..3236ce71d 100644 --- a/Descent3/init.cpp +++ b/Descent3/init.cpp @@ -1444,7 +1444,22 @@ void InitIOSystems(bool editor) { // Platform dependent paths std::filesystem::path platform_dir = std::filesystem::canonical(D3_DATADIR); cf_AddBaseDirectory(platform_dir); - // TODO: add Steam/registry locations + + std::vector default_platform_dirs = { + D3_STANDARD_PATHS + }; + + for (const auto& platform_dir: default_platform_dirs) { + if (platform_dir.u8string().at(0) == '~') { + // On Unix, replace "~" in paths by the runtime $HOME directory + std::string base_dir_str = platform_dir.u8string(); + const std::string home_dir = std::getenv("HOME"); + base_dir_str.replace(0,1,home_dir); + cf_AddBaseDirectory(std::filesystem::path(base_dir_str)); + } else { + cf_AddBaseDirectory(platform_dir); + } + } // Add path of executable std::filesystem::path exec_path = ddio_GetBasePath(); @@ -1534,7 +1549,7 @@ void InitIOSystems(bool editor) { // last library opened is the first to be searched for dynamic libs, so put // this one at the end to find our newly build script libraries first - sys_hid = cf_OpenLibrary(PRIMARY_HOG); + sys_hid = cf_OpenLibrary(D3_PRIMARY_HOG); // Check to see if there is a -mission command line option // if there is, attempt to open that hog/mn3 so it can override such diff --git a/ddio/ddio.h b/ddio/ddio.h index ff2038741..404d1a682 100644 --- a/ddio/ddio.h +++ b/ddio/ddio.h @@ -318,9 +318,6 @@ void ddio_MouseSetVCoords(int width, int height); // File Operations // --------------------------------------------------------------------------- -// Gets the full path of the executable file -bool ddio_GetBinaryPath(char *exec_path, size_t len); - // deletes a file. Returns 1 if successful, 0 on failure // This pathname is *RELATIVE* not fully qualified int ddio_DeleteFile(const char *name); diff --git a/ddio/lnxio.cpp b/ddio/lnxio.cpp index c96173b2b..886692d79 100644 --- a/ddio/lnxio.cpp +++ b/ddio/lnxio.cpp @@ -106,33 +106,3 @@ void ddio_DebugMessage(unsigned err, char *fmt, ...) { LOG_DEBUG << buf; } -bool ddio_GetBinaryPath(char *exec_path, size_t len) { -#ifdef MACOSX - if (exec_path == NULL || len == 0) { - LOG_ERROR << "Invalid arguments"; - return false; - } - - uint32_t size = (uint32_t)len; - if (_NSGetExecutablePath(exec_path, &size) != 0) { - LOG_ERROR.printf("Buffer too small; need size %u", size); - return false; - } -#elif defined(__LINUX__) - if (realpath("/proc/self/exe", exec_path) == NULL) { - perror("realpath"); - return false; - } -#else - if (GetModuleFileName(NULL, exec_path, len) == 0) { - DWORD error = GetLastError(); - LOG_ERROR << "GetModuleFileName failed!"; - return false; - } - exec_path[len - 1] = '\0'; - return true; - -#endif - exec_path[len - 1] = '\0'; - return true; -} diff --git a/lib/d3_platform_path.h.in b/lib/d3_platform_path.h.in index 3c360e6ab..5ce9384d0 100644 --- a/lib/d3_platform_path.h.in +++ b/lib/d3_platform_path.h.in @@ -21,6 +21,12 @@ // Platform-specific compile-time defined location of data files #define D3_DATADIR "@D3_DATADIR@" +// Standard Descent 3 installation locations for the platform (Steam, GoG...) +#define D3_STANDARD_PATHS "@D3_STANDARD_PATHS_CPP@" + +// .hog file shipped with the game +#define D3_PRIMARY_HOG "@D3_PRIMARY_HOG@" + // Part of preference path (organization) #define D3_PREF_ORG "Outrage Entertainment"