| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- #include "configparser.h"
- #include "loghelper.h"
- ConfigParser::ConfigParser()
- {
- this->current_app_version = 0;
- this->current_seg_version = 0;
- }
- bool ConfigParser::readConfig(QString content)
- {
- QString errorStr;
- int errorLine;
- int errorColumn;
- QDomDocument doc;
- if(!doc.setContent(content,false,&errorStr,&errorLine,&errorColumn))
- {
- qDebug()<<errorStr<<errorLine<<errorColumn;
- LogHelper::writeLog(errorStr + " " +\
- QString::number(errorLine) + " " +QString::number(errorColumn));
- return false;
- }
- QDomElement root = doc.documentElement();
- if (root.tagName()!="SpeedNumCube")
- {
- qDebug()<<root.tagName();
- return false;
- }
- parseConfigElement(root);
- return true;
- }
- void ConfigParser::parseConfigElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- if(child.toElement().tagName()=="config_urls")
- {
- parseConfigUrlsElement(child.toElement());
- }
- if(child.toElement().tagName()=="app_ver_map")
- {
- parseAppMapElement(child.toElement());
- }
- if(child.toElement().tagName()=="seg_ver_map")
- {
- parseSegMapElement(child.toElement());
- }
- if(child.toElement().tagName()=="banner_ad")
- {
- banner_ad= child.toElement().text();
- }
- if(child.toElement().tagName()=="text_ads")
- {
- parseAdElement(child.toElement());
- }
- if(child.toElement().tagName()=="corp_prefix")
- {
- parseCorpPrefixElement(child.toElement());
- }
- if(child.toElement().tagName()=="client_config")
- {
- parseClientConfigElement(child.toElement());
- }
- if(child.toElement().tagName()=="app")
- {
- parseAppElement(child.toElement());
- }
- if(child.toElement().tagName()=="seg")
- {
- parseSegElement(child.toElement());
- }
- child = child.nextSibling();
- }
- }
- void ConfigParser::parseAppMapElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- int sn = child.toElement().attribute("sn").toInt();
- QString ver = child.toElement().text();
- app_map.insert(ver,sn);
- child = child.nextSibling();
- }
- }
- void ConfigParser::parseSegMapElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- int sn = child.toElement().attribute("sn").toInt();
- QString ver = child.toElement().text();
- seg_map.insert(ver,sn);
- child = child.nextSibling();
- }
- }
- void ConfigParser::parseConfigUrlsElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- config_urls << child.toElement().text();
- child = child.nextSibling();
- }
- }
- void ConfigParser::parseAppElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- if(child.toElement().tagName()=="current_app_version")
- {
- current_app_version= child.toElement().text().toInt();
- this->update = child.toElement().attribute("update");
- }
- if(child.toElement().tagName()=="patch_urls")
- {
- parseAppPatchUrlElement(child.toElement());
- }
- if(child.toElement().tagName()=="update_logs")
- {
- parseAppUpdateLogElement(child.toElement());
- }
- child = child.nextSibling();
- }
- }
- void ConfigParser::parseSegElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- if(child.toElement().tagName()=="current_seg_version")
- {
- current_seg_version= child.toElement().text().toInt();
- }
- if(child.toElement().tagName()=="patch_urls")
- {
- parseSegPatchUrlElement(child.toElement());
- }
- if(child.toElement().tagName()=="update_logs")
- {
- parseSegUpdateLogElement(child.toElement());
- }
- child = child.nextSibling();
- }
- }
- void ConfigParser::parseAppPatchUrlElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- int sn = child.toElement().attribute("sn").toInt();
- QString url = child.toElement().text();
- app_patch_urls.insert(sn,url);
- child = child.nextSibling();
- }
- }
- void ConfigParser::parseAppUpdateLogElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- int sn = child.toElement().attribute("sn").toInt();
- QString url = child.toElement().text();
- app_update_logs.insert(sn,url);
- child = child.nextSibling();
- }
- }
- void ConfigParser::parseSegPatchUrlElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- int sn = child.toElement().attribute("sn").toInt();
- QString url = child.toElement().text();
- seg_patch_urls.insert(sn,url);
- child = child.nextSibling();
- }
- }
- void ConfigParser::parseSegUpdateLogElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- int sn = child.toElement().attribute("sn").toInt();
- QString url = child.toElement().text();
- seg_update_logs.insert(sn,url);
- child = child.nextSibling();
- }
- }
- void ConfigParser::parseAdElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- QString url = child.toElement().attribute("link");
- QString content = child.toElement().text();
- text_ads.insert(url,content);
- child = child.nextSibling();
- }
- }
- void ConfigParser::parseCorpPrefixElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- QString corp = child.toElement().attribute("corp");
- QString content = child.toElement().text();
- corp_prefix.insert(corp,content);
- child = child.nextSibling();
- }
- }
- void ConfigParser::parseClientConfigElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- QStringList list;
- QString name = child.toElement().attribute("name");
- QString ws_url = child.toElement().attribute("ws_url");
- QString notice_url = child.toElement().attribute("notice_url");
- list<<name<<ws_url<<notice_url;
- QString content = child.toElement().text();
- client_config.insert(content,list);
- child = child.nextSibling();
- }
- }
|