ModInfo.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <engine/ModInfo.h>
00022 #include <common/Defines.h>
00023 #include <XML/XMLFile.h>
00024 
00025 ModInfo::ModInfo(const std::string &name) :
00026         name_(name)
00027 {
00028 
00029 }
00030 
00031 ModInfo::~ModInfo()
00032 {
00033 }
00034 
00035 bool ModInfo::parse(const std::string &fileName)
00036 {
00037         entries_.clear();
00038         XMLFile file;
00039         if (!file.readFile(fileName))
00040         {
00041                 S3D::dialogMessage("ModInfo", S3D::formatStringBuffer(
00042                         "Failed to parse \"%s\":%s\n", 
00043                         fileName.c_str(),
00044                         file.getParserError()));
00045                 return false;
00046         }
00047         if (!file.getRootNode())
00048         {
00049                 S3D::dialogMessage("ModInfo", S3D::formatStringBuffer(
00050                                           "Failed to find mod info definition file \"%s\"",
00051                                           fileName.c_str()));
00052                 return false;           
00053         }
00054 
00055         // Parse the main mod info
00056         std::string tmpicon, tmpgamefile;
00057         XMLNode *mainNode = 0;
00058         if (!file.getRootNode()->getNamedChild("main", mainNode)) return false;
00059         if (!mainNode->getNamedChild("description", description_)) return false;
00060         if (!mainNode->getNamedChild("icon", tmpicon)) return false;
00061         if (!mainNode->getNamedChild("url", url_)) return false;
00062         if (!mainNode->getNamedChild("protocolversion", protocolversion_)) return false;
00063         if (!mainNode->getNamedChild("shortdescription", shortDescription_, false))
00064         {
00065                 shortDescription_ = description_;
00066         }
00067         if (!mainNode->failChildren()) return false;
00068 
00069         if (S3D::checkDataFile(tmpicon.c_str()))
00070         {
00071                 icon_ = S3D::getDataFile(tmpicon.c_str());
00072         }
00073         else
00074         {
00075                 icon_ = S3D::getDataFile("data/windows/tank2.bmp");
00076         }
00077 
00078         // Parse the mod game info
00079         XMLNode *gameNode = 0;
00080         while (file.getRootNode()->getNamedChild("game", gameNode, false))
00081         {
00082                 MenuEntry entry;
00083                 if (!gameNode->getNamedChild("description", entry.description)) return false;
00084                 if (!gameNode->getNamedChild("icon", tmpicon)) return false;
00085                 if (!gameNode->getNamedChild("gamefile", tmpgamefile)) return false;
00086                 if (!gameNode->getNamedChild("shortdescription", entry.shortdescription, false))
00087                 {
00088                         entry.shortdescription = entry.description;
00089                 }
00090 
00091                 if (S3D::checkDataFile(tmpicon.c_str())) 
00092                 {
00093                         entry.icon = S3D::getDataFile(tmpicon.c_str());
00094                 }
00095                 else
00096                 {
00097                         entry.icon = S3D::getDataFile("data/windows/tank2.bmp");
00098                 }
00099         
00100                 entry.gamefile = S3D::getDataFile(tmpgamefile.c_str());
00101                 if (!S3D::checkDataFile(tmpgamefile.c_str())) return false;
00102 
00103                 if (!gameNode->failChildren()) return false;
00104                 entries_.push_back(entry);
00105         }
00106 
00107         return file.getRootNode()->failChildren();
00108 }

Generated on Mon Feb 16 15:14:49 2009 for Scorched3D by  doxygen 1.5.3