1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-25 03:42:48 +01:00

Use findFilePath when loading data files

This should make file loading more reliable for case sensitive
operating systems.
This commit is contained in:
dan 2016-08-29 23:47:15 +01:00 committed by Daniel Evans
parent 674ce55af3
commit 306f6fa9d7
5 changed files with 37 additions and 42 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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

View File

@ -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);
}

View File

@ -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);