mirror of
https://github.com/glest/glest-source.git
synced 2025-08-23 00:12:49 +02:00
- updates to commondata handling. From now on commondata tag specified the commondata folder under a techtree making it easier to share data and portable since you just need to copy the techtree and its contents, this means no sharing data between techtrees (which is good since we don't want such dependencies)
This commit is contained in:
@@ -1807,16 +1807,18 @@ bool searchAndReplaceTextInFile(string fileName, string findText, string replace
|
||||
|
||||
while(fgets(buffer,MAX_LEN_SINGLE_LINE + 2,fp1)) {
|
||||
buff_ptr = buffer;
|
||||
while ((find_ptr = strstr(buff_ptr,findText.c_str()))) {
|
||||
//printf("Replacing text [%s] with [%s] in file [%s]\n",findText.c_str(),replaceText.c_str(),fileName.c_str());
|
||||
if(findText != "") {
|
||||
while ((find_ptr = strstr(buff_ptr,findText.c_str()))) {
|
||||
//printf("Replacing text [%s] with [%s] in file [%s]\n",findText.c_str(),replaceText.c_str(),fileName.c_str());
|
||||
|
||||
while(buff_ptr < find_ptr) {
|
||||
fputc((int)*buff_ptr++,fp2);
|
||||
while(buff_ptr < find_ptr) {
|
||||
fputc((int)*buff_ptr++,fp2);
|
||||
}
|
||||
fputs(replaceText.c_str(),fp2);
|
||||
|
||||
buff_ptr += find_len;
|
||||
replacedText = true;
|
||||
}
|
||||
fputs(replaceText.c_str(),fp2);
|
||||
|
||||
buff_ptr += find_len;
|
||||
replacedText = true;
|
||||
}
|
||||
fputs(buff_ptr,fp2);
|
||||
}
|
||||
@@ -1835,6 +1837,24 @@ bool searchAndReplaceTextInFile(string fileName, string findText, string replace
|
||||
return replacedText;
|
||||
}
|
||||
|
||||
void copyFileTo(string fromFileName, string toFileName) {
|
||||
const int MAX_LEN_SINGLE_LINE = 4096;
|
||||
char buffer[MAX_LEN_SINGLE_LINE+2];
|
||||
char *buff_ptr, *find_ptr;
|
||||
FILE *fp1, *fp2;
|
||||
|
||||
fp1 = fopen(fromFileName.c_str(),"r");
|
||||
fp2 = fopen(toFileName.c_str(),"w");
|
||||
|
||||
while(fgets(buffer,MAX_LEN_SINGLE_LINE + 2,fp1)) {
|
||||
buff_ptr = buffer;
|
||||
fputs(buff_ptr,fp2);
|
||||
}
|
||||
|
||||
fclose(fp2);
|
||||
fclose(fp1);
|
||||
}
|
||||
|
||||
// =====================================
|
||||
// ModeInfo
|
||||
// =====================================
|
||||
|
@@ -104,8 +104,87 @@ void Properties::load(const string &path, bool clearCurrentProperties) {
|
||||
fileStream.close();
|
||||
}
|
||||
|
||||
bool Properties::applyTagsToValue(string &value) {
|
||||
std::map<string,string> Properties::getTagReplacementValues(std::map<string,string> *mapExtraTagReplacementValues) {
|
||||
std::map<string,string> mapTagReplacementValues;
|
||||
|
||||
//
|
||||
// #1
|
||||
// First add the standard tags
|
||||
//
|
||||
char *homeDir = NULL;
|
||||
#ifdef WIN32
|
||||
homeDir = getenv("USERPROFILE");
|
||||
#else
|
||||
homeDir = getenv("HOME");
|
||||
#endif
|
||||
|
||||
mapTagReplacementValues["~/"] = (homeDir != NULL ? homeDir : "");
|
||||
mapTagReplacementValues["$HOME"] = (homeDir != NULL ? homeDir : "");
|
||||
mapTagReplacementValues["%%HOME%%"] = (homeDir != NULL ? homeDir : "");
|
||||
mapTagReplacementValues["%%USERPROFILE%%"] = (homeDir != NULL ? homeDir : "");
|
||||
mapTagReplacementValues["%%HOMEPATH%%"] = (homeDir != NULL ? homeDir : "");
|
||||
|
||||
// For win32 we allow use of the appdata variable since that is the recommended
|
||||
// place for application data in windows platform
|
||||
#ifdef WIN32
|
||||
TCHAR szPath[MAX_PATH]="";
|
||||
// Get path for each computer, non-user specific and non-roaming data.
|
||||
if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_APPDATA,
|
||||
NULL, 0, szPath))) {
|
||||
string appPath = szPath;
|
||||
mapTagReplacementValues["$APPDATA"] = appPath;
|
||||
mapTagReplacementValues["%%APPDATA%%"] = appPath;
|
||||
}
|
||||
#endif
|
||||
|
||||
char *username = NULL;
|
||||
username = getenv("USERNAME");
|
||||
|
||||
mapTagReplacementValues["$USERNAME"] = (username != NULL ? username : "");
|
||||
mapTagReplacementValues["%%USERNAME%%"] = (username != NULL ? username : "");
|
||||
|
||||
mapTagReplacementValues["$APPLICATIONPATH"] = Properties::applicationPath;
|
||||
mapTagReplacementValues["%%APPLICATIONPATH%%"] = Properties::applicationPath;
|
||||
|
||||
#if defined(CUSTOM_DATA_INSTALL_PATH)
|
||||
mapTagReplacementValues["$APPLICATIONDATAPATH"] = CUSTOM_DATA_INSTALL_PATH;
|
||||
mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = CUSTOM_DATA_INSTALL_PATH;
|
||||
|
||||
//mapTagReplacementValues["$COMMONDATAPATH", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
|
||||
//mapTagReplacementValues["%%COMMONDATAPATH%%", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
|
||||
|
||||
#else
|
||||
mapTagReplacementValues["$APPLICATIONDATAPATH"] = Properties::applicationPath;
|
||||
mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = Properties::applicationPath;
|
||||
|
||||
//mapTagReplacementValues["$COMMONDATAPATH", Properties::applicationPath + "/commondata/");
|
||||
//mapTagReplacementValues["%%COMMONDATAPATH%%", Properties::applicationPath + "/commondata/");
|
||||
#endif
|
||||
|
||||
//
|
||||
// #2
|
||||
// Next add the extra tags if passed in
|
||||
//
|
||||
if(mapExtraTagReplacementValues != NULL) {
|
||||
for(std::map<string,string>::iterator iterMap = mapExtraTagReplacementValues->begin();
|
||||
iterMap != mapExtraTagReplacementValues->end(); ++iterMap) {
|
||||
mapTagReplacementValues[iterMap->first] = iterMap->second;
|
||||
}
|
||||
}
|
||||
|
||||
return mapTagReplacementValues;
|
||||
}
|
||||
|
||||
bool Properties::applyTagsToValue(string &value, std::map<string,string> *mapTagReplacementValues) {
|
||||
string originalValue = value;
|
||||
|
||||
if(mapTagReplacementValues != NULL) {
|
||||
for(std::map<string,string>::iterator iterMap = mapTagReplacementValues->begin();
|
||||
iterMap != mapTagReplacementValues->end(); ++iterMap) {
|
||||
replaceAll(value, iterMap->first, iterMap->second);
|
||||
}
|
||||
}
|
||||
else {
|
||||
char *homeDir = NULL;
|
||||
#ifdef WIN32
|
||||
homeDir = getenv("USERPROFILE");
|
||||
@@ -144,17 +223,19 @@ bool Properties::applyTagsToValue(string &value) {
|
||||
replaceAll(value, "$APPLICATIONDATAPATH", CUSTOM_DATA_INSTALL_PATH);
|
||||
replaceAll(value, "%%APPLICATIONDATAPATH%%", CUSTOM_DATA_INSTALL_PATH);
|
||||
|
||||
replaceAll(value, "$COMMONDATAPATH", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
|
||||
replaceAll(value, "%%COMMONDATAPATH%%", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
|
||||
//replaceAll(value, "$COMMONDATAPATH", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
|
||||
//replaceAll(value, "%%COMMONDATAPATH%%", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/");
|
||||
|
||||
#else
|
||||
replaceAll(value, "$APPLICATIONDATAPATH", Properties::applicationPath);
|
||||
replaceAll(value, "%%APPLICATIONDATAPATH%%", Properties::applicationPath);
|
||||
|
||||
replaceAll(value, "$COMMONDATAPATH", Properties::applicationPath + "/commondata/");
|
||||
replaceAll(value, "%%COMMONDATAPATH%%", Properties::applicationPath + "/commondata/");
|
||||
//replaceAll(value, "$COMMONDATAPATH", Properties::applicationPath + "/commondata/");
|
||||
//replaceAll(value, "%%COMMONDATAPATH%%", Properties::applicationPath + "/commondata/");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//printf("\nBEFORE SUBSTITUTE [%s] AFTER [%s]\n",originalValue.c_str(),value.c_str());
|
||||
return (originalValue != value);
|
||||
}
|
||||
|
@@ -88,7 +88,7 @@ XmlIo::~XmlIo(){
|
||||
XMLPlatformUtils::Terminate();
|
||||
}
|
||||
|
||||
XmlNode *XmlIo::load(const string &path){
|
||||
XmlNode *XmlIo::load(const string &path, std::map<string,string> mapTagReplacementValues) {
|
||||
|
||||
try{
|
||||
ErrorHandler errorHandler;
|
||||
@@ -111,7 +111,7 @@ XmlNode *XmlIo::load(const string &path){
|
||||
throw runtime_error("Can not parse URL: " + path);
|
||||
}
|
||||
|
||||
XmlNode *rootNode= new XmlNode(document->getDocumentElement());
|
||||
XmlNode *rootNode= new XmlNode(document->getDocumentElement(),mapTagReplacementValues);
|
||||
parser->release();
|
||||
return rootNode;
|
||||
}
|
||||
@@ -167,8 +167,8 @@ void XmlTree::init(const string &name){
|
||||
this->rootNode= new XmlNode(name);
|
||||
}
|
||||
|
||||
void XmlTree::load(const string &path){
|
||||
this->rootNode= XmlIo::getInstance().load(path);
|
||||
void XmlTree::load(const string &path, std::map<string,string> mapTagReplacementValues) {
|
||||
this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues);
|
||||
}
|
||||
|
||||
void XmlTree::save(const string &path){
|
||||
@@ -183,7 +183,7 @@ XmlTree::~XmlTree(){
|
||||
// class XmlNode
|
||||
// =====================================================
|
||||
|
||||
XmlNode::XmlNode(DOMNode *node) {
|
||||
XmlNode::XmlNode(DOMNode *node, std::map<string,string> mapTagReplacementValues) {
|
||||
if(node == NULL || node->getNodeName() == NULL) {
|
||||
throw runtime_error("XML structure seems to be corrupt!");
|
||||
}
|
||||
@@ -203,7 +203,7 @@ XmlNode::XmlNode(DOMNode *node) {
|
||||
for(unsigned int i = 0; i < node->getChildNodes()->getLength(); ++i) {
|
||||
DOMNode *currentNode= node->getChildNodes()->item(i);
|
||||
if(currentNode != NULL && currentNode->getNodeType()==DOMNode::ELEMENT_NODE){
|
||||
XmlNode *xmlNode= new XmlNode(currentNode);
|
||||
XmlNode *xmlNode= new XmlNode(currentNode, mapTagReplacementValues);
|
||||
children.push_back(xmlNode);
|
||||
}
|
||||
}
|
||||
@@ -215,7 +215,7 @@ XmlNode::XmlNode(DOMNode *node) {
|
||||
for(unsigned int i = 0; i < domAttributes->getLength(); ++i) {
|
||||
DOMNode *currentNode= domAttributes->item(i);
|
||||
if(currentNode->getNodeType() == DOMNode::ATTRIBUTE_NODE) {
|
||||
XmlAttribute *xmlAttribute= new XmlAttribute(domAttributes->item(i));
|
||||
XmlAttribute *xmlAttribute= new XmlAttribute(domAttributes->item(i), mapTagReplacementValues);
|
||||
attributes.push_back(xmlAttribute);
|
||||
}
|
||||
}
|
||||
@@ -321,8 +321,8 @@ XmlNode *XmlNode::addChild(const string &name){
|
||||
return node;
|
||||
}
|
||||
|
||||
XmlAttribute *XmlNode::addAttribute(const string &name, const string &value) {
|
||||
XmlAttribute *attr= new XmlAttribute(name, value);
|
||||
XmlAttribute *XmlNode::addAttribute(const string &name, const string &value, std::map<string,string> mapTagReplacementValues) {
|
||||
XmlAttribute *attr= new XmlAttribute(name, value, mapTagReplacementValues);
|
||||
attributes.push_back(attr);
|
||||
return attr;
|
||||
}
|
||||
@@ -371,27 +371,30 @@ string XmlNode::getTreeString() const {
|
||||
// class XmlAttribute
|
||||
// =====================================================
|
||||
|
||||
XmlAttribute::XmlAttribute(DOMNode *attribute) {
|
||||
skipRestrictionCheck = false;
|
||||
usesCommondata = false;
|
||||
char str[strSize]="";
|
||||
XmlAttribute::XmlAttribute(DOMNode *attribute, std::map<string,string> mapTagReplacementValues) {
|
||||
skipRestrictionCheck = false;
|
||||
usesCommondata = false;
|
||||
this->mapTagReplacementValues = mapTagReplacementValues;
|
||||
char str[strSize] = "";
|
||||
|
||||
XMLString::transcode(attribute->getNodeValue(), str, strSize-1);
|
||||
value= str;
|
||||
usesCommondata = ((value.find("$COMMONDATAPATH") != string::npos) || (value.find("%%COMMONDATAPATH%%") != string::npos));
|
||||
skipRestrictionCheck = Properties::applyTagsToValue(this->value);
|
||||
skipRestrictionCheck = Properties::applyTagsToValue(this->value,&this->mapTagReplacementValues);
|
||||
|
||||
XMLString::transcode(attribute->getNodeName(), str, strSize-1);
|
||||
name= str;
|
||||
}
|
||||
|
||||
XmlAttribute::XmlAttribute(const string &name, const string &value) {
|
||||
skipRestrictionCheck = false;
|
||||
usesCommondata = false;
|
||||
this->name= name;
|
||||
this->value= value;
|
||||
XmlAttribute::XmlAttribute(const string &name, const string &value, std::map<string,string> mapTagReplacementValues) {
|
||||
skipRestrictionCheck = false;
|
||||
usesCommondata = false;
|
||||
this->mapTagReplacementValues = mapTagReplacementValues;
|
||||
this->name = name;
|
||||
this->value = value;
|
||||
|
||||
usesCommondata = ((value.find("$COMMONDATAPATH") != string::npos) || (value.find("%%COMMONDATAPATH%%") != string::npos));
|
||||
skipRestrictionCheck = Properties::applyTagsToValue(this->value);
|
||||
skipRestrictionCheck = Properties::applyTagsToValue(this->value,&this->mapTagReplacementValues);
|
||||
}
|
||||
|
||||
bool XmlAttribute::getBoolValue() const {
|
||||
|
Reference in New Issue
Block a user