1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-12-18 10:37:53 +01:00

Added WD and Linux-specific /usr/* to game data search paths.

Improved data not found error message.
Ref #100.
This commit is contained in:
Muzychenko Andrey 2021-12-08 15:55:49 +03:00
parent 389122182e
commit 3400ea4576
4 changed files with 38 additions and 9 deletions

View file

@ -118,7 +118,7 @@ int pb::uninit()
return 0; return 0;
} }
void pb::SelectDatFile(std::array<char*, 2> dataSearchPaths) void pb::SelectDatFile(const std::vector<const char*>& dataSearchPaths)
{ {
DatFileName.clear(); DatFileName.clear();
FullTiltDemoMode = FullTiltMode = false; FullTiltDemoMode = FullTiltMode = false;

View file

@ -45,7 +45,7 @@ public:
static int init(); static int init();
static int uninit(); static int uninit();
static void SelectDatFile(std::array<char*, 2> dataSearchPaths); static void SelectDatFile(const std::vector<const char*>& dataSearchPaths);
static void reset_table(); static void reset_table();
static void firsttime_setup(); static void firsttime_setup();
static void mode_change(int mode); static void mode_change(int mode);

View file

@ -29,7 +29,7 @@
#include <string> #include <string>
#include <thread> #include <thread>
#include <map> #include <map>
#include <array> //#include <array>
#define SDL_MAIN_HANDLED #define SDL_MAIN_HANDLED
#include "SDL.h" #include "SDL.h"
@ -94,4 +94,15 @@ inline FILE* fopenu(const char* path, const char* opt)
} }
#endif #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 #endif //PCH_H

View file

@ -114,14 +114,23 @@ int winmain::WinMain(LPCSTR lpCmdLine)
auto iniPath = std::string(prefPath) + "imgui_pb.ini"; auto iniPath = std::string(prefPath) + "imgui_pb.ini";
io.IniFilename = iniPath.c_str(); 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(); options::InitPrimary();
// Data search order: WD, executable path, user pref path, platform specific paths.
auto basePath = SDL_GetBasePath(); auto basePath = SDL_GetBasePath();
pb::SelectDatFile(std::array<char*, 2> std::vector<const char*> searchPaths
{ {
{
"",
basePath, basePath,
prefPath prefPath
}); }
};
searchPaths.insert(searchPaths.end(), std::begin(PlatformDataPaths), std::end(PlatformDataPaths));
pb::SelectDatFile(searchPaths);
// Second step: run updates depending on FullTiltMode
options::InitSecondary(); options::InitSecondary();
if (!Sound::Init(Options.SoundChannels, Options.Sounds)) if (!Sound::Init(Options.SoundChannels, Options.Sounds))
@ -132,8 +141,17 @@ int winmain::WinMain(LPCSTR lpCmdLine)
if (pb::init()) 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", SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not load game data",
"The .dat file is missing", window); message.c_str(), window);
return 1; return 1;
} }