Cleaned up "/" usage (avoid "//"), and in the way fixed problems

with textures that were not found (due to ealier not completely
finished clean ups).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12404 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2013-01-21 23:27:39 +00:00
parent 21eafebd92
commit bc237e8cef
5 changed files with 29 additions and 31 deletions

View File

@ -850,7 +850,7 @@ bool FileManager::isDirectory(const std::string &path) const
{ {
struct stat mystat; struct stat mystat;
std::string s(path); std::string s(path);
// At least on windows stat returns an error if there is // At least on windows stat returns an error if there is
// a '/' at the end of the path. // a '/' at the end of the path.
if(s[s.size()-1]=='/') if(s[s.size()-1]=='/')
s.erase(s.end()-1, s.end()); s.erase(s.end()-1, s.end());
@ -873,11 +873,7 @@ void FileManager::listFiles(std::set<std::string>& result,
{ {
result.clear(); result.clear();
#if defined(WIN32) std::string path = is_full_path ? dir : m_root_dir+dir;
std::string path = is_full_path ? dir : m_root_dir+"/"+dir;
#else
std::string path = is_full_path ? dir + "/" : m_root_dir+"/"+dir + "/";
#endif
#ifndef ANDROID #ifndef ANDROID
if(!isDirectory(path)) if(!isDirectory(path))

View File

@ -172,7 +172,7 @@ void KartProperties::load(const std::string &filename, const std::string &node)
m_kart_model = new KartModel(/*is_master*/true); m_kart_model = new KartModel(/*is_master*/true);
const XMLNode * root = 0; const XMLNode * root = 0;
m_root = StringUtils::getPath(filename); m_root = StringUtils::getPath(filename)+"/";
m_ident = StringUtils::getBasename(StringUtils::getPath(filename)); m_ident = StringUtils::getBasename(StringUtils::getPath(filename));
try try
{ {
@ -202,14 +202,14 @@ void KartProperties::load(const std::string &filename, const std::string &node)
// Load material // Load material
std::string materials_file = m_root+"/materials.xml"; std::string materials_file = m_root+"materials.xml";
file_manager->pushModelSearchPath (m_root); file_manager->pushModelSearchPath (m_root);
file_manager->pushTextureSearchPath(m_root); file_manager->pushTextureSearchPath(m_root);
// addShared makes sure that these textures/material infos stay in memory // addShared makes sure that these textures/material infos stay in memory
material_manager->addSharedMaterial(materials_file); material_manager->addSharedMaterial(materials_file);
m_icon_file = m_root+"/"+m_icon_file; m_icon_file = m_root+m_icon_file;
// Make permanent is important, since otherwise icons can get deleted // Make permanent is important, since otherwise icons can get deleted
// (e.g. when freeing temp. materials from a track, the last icon // (e.g. when freeing temp. materials from a track, the last icon
@ -218,7 +218,7 @@ void KartProperties::load(const std::string &filename, const std::string &node)
/*is_full+path*/true, /*is_full+path*/true,
/*make_permanent*/true); /*make_permanent*/true);
if(m_minimap_icon_file!="") if(m_minimap_icon_file!="")
m_minimap_icon = irr_driver->getTexture(m_root+"/"+m_minimap_icon_file); m_minimap_icon = irr_driver->getTexture(m_root+m_minimap_icon_file);
else else
m_minimap_icon = NULL; m_minimap_icon = NULL;

View File

@ -169,7 +169,7 @@ void KartPropertiesManager::loadAllKarts(bool loading_icon)
for(std::set<std::string>::const_iterator subdir=result.begin(); for(std::set<std::string>::const_iterator subdir=result.begin();
subdir!=result.end(); subdir++) subdir!=result.end(); subdir++)
{ {
const bool loaded = loadKart(*dir+"/"+*subdir); const bool loaded = loadKart(*dir+*subdir);
if (loaded && loading_icon) if (loaded && loading_icon)
{ {
@ -189,9 +189,8 @@ void KartPropertiesManager::loadAllKarts(bool loading_icon)
bool KartPropertiesManager::loadKart(const std::string &dir) bool KartPropertiesManager::loadKart(const std::string &dir)
{ {
std::string config_filename=dir+"/kart.xml"; std::string config_filename=dir+"/kart.xml";
FILE *f=fopen(config_filename.c_str(), "r"); if(!file_manager->fileExists(config_filename))
if(!f) return false; return false;
fclose(f);
KartProperties* kart_properties; KartProperties* kart_properties;
try try

View File

@ -81,8 +81,12 @@ Track::Track(const std::string &filename)
m_materials_loaded = false; m_materials_loaded = false;
m_filename = filename; m_filename = filename;
m_root = StringUtils::getPath(StringUtils::removeExtension(m_filename)); m_root =
StringUtils::getPath(StringUtils::removeExtension(m_filename));
m_ident = StringUtils::getBasename(m_root); m_ident = StringUtils::getBasename(m_root);
// The directory should always have a '/' at the end, but getBasename
// above returns "" if a "/" is at the end, so we add the "/" here.
m_root += "/";
m_designer = ""; m_designer = "";
m_screenshot = ""; m_screenshot = "";
m_version = 0; m_version = 0;
@ -362,11 +366,11 @@ void Track::loadTrackInfo()
if(xml_node) loadCurves(*xml_node); if(xml_node) loadCurves(*xml_node);
// Set the correct paths // Set the correct paths
m_screenshot = m_root+"/"+m_screenshot; m_screenshot = m_root+m_screenshot;
delete root; delete root;
std::string dir = StringUtils::getPath(m_filename); std::string dir = StringUtils::getPath(m_filename);
std::string easter_name = dir+"/easter_eggs.xml"; std::string easter_name = dir+"easter_eggs.xml";
m_has_easter_eggs = file_manager->fileExists(easter_name); m_has_easter_eggs = file_manager->fileExists(easter_name);
} // loadTrackInfo } // loadTrackInfo
@ -394,7 +398,7 @@ void Track::getMusicInformation(std::vector<std::string>& filenames,
{ {
for(int i=0; i<(int)filenames.size(); i++) for(int i=0; i<(int)filenames.size(); i++)
{ {
std::string full_path = m_root+"/"+filenames[i]; std::string full_path = m_root+filenames[i];
MusicInformation* mi = music_manager->getMusicInformation(full_path); MusicInformation* mi = music_manager->getMusicInformation(full_path);
if(!mi) if(!mi)
{ {
@ -438,8 +442,8 @@ void Track::startMusic() const
*/ */
void Track::loadQuadGraph(unsigned int mode_id, const bool reverse) void Track::loadQuadGraph(unsigned int mode_id, const bool reverse)
{ {
QuadGraph::create(m_root+"/"+m_all_modes[mode_id].m_quad_name, QuadGraph::create(m_root+m_all_modes[mode_id].m_quad_name,
m_root+"/"+m_all_modes[mode_id].m_graph_name, m_root+m_all_modes[mode_id].m_graph_name,
reverse); reverse);
QuadGraph::get()->setupPaths(); QuadGraph::get()->setupPaths();
@ -718,7 +722,7 @@ bool Track::loadMainTrack(const XMLNode &root)
const XMLNode *track_node= root.getNode("track"); const XMLNode *track_node= root.getNode("track");
std::string model_name; std::string model_name;
track_node->get("model", &model_name); track_node->get("model", &model_name);
std::string full_path = m_root+"/"+model_name; std::string full_path = m_root+model_name;
scene::IMesh *mesh = irr_driver->getMesh(full_path); scene::IMesh *mesh = irr_driver->getMesh(full_path);
if(!mesh) if(!mesh)
{ {
@ -921,7 +925,7 @@ bool Track::loadMainTrack(const XMLNode &root)
scene::ISceneNode* scene_node; scene::ISceneNode* scene_node;
model_name=""; model_name="";
n->get("model", &model_name); n->get("model", &model_name);
full_path = m_root+"/"+model_name; full_path = m_root+model_name;
// a special challenge orb object for overworld // a special challenge orb object for overworld
std::string challenge; std::string challenge;
@ -1183,7 +1187,7 @@ void Track::createWater(const XMLNode &node)
{ {
std::string model_name; std::string model_name;
node.get("model", &model_name); node.get("model", &model_name);
std::string full_path = m_root+"/"+model_name; std::string full_path = m_root+model_name;
scene::IMesh *mesh = irr_driver->getMesh(full_path); scene::IMesh *mesh = irr_driver->getMesh(full_path);
if (mesh == NULL) return; if (mesh == NULL) return;
@ -1295,7 +1299,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
// First read the temporary materials.dat file if it exists // First read the temporary materials.dat file if it exists
try try
{ {
std::string materials_file = m_root+"/materials.xml"; std::string materials_file = m_root+"materials.xml";
if(m_cache_track) if(m_cache_track)
{ {
if(!m_materials_loaded) if(!m_materials_loaded)
@ -1312,7 +1316,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
} }
// Start building the scene graph // Start building the scene graph
std::string path = m_root+"/"+m_all_modes[mode_id].m_scene; std::string path = m_root+m_all_modes[mode_id].m_scene;
XMLNode *root = file_manager->createXMLTree(path); XMLNode *root = file_manager->createXMLTree(path);
// Make sure that we have a track (which is used for raycasts to // Make sure that we have a track (which is used for raycasts to
@ -1682,7 +1686,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
if(easter_world) if(easter_world)
{ {
std::string dir = StringUtils::getPath(m_filename); std::string dir = StringUtils::getPath(m_filename);
easter_world->readData(dir+"/easter_eggs.xml"); easter_world->readData(dir+"easter_eggs.xml");
} }
} // loadTrackModel } // loadTrackModel

View File

@ -148,7 +148,7 @@ void TrackManager::loadTrackList()
subdir != dirs.end(); subdir++) subdir != dirs.end(); subdir++)
{ {
if(*subdir=="." || *subdir=="..") continue; if(*subdir=="." || *subdir=="..") continue;
loadTrack(dir+*subdir); loadTrack(dir+*subdir+"/");
} // for dir in dirs } // for dir in dirs
} // for i <m_track_search_path.size() } // for i <m_track_search_path.size()
} // loadTrackList } // loadTrackList
@ -160,10 +160,9 @@ void TrackManager::loadTrackList()
*/ */
bool TrackManager::loadTrack(const std::string& dirname) bool TrackManager::loadTrack(const std::string& dirname)
{ {
std::string config_file = dirname+"/track.xml"; std::string config_file = dirname+"track.xml";
FILE *f=fopen(config_file.c_str(),"r"); if(!file_manager->fileExists(config_file))
if(!f) return false; return false;
fclose(f);
Track *track; Track *track;