Solving Issue 1180 - Load addon GPs from local folder

This commit is contained in:
konstin 2014-03-05 12:11:20 +01:00
parent 8600d3bc61
commit c09a3172f1
8 changed files with 174 additions and 116 deletions

View File

@ -396,45 +396,48 @@ namespace UserConfigParams
PARAM_DEFAULT( BoolUserConfigParam(false, "player_last", PARAM_DEFAULT( BoolUserConfigParam(false, "player_last",
&m_gp_start_order, &m_gp_start_order,
"Always put the player at the back or not (Bully mode).") ); "Always put the player at the back or not (Bully mode).") );
PARAM_PREFIX StringUserConfigParam m_additional_gp_directory
PARAM_DEFAULT( StringUserConfigParam("", "additional_gp_directory",
"Directory with additional GP's."));
// ---- Video // ---- Video
PARAM_PREFIX GroupUserConfigParam m_video_group PARAM_PREFIX GroupUserConfigParam m_video_group
PARAM_DEFAULT( GroupUserConfigParam("Video", "Video Settings") ); PARAM_DEFAULT( GroupUserConfigParam("Video", "Video Settings") );
PARAM_PREFIX IntUserConfigParam m_width PARAM_PREFIX IntUserConfigParam m_width
PARAM_DEFAULT( IntUserConfigParam(1024, "width", &m_video_group, PARAM_DEFAULT( IntUserConfigParam(1024, "width", &m_video_group,
"Screen/window width in pixels") ); "Screen/window width in pixels") );
PARAM_PREFIX IntUserConfigParam m_height PARAM_PREFIX IntUserConfigParam m_height
PARAM_DEFAULT( IntUserConfigParam(768, "height", &m_video_group, PARAM_DEFAULT( IntUserConfigParam(768, "height", &m_video_group,
"Screen/window height in pixels") ); "Screen/window height in pixels") );
PARAM_PREFIX BoolUserConfigParam m_fullscreen PARAM_PREFIX BoolUserConfigParam m_fullscreen
PARAM_DEFAULT( BoolUserConfigParam(false, "fullscreen", PARAM_DEFAULT( BoolUserConfigParam(false, "fullscreen",
&m_video_group) ); &m_video_group) );
PARAM_PREFIX IntUserConfigParam m_prev_width PARAM_PREFIX IntUserConfigParam m_prev_width
PARAM_DEFAULT( IntUserConfigParam(1024, "prev_width", PARAM_DEFAULT( IntUserConfigParam(1024, "prev_width",
&m_video_group, "Previous screen/window width") ); &m_video_group, "Previous screen/window width") );
PARAM_PREFIX IntUserConfigParam m_prev_height PARAM_PREFIX IntUserConfigParam m_prev_height
PARAM_DEFAULT( IntUserConfigParam(768, "prev_height", PARAM_DEFAULT( IntUserConfigParam(768, "prev_height",
&m_video_group,"Previous screen/window height") ); &m_video_group,"Previous screen/window height") );
PARAM_PREFIX BoolUserConfigParam m_prev_fullscreen PARAM_PREFIX BoolUserConfigParam m_prev_fullscreen
PARAM_DEFAULT( BoolUserConfigParam(false, "prev_fullscreen", PARAM_DEFAULT( BoolUserConfigParam(false, "prev_fullscreen",
&m_video_group) ); &m_video_group) );
PARAM_PREFIX BoolUserConfigParam m_remember_window_location PARAM_PREFIX BoolUserConfigParam m_remember_window_location
PARAM_DEFAULT( BoolUserConfigParam(false, "remember_window_location", PARAM_DEFAULT( BoolUserConfigParam(false, "remember_window_location",
&m_video_group) ); &m_video_group) );
PARAM_PREFIX IntUserConfigParam m_window_x PARAM_PREFIX IntUserConfigParam m_window_x
PARAM_DEFAULT( IntUserConfigParam(-1, "window_x", PARAM_DEFAULT( IntUserConfigParam(-1, "window_x",
&m_video_group,"If remember_window_location is true") ); &m_video_group,"If remember_window_location is true") );
PARAM_PREFIX IntUserConfigParam m_window_y PARAM_PREFIX IntUserConfigParam m_window_y
PARAM_DEFAULT( IntUserConfigParam(-1, "window_y", PARAM_DEFAULT( IntUserConfigParam(-1, "window_y",
&m_video_group,"If remember_window_location is true") ); &m_video_group,"If remember_window_location is true") );
PARAM_PREFIX BoolUserConfigParam m_display_fps PARAM_PREFIX BoolUserConfigParam m_display_fps
PARAM_DEFAULT( BoolUserConfigParam(false, "show_fps", PARAM_DEFAULT( BoolUserConfigParam(false, "show_fps",
&m_video_group, "Display frame per seconds") ); &m_video_group, "Display frame per seconds") );
PARAM_PREFIX IntUserConfigParam m_max_fps PARAM_PREFIX IntUserConfigParam m_max_fps
PARAM_DEFAULT( IntUserConfigParam(120, "max_fps", PARAM_DEFAULT( IntUserConfigParam(120, "max_fps",
&m_video_group, "Maximum fps, should be at least 60") ); &m_video_group, "Maximum fps, should be at least 60") );

