From 3400ea457691a21b7fbd3d158cd988ad13289e58 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Wed, 8 Dec 2021 15:55:49 +0300 Subject: [PATCH] Added WD and Linux-specific /usr/* to game data search paths. Improved data not found error message. Ref #100. --- SpaceCadetPinball/pb.cpp | 2 +- SpaceCadetPinball/pb.h | 2 +- SpaceCadetPinball/pch.h | 13 ++++++++++++- SpaceCadetPinball/winmain.cpp | 30 ++++++++++++++++++++++++------ 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/SpaceCadetPinball/pb.cpp b/SpaceCadetPinball/pb.cpp index 350bd55..f3c7eb6 100644 --- a/SpaceCadetPinball/pb.cpp +++ b/SpaceCadetPinball/pb.cpp @@ -118,7 +118,7 @@ int pb::uninit() return 0; } -void pb::SelectDatFile(std::array dataSearchPaths) +void pb::SelectDatFile(const std::vector& dataSearchPaths) { DatFileName.clear(); FullTiltDemoMode = FullTiltMode = false; diff --git a/SpaceCadetPinball/pb.h b/SpaceCadetPinball/pb.h index 40a62af..ac12aa8 100644 --- a/SpaceCadetPinball/pb.h +++ b/SpaceCadetPinball/pb.h @@ -45,7 +45,7 @@ public: static int init(); static int uninit(); - static void SelectDatFile(std::array dataSearchPaths); + static void SelectDatFile(const std::vector& dataSearchPaths); static void reset_table(); static void firsttime_setup(); static void mode_change(int mode); diff --git a/SpaceCadetPinball/pch.h b/SpaceCadetPinball/pch.h index 60d9a7b..281dfd1 100644 --- a/SpaceCadetPinball/pch.h +++ b/SpaceCadetPinball/pch.h @@ -29,7 +29,7 @@ #include #include #include -#include +//#include #define SDL_MAIN_HANDLED #include "SDL.h" @@ -94,4 +94,15 @@ inline FILE* fopenu(const char* path, const char* opt) } #endif +// Platform specific data paths not found in SDL +constexpr const char* PlatformDataPaths[2] = +{ + #ifdef _WIN32 + nullptr + #else + "/usr/local/share/SpaceCadetPinball/", + "/usr/share/SpaceCadetPinball/" + #endif +}; + #endif //PCH_H diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index 084eb0e..8650159 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -114,14 +114,23 @@ int winmain::WinMain(LPCSTR lpCmdLine) auto iniPath = std::string(prefPath) + "imgui_pb.ini"; io.IniFilename = iniPath.c_str(); - // First step: just load the options, second: run updates depending on FullTiltMode + // First step: just load the options options::InitPrimary(); + + // Data search order: WD, executable path, user pref path, platform specific paths. auto basePath = SDL_GetBasePath(); - pb::SelectDatFile(std::array + std::vector searchPaths { - basePath, - prefPath - }); + { + "", + basePath, + prefPath + } + }; + searchPaths.insert(searchPaths.end(), std::begin(PlatformDataPaths), std::end(PlatformDataPaths)); + pb::SelectDatFile(searchPaths); + + // Second step: run updates depending on FullTiltMode options::InitSecondary(); if (!Sound::Init(Options.SoundChannels, Options.Sounds)) @@ -132,8 +141,17 @@ int winmain::WinMain(LPCSTR lpCmdLine) if (pb::init()) { + std::string message = "The .dat file is missing.\n" + "Make sure that the game data is present in any of the following locations:\n"; + for (auto path : searchPaths) + { + if (path) + { + message = message + (path[0] ? path : "working directory") + "\n"; + } + } SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not load game data", - "The .dat file is missing", window); + message.c_str(), window); return 1; }