From 306f6fa9d7f60d786d3e6317c1a2ca7befe5f684 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 29 Aug 2016 23:47:15 +0100 Subject: [PATCH] Use findFilePath when loading data files This should make file loading more reliable for case sensitive operating systems. --- rwengine/src/engine/GameData.cpp | 66 +++++++++++++++++--------------- rwengine/src/engine/GameData.hpp | 2 +- rwgame/RWGame.cpp | 5 --- rwviewer/ViewerWindow.cpp | 4 -- tests/test_globals.hpp | 2 - 5 files changed, 37 insertions(+), 42 deletions(-) diff --git a/rwengine/src/engine/GameData.cpp b/rwengine/src/engine/GameData.cpp index 47c32ae2..018379cc 100644 --- a/rwengine/src/engine/GameData.cpp +++ b/rwengine/src/engine/GameData.cpp @@ -51,9 +51,13 @@ void GameData::load() { index.indexGameDirectory(datpath); index.indexTree(datpath); - - parseDAT(datpath+"/data/default.dat"); - parseDAT(datpath+"/data/gta3.dat"); + + // Initalize all the archives. + loadIMG("models/gta3.img"); + loadIMG("anim/cuts.img"); + + parseDAT("data/default.dat"); + parseDAT("data/gta3.dat"); loadDFF("wheels.dff"); loadDFF("weapons.dff"); @@ -63,20 +67,20 @@ void GameData::load() loadTXD("hud.txd"); loadTXD("fonts.txd"); - loadCarcols(datpath+"/data/carcols.dat"); - loadWeather(datpath+"/data/timecyc.dat"); - loadHandling(datpath+"/data/handling.cfg"); - loadWaterpro(datpath+"/data/waterpro.dat"); - loadWater(datpath+"/data/water.dat"); - loadWeaponDAT(datpath+"/data/weapon.dat"); + loadCarcols("data/carcols.dat"); + loadWeather("data/timecyc.dat"); + loadHandling("data/handling.cfg"); + loadWaterpro("data/waterpro.dat"); + loadWeaponDAT("data/weapon.dat"); loadIFP("ped.ifp"); } void GameData::parseDAT(const std::string& path) { - std::ifstream datfile(path.c_str()); - + auto datpath = index.findFilePath(path); + std::ifstream datfile(datpath.c_str()); + if(!datfile.is_open()) { logger->error("Data", "Failed to open game file " + path); @@ -111,20 +115,16 @@ void GameData::parseDAT(const std::string& path) else if(cmd == "IPL") { auto path = line.substr(space+1); - auto systempath = index.findFilePath(path); - loadIPL(systempath.native()); + auto systempath = index.findFilePath(path).native(); + loadIPL(systempath); } - else if(cmd == "TEXDICTION") + else if(cmd == "TEXDICTION") { - std::string texpath = line.substr(space+1); - for( size_t t = 0; t < texpath.size(); ++t) { - texpath[t] = tolower(texpath[t]); - if(texpath[t] == '\\') { - texpath[t] = '/'; - } - } - std::string texname = texpath.substr(texpath.find_last_of("/")+1); - loadTXD(texname); + auto path = line.substr(space+1); + /// @todo improve TXD handling + auto name = index.findFilePath(path).filename().native(); + std::transform(name.begin(), name.end(), name.begin(), ::tolower); + loadTXD(name); } } } @@ -194,7 +194,8 @@ void GameData::loadCOL(const size_t zone, const std::string& name) void GameData::loadIMG(const std::string& name) { - index.indexArchive(datpath + name); + auto syspath = index.findFilePath(name).native(); + index.indexArchive(syspath); } void GameData::loadIPL(const std::string& name) @@ -232,7 +233,8 @@ enum ColSection { void GameData::loadCarcols(const std::string& path) { - std::ifstream fstream(path.c_str()); + auto syspath = index.findFilePath(path); + std::ifstream fstream(syspath.c_str()); std::string line; ColSection currentSection = Unknown; @@ -283,14 +285,16 @@ void GameData::loadCarcols(const std::string& path) void GameData::loadWeather(const std::string &path) { - weatherLoader.load(path); + auto syspath = index.findFilePath(path).native(); + weatherLoader.load(syspath); } void GameData::loadHandling(const std::string& path) { GenericDATLoader l; + auto syspath = index.findFilePath(path).native(); - l.loadHandling(path, vehicleInfo); + l.loadHandling(syspath, vehicleInfo); } SCMFile *GameData::loadSCM(const std::string &name) @@ -313,7 +317,8 @@ void GameData::loadGXT(const std::string &name) void GameData::loadWaterpro(const std::string& path) { - std::ifstream ifstr(path.c_str(), std::ios_base::binary); + auto syspath = index.findFilePath(path); + std::ifstream ifstr(syspath.c_str(), std::ios_base::binary); if(ifstr.is_open()) { uint32_t numlevels; @@ -425,11 +430,12 @@ void GameData::loadDynamicObjects(const std::string& name) l.loadDynamicObjects(name, dynamicObjectData); } -void GameData::loadWeaponDAT(const std::string &name) +void GameData::loadWeaponDAT(const std::string &path) { GenericDATLoader l; + auto syspath = index.findFilePath(path).native(); - l.loadWeapons(name, weaponData); + l.loadWeapons(syspath, weaponData); } bool GameData::loadAudioStream(const std::string &name) diff --git a/rwengine/src/engine/GameData.hpp b/rwengine/src/engine/GameData.hpp index 0ae50a4d..6ca00102 100644 --- a/rwengine/src/engine/GameData.hpp +++ b/rwengine/src/engine/GameData.hpp @@ -145,7 +145,7 @@ public: /** * Loads weapon.dat */ - void loadWeaponDAT(const std::string& name); + void loadWeaponDAT(const std::string& path); bool loadAudioStream(const std::string& name); bool loadAudioClip(const std::string& name, const std::string& fileName); diff --git a/rwgame/RWGame.cpp b/rwgame/RWGame.cpp index 6bfce6e3..92a30ec5 100644 --- a/rwgame/RWGame.cpp +++ b/rwgame/RWGame.cpp @@ -103,11 +103,6 @@ RWGame::RWGame(int argc, char* argv[]) data = new GameData(&log, work, config.getGameDataPath()); - // Initalize all the archives. - data->loadIMG("/models/gta3"); - //engine->data.loadIMG("/models/txd"); - data->loadIMG("/anim/cuts"); - data->load(); // Initialize renderer diff --git a/rwviewer/ViewerWindow.cpp b/rwviewer/ViewerWindow.cpp index e370db4e..3355cb86 100644 --- a/rwviewer/ViewerWindow.cpp +++ b/rwviewer/ViewerWindow.cpp @@ -167,10 +167,6 @@ void ViewerWindow::loadGame(const QString &path) gameWorld->data->load(); - // Initalize all the archives. - gameWorld->data->loadIMG("/models/gta3"); - gameWorld->data->loadIMG("/anim/cuts"); - loadedData(gameWorld); } diff --git a/tests/test_globals.hpp b/tests/test_globals.hpp index 810fe3dc..042a1a1e 100644 --- a/tests/test_globals.hpp +++ b/tests/test_globals.hpp @@ -79,8 +79,6 @@ public: #if RW_TEST_WITH_DATA d = new GameData(&log, &work, getGamePath()); - d->loadIMG("/models/gta3"); - d->loadIMG("/anim/cuts"); d->load(); e = new GameWorld(&log, &work, d);