View File

@ -507,8 +507,8 @@ void FileManager::popModelSearchPath()
* \return True if the file is found, false otherwise. * \return True if the file is found, false otherwise.
*/ */
bool FileManager::findFile(std::string& full_path, bool FileManager::findFile(std::string& full_path,
const std::string& file_name, const std::string& file_name,
const std::vector<std::string>& search_path) const const std::vector<std::string>& search_path) const
{ {
for(std::vector<std::string>::const_reverse_iterator for(std::vector<std::string>::const_reverse_iterator
i = search_path.rbegin(); i = search_path.rbegin();
@ -517,7 +517,7 @@ bool FileManager::findFile(std::string& full_path,
full_path = *i + file_name; full_path = *i + file_name;
if(m_file_system->existFile(full_path.c_str())) return true; if(m_file_system->existFile(full_path.c_str())) return true;
} }
full_path=""; full_path = "";
return false; return false;
} // findFile } // findFile

View File

@ -47,7 +47,7 @@ public:
/** The various asset types (and directories) STK might request. /** The various asset types (and directories) STK might request.
* The last entry ASSET_COUNT specifies the number of entries. */ * The last entry ASSET_COUNT specifies the number of entries. */
enum AssetType {ASSET_MIN, enum AssetType {ASSET_MIN,
CHALLENGE=ASSET_MIN, CHALLENGE = ASSET_MIN,
FONT, GFX, GRANDPRIX, GUI, MODEL, MUSIC, FONT, GFX, GRANDPRIX, GUI, MODEL, MUSIC,
SFX, SHADER, SKIN, TEXTURE, TRANSLATION, SFX, SHADER, SKIN, TEXTURE, TRANSLATION,
ASSET_MAX = TRANSLATION, ASSET_MAX = TRANSLATION,
@ -55,7 +55,7 @@ public:
private: private:
/** The names of the various subdirectories of the asset types. */ /** The names of the various subdirectories of the asset types. */
std::vector< std::string > m_subdir_name; std::vector<std::string> m_subdir_name;
/** Handle to irrlicht's file systems. */ /** Handle to irrlicht's file systems. */
io::IFileSystem *m_file_system; io::IFileSystem *m_file_system;
@ -73,64 +73,65 @@ private:
std::string m_screenshot_dir; std::string m_screenshot_dir;
std::vector<std::string> std::vector<std::string>
m_texture_search_path, m_texture_search_path,
m_model_search_path, m_model_search_path,
m_music_search_path; m_music_search_path;
bool findFile(std::string& full_path, bool findFile(std::string& full_path,
const std::string& fname, const std::string& fname,
const std::vector<std::string>& search_path) const std::vector<std::string>& search_path)
const; const;
void makePath(std::string& path, const std::string& dir, void makePath(std::string& path, const std::string& dir,
const std::string& fname) const; const std::string& fname) const;
bool checkAndCreateDirectory(const std::string &path); bool checkAndCreateDirectory(const std::string &path);
io::path createAbsoluteFilename(const std::string &f); io::path createAbsoluteFilename(const std::string &f);
void checkAndCreateConfigDir(); void checkAndCreateConfigDir();
bool isDirectory(const std::string &path) const; bool isDirectory(const std::string &path) const;
void checkAndCreateAddonsDir(); void checkAndCreateAddonsDir();
void checkAndCreateScreenshotDir(); void checkAndCreateScreenshotDir();
#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__APPLE__) #if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__APPLE__)
std::string checkAndCreateLinuxDir(const char *env_name, std::string checkAndCreateLinuxDir(const char *env_name,
const char *dir_name, const char *dir_name,
const char *fallback1, const char *fallback1,
const char *fallback2=NULL); const char *fallback2=NULL);
#endif #endif
public: public:
FileManager(); FileManager();
~FileManager(); ~FileManager();
void reInit(); void reInit();
void dropFileSystem(); void dropFileSystem();
static void addRootDirs(const std::string &roots); static void addRootDirs(const std::string &roots);
io::IXMLReader *createXMLReader(const std::string &filename); io::IXMLReader *createXMLReader(const std::string &filename);
XMLNode *createXMLTree(const std::string &filename); XMLNode *createXMLTree(const std::string &filename);
XMLNode *createXMLTreeFromString(const std::string & content); XMLNode *createXMLTreeFromString(const std::string & content);
std::string getScreenshotDir() const; std::string getScreenshotDir() const;
bool checkAndCreateDirectoryP(const std::string &path); bool checkAndCreateDirectoryP(const std::string &path);
const std::string &getAddonsDir() const; const std::string &getAddonsDir() const;
std::string getAddonsFile(const std::string &name); std::string getAddonsFile(const std::string &name);
void checkAndCreateDirForAddons(const std::string &dir); void checkAndCreateDirForAddons(const std::string &dir);
bool removeFile(const std::string &name) const; bool removeFile(const std::string &name) const;
bool removeDirectory(const std::string &name) const; bool removeDirectory(const std::string &name) const;
std::vector<std::string>getMusicDirs() const; std::vector<std::string>
std::string getAssetChecked(AssetType type, const std::string& name, getMusicDirs() const;
bool abort_on_error=false) const; std::string getAssetChecked(AssetType type, const std::string& name,
std::string getAsset(AssetType type, const std::string &name) const; bool abort_on_error=false) const;
std::string getAsset(const std::string &name) const; std::string getAsset(AssetType type, const std::string &name) const;
std::string getAsset(const std::string &name) const;
std::string searchMusic(const std::string& file_name) const; std::string searchMusic(const std::string& file_name) const;
std::string searchTexture(const std::string& fname) const; std::string searchTexture(const std::string& fname) const;
std::string getUserConfigFile(const std::string& fname) const; std::string getUserConfigFile(const std::string& fname) const;
void listFiles (std::set<std::string>& result, void listFiles(std::set<std::string>& result,
const std::string& dir, const std::string& dir,
bool make_full_path=false) const; bool make_full_path=false) const;
void pushTextureSearchPath(const std::string& path); void pushTextureSearchPath (const std::string& path);
void pushModelSearchPath (const std::string& path); void pushModelSearchPath (const std::string& path);
void popTextureSearchPath (); void popTextureSearchPath ();
void popModelSearchPath (); void popModelSearchPath ();
void redirectOutput(); void redirectOutput ();
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Adds a directory to the music search path (or stack). /** Adds a directory to the music search path (or stack).
*/ */

View File

@ -392,17 +392,21 @@ void cmdLineHelp()
{ {
Log::info("main", Log::info("main",
"Usage: %s [OPTIONS]\n\n" "Usage: %s [OPTIONS]\n\n"
"Run SuperTuxKart, a racing game with go-kart that features" "Run SuperTuxKart, a racing game with go-kart that features"
" the Tux and friends.\n\n" " the Tux and friends.\n\n"
"Options:\n" "Options:\n"
" -N, --no-start-screen Immediately start race without showing a " " -N, --no-start-screen Immediately start race without showing a "
"menu.\n" "menu.\n"
" -R, --race-now Same as -N but also skip the ready-set-go phase" " -R, --race-now Same as -N but also skip the ready-set-go phase "
" and the music.\n" "and the music.\n"
" -t, --track=NAME Start at track NAME.\n" " -t, --track=NAME Start at track NAME.\n"
" --gp=NAME Start the specified Grand Prix.\n" " --gp=NAME Start the specified Grand Prix.\n"
" --stk-config=FILE use ./data/FILE instead of " " --stk-config=FILE use ./data/FILE instead of "
"./data/stk_config.xml\n" "./data/stk_config.xml\n"
" --add-gp-dir=DIR Load Grand Prixs in DIR. Setting will be saved "
"in config.xml\n"
" -k, --numkarts=NUM Number of karts on the racetrack.\n" " -k, --numkarts=NUM Number of karts on the racetrack.\n"
" --kart=NAME Use kart number NAME.\n" " --kart=NAME Use kart number NAME.\n"
" --ai=a,b,... Use the karts a, b, ... for the AI.\n" " --ai=a,b,... Use the karts a, b, ... for the AI.\n"
@ -467,8 +471,7 @@ int handleCmdLinePreliminary()
cmdLineHelp(); cmdLineHelp();
exit(0); exit(0);
} }
if( CommandLine::has("--gamepad-visualisation") || if( CommandLine::has("--gamepad-visualisation") )
CommandLine::has("--gamepad-visualization") )
UserConfigParams::m_gamepad_visualisation=true; UserConfigParams::m_gamepad_visualisation=true;
if( CommandLine::has("--debug=memory")) if( CommandLine::has("--debug=memory"))
UserConfigParams::m_verbosity |= UserConfigParams::LOG_MEMORY; UserConfigParams::m_verbosity |= UserConfigParams::LOG_MEMORY;
@ -498,15 +501,15 @@ int handleCmdLinePreliminary()
if( CommandLine::has( "--stk-config", &s)) if( CommandLine::has( "--stk-config", &s))
{ {
stk_config->load(file_manager->getAsset(s)); stk_config->load(file_manager->getAsset(s));
Log::info("main", "STK config will be read from %s.",s.c_str()); Log::info("main", "STK config will be read from %s.", s.c_str());
} }
if( CommandLine::has( "--trackdir", &s)) if( CommandLine::has( "--trackdir", &s))
TrackManager::addTrackSearchDir(s); TrackManager::addTrackSearchDir(s);
if( CommandLine::has( "--kartdir", &s)) if( CommandLine::has( "--kartdir", &s))
KartPropertiesManager::addKartSearchDir(s); KartPropertiesManager::addKartSearchDir(s);
if( CommandLine::has( "--no-graphics") || if( CommandLine::has("--no-graphics") ||
CommandLine::has("-l" ) ) CommandLine::has("-l" ) )
{ {
ProfileWorld::disableGraphics(); ProfileWorld::disableGraphics();
UserConfigParams::m_log_errors_to_console=true; UserConfigParams::m_log_errors_to_console=true;
@ -539,13 +542,14 @@ int handleCmdLinePreliminary()
} }
else else
Log::warn("main", "Resolution %s has been blacklisted, so " Log::warn("main", "Resolution %s has been blacklisted, so "
"it is not available!", res.c_str()); "it is not available!", res.c_str());
} }
else else
{ {
Log::fatal("main", "Error: --screensize argument must be " Log::fatal("main", "Error: --screensize argument must be given as "
"given as WIDTHxHEIGHT"); "WIDTHxHEIGHT");
} }
} }
@ -589,6 +593,19 @@ int handleCmdLinePreliminary()
if(CommandLine::has("--log", &n)) if(CommandLine::has("--log", &n))
Log::setLogLevel(n); Log::setLogLevel(n);
// Enable loading GP's from local directory
if(CommandLine::has("--add-gp-dir", &s))
{
// Ensure that the path ends with a /
if (s[s.size()] == '/')
UserConfigParams::m_additional_gp_directory = s;
else
UserConfigParams::m_additional_gp_directory = s + "/";
Log::info("main", "Additional Grand Prix will be loaded from %s",
UserConfigParams::m_additional_gp_directory.c_str());
}
return 0; return 0;
} // handleCmdLinePreliminary } // handleCmdLinePreliminary
@ -1144,7 +1161,8 @@ int main(int argc, char *argv[] )
// Both item_manager and powerup_manager load models and therefore // Both item_manager and powerup_manager load models and therefore
// textures from the model directory. To avoid reading the // textures from the model directory. To avoid reading the
// materials.xml twice, we do this here once for both: // materials.xml twice, we do this here once for both:
file_manager->pushTextureSearchPath(file_manager->getAsset(FileManager::MODEL,"")); file_manager->pushTextureSearchPath(file_manager->getAsset(
FileManager::MODEL,""));
const std::string materials_file = const std::string materials_file =
file_manager->getAsset(FileManager::MODEL,"materials.xml"); file_manager->getAsset(FileManager::MODEL,"materials.xml");
if(materials_file!="") if(materials_file!="")

View File

@ -32,15 +32,29 @@
#include <stdexcept> #include <stdexcept>
GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error) GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error)
{
load_from_file(file_manager->getAsset(FileManager::GRANDPRIX, filename),
filename);
}
// ----------------------------------------------------------------------------
GrandPrixData::GrandPrixData(const std::string dir, const std::string filename)
throw(std::logic_error)
{
assert(dir[dir.size()] == '/');
load_from_file(dir + filename, filename);
}
// ----------------------------------------------------------------------------
void GrandPrixData::load_from_file(const std::string fullpath,
const std::string filename)
{ {
m_filename = filename; m_filename = filename;
m_id = StringUtils::getBasename(StringUtils::removeExtension(filename)); m_id = StringUtils::getBasename(StringUtils::removeExtension(filename));
XMLNode* root = file_manager->createXMLTree(file_manager->getAsset(FileManager::GRANDPRIX,filename)); XMLNode * root = file_manager->createXMLTree(fullpath);
if (!root) if (!root)
{ {
Log::error("GrandPrixData","Error while trying to read grandprix file '%s'", Log::error("GrandPrixData","Error while trying to read grandprix file "
filename.c_str()); "'%s'", fullpath.c_str());
throw std::logic_error("File not found"); throw std::logic_error("File not found");
} }
@ -51,8 +65,9 @@ GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error)
std::string temp_name; std::string temp_name;
if (root->get("name", &temp_name) == 0) if (root->get("name", &temp_name) == 0)
{ {
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : " Log::error("GrandPrixData", "Error while trying to read grandprix "
"missing 'name' attribute\n", filename.c_str()); "file '%s' : missing 'name' attribute\n",
fullpath.c_str());
delete root; delete root;
throw std::logic_error("File contents are incomplete or corrupt"); throw std::logic_error("File contents are incomplete or corrupt");
} }
@ -61,8 +76,9 @@ GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error)
} }
else else
{ {
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : " Log::error("GrandPrixData", "Error while trying to read grandprix file "
"Root node has an unexpected name\n", filename.c_str()); "'%s' : Root node has an unexpected name\n",
fullpath.c_str());
delete root; delete root;
throw std::logic_error("File contents are incomplete or corrupt"); throw std::logic_error("File contents are incomplete or corrupt");
} }
@ -80,18 +96,20 @@ GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error)
int numLaps; int numLaps;
bool reversed = false; bool reversed = false;
const int idFound = node->get("id", &trackID ); const int idFound = node->get("id", &trackID);
const int lapFound = node->get("laps", &numLaps ); const int lapFound = node->get("laps", &numLaps);
// Will stay false if not found // Will stay false if not found
node->get("reverse", &reversed ); node->get("reverse", &reversed );
if (!idFound || !lapFound) if (!idFound || !lapFound)
{ {
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : " Log::error("GrandPrixData", "Error while trying to read "
"<track> tag does not have idi and laps reverse attributes. \n", "grandprix file '%s' : <track> tag does not have "
filename.c_str()); "idi and laps reverse attributes. \n",
fullpath.c_str());
delete root; delete root;
throw std::logic_error("File contents are incomplete or corrupt"); throw std::logic_error("File contents are incomplete or "
"corrupt");
} }
// Make sure the track really is reversible // Make sure the track really is reversible
@ -110,22 +128,22 @@ GrandPrixData::GrandPrixData(const std::string filename) throw(std::logic_error)
} }
else else
{ {
std::cerr << "Unknown node in Grand Prix XML file : " << node->getName().c_str() << std::endl; Log::error("Unknown node in Grand Prix XML file: %s/n",
node->getName().c_str());
delete root; delete root;
throw std::runtime_error("Unknown node in sfx XML file"); throw std::runtime_error("Unknown node in sfx XML file");
} }
}// nend for }// end for
delete root; delete root;
// sanity checks // sanity checks
if (!foundName) if (!foundName)
{ {
Log::error("GrandPrixData", "Error while trying to read grandprix file '%s' : " Log::error("GrandPrixData", "Error while trying to read grandprix file "
"missing 'name' attribute\n", filename.c_str()); "'%s' : missing 'name' attribute\n", fullpath.c_str());
throw std::logic_error("File contents are incomplete or corrupt"); throw std::logic_error("File contents are incomplete or corrupt");
} }
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool GrandPrixData::checkConsistency(bool chatty) const bool GrandPrixData::checkConsistency(bool chatty) const
@ -149,7 +167,6 @@ bool GrandPrixData::checkConsistency(bool chatty) const
return true; return true;
} // checkConsistency } // checkConsistency
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Returns true if the track is available. This is used to test if Fort Magma /** Returns true if the track is available. This is used to test if Fort Magma
* is available (this way FortMagma is not used in the last Grand Prix in * is available (this way FortMagma is not used in the last Grand Prix in

View File

@ -27,6 +27,7 @@
#include <stdexcept> #include <stdexcept>
#include "utils/translation.hpp" #include "utils/translation.hpp"
#include "io/file_manager.hpp"
/** Simple class that hold the data relevant to a 'grand_prix', aka. a number /** Simple class that hold the data relevant to a 'grand_prix', aka. a number
* of races that has to be completed one after the other * of races that has to be completed one after the other
@ -34,6 +35,7 @@
*/ */
class GrandPrixData class GrandPrixData
{ {
private:
/** The name of the grand prix. */ /** The name of the grand prix. */
irr::core::stringw m_name; irr::core::stringw m_name;
@ -63,6 +65,7 @@ class GrandPrixData
/** Whether the track in question should be done in reverse mode */ /** Whether the track in question should be done in reverse mode */
std::vector<bool> m_reversed; std::vector<bool> m_reversed;
void load_from_file(const std::string fullpath, const std::string filename);
bool isTrackAvailable(const std::string &id) const; bool isTrackAvailable(const std::string &id) const;
public: public:
@ -70,8 +73,11 @@ public:
#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__) #if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
#pragma warning(disable:4290) #pragma warning(disable:4290)
#endif #endif
GrandPrixData (const std::string filename) throw(std::logic_error); GrandPrixData () {}; // empty for initialising
GrandPrixData () {}; // empty for initialising GrandPrixData (const std::string filename) throw(std::logic_error);
GrandPrixData (const std::string dir, const std::string filename)
throw(std::logic_error);
bool checkConsistency(bool chatty=true) const; bool checkConsistency(bool chatty=true) const;
const std::vector<std::string>& getTrackNames() const; const std::vector<std::string>& getTrackNames() const;

View File

@ -21,6 +21,7 @@
#include <set> #include <set>
#include "io/file_manager.hpp" #include "io/file_manager.hpp"
#include "utils/string_utils.hpp" #include "utils/string_utils.hpp"
#include "config/user_config.hpp"
GrandPrixManager *grand_prix_manager = NULL; GrandPrixManager *grand_prix_manager = NULL;
@ -33,10 +34,34 @@ GrandPrixManager::GrandPrixManager()
for(std::set<std::string>::iterator i = result.begin(); for(std::set<std::string>::iterator i = result.begin();
i != result.end() ; i++) i != result.end() ; i++)
{ {
if (StringUtils::hasSuffix(*i, ".grandprix")) load(*i); if (StringUtils::hasSuffix(*i, ".grandprix"))
} // for i {
} // GrandPrixManager try
{ m_gp_data.push_back(new GrandPrixData(*i)); }
catch (std::logic_error& er)
{ Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n",
i->c_str(), er.what()); }
}
}
// Load additional Grand Prixs
const std::string dir = UserConfigParams::m_additional_gp_directory;
if(dir != "") {
file_manager->listFiles(result, dir);
for(std::set<std::string>::iterator i = result.begin();
i != result.end() ; i++)
{
if (StringUtils::hasSuffix(*i, ".grandprix"))
{
try
{ m_gp_data.push_back(new GrandPrixData(dir, *i)); }
catch (std::logic_error& er)
{ Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n",
i->c_str(), er.what()); }
}
}
}
} // GrandPrixManager
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
GrandPrixManager::~GrandPrixManager() GrandPrixManager::~GrandPrixManager()
{ {
@ -50,22 +75,11 @@ GrandPrixManager::~GrandPrixManager()
const GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const const GrandPrixData* GrandPrixManager::getGrandPrix(const std::string& s) const
{ {
for(unsigned int i=0; i<m_gp_data.size(); i++) for(unsigned int i=0; i<m_gp_data.size(); i++)
if(m_gp_data[i]->getId()==s) return m_gp_data[i]; if(m_gp_data[i]->getId() == s)
return m_gp_data[i];
return NULL; return NULL;
} // getGrandPrix } // getGrandPrix
// ----------------------------------------------------------------------------
void GrandPrixManager::load(const std::string& filename)
{
try
{
m_gp_data.push_back(new GrandPrixData(filename));
}
catch (std::logic_error& er)
{
Log::error("GrandPrixManager", "Ignoring GP %s ( %s ) \n", filename.c_str(), er.what());
}
} // load
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void GrandPrixManager::checkConsistency() void GrandPrixManager::checkConsistency()
{ {

View File

@ -34,10 +34,9 @@ private:
public: public:
GrandPrixManager(); GrandPrixManager();
~GrandPrixManager(); ~GrandPrixManager();
void load(const std::string &filename); const GrandPrixData* getGrandPrix(int i) const {return m_gp_data[i]; }
const GrandPrixData* getGrandPrix(int i) const { return m_gp_data[i]; }
const GrandPrixData* getGrandPrix(const std::string& s) const; const GrandPrixData* getGrandPrix(const std::string& s) const;
unsigned int getNumberOfGrandPrix() const { return m_gp_data.size(); } unsigned int getNumberOfGrandPrix() const {return m_gp_data.size();}
void checkConsistency(); void checkConsistency();
}; // GrandPrixManager }; // GrandPrixManager