00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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 }