- no longer over-write special tag substitutions in ini files in order to preserve derived paths etc

This commit is contained in:
Mark Vejvoda 2012-10-24 14:43:02 +00:00
parent 2796922914
commit 5e3c4e28cf
2 changed files with 40 additions and 18 deletions

View File

@ -42,6 +42,9 @@ public:
private: private:
PropertyVector propertyVector; PropertyVector propertyVector;
PropertyMap propertyMap; PropertyMap propertyMap;
PropertyVector propertyVectorTmp;
PropertyMap propertyMapTmp;
string path; string path;
static string applicationPath; static string applicationPath;
static string gameVersion; static string gameVersion;
@ -57,9 +60,9 @@ public:
void load(const string &path,bool clearCurrentProperties=true); void load(const string &path,bool clearCurrentProperties=true);
void save(const string &path); void save(const string &path);
int getPropertyCount() const {return (int)propertyVector.size();} int getPropertyCount() const;
string getKey(int i) const {return propertyVector[i].first;} string getKey(int i) const;
string getString(int i) const {return propertyVector[i].second;} string getString(int i) const;
bool getBool(const string &key, const char *defaultValueIfNotFound=NULL) const; bool getBool(const string &key, const char *defaultValueIfNotFound=NULL) const;
int getInt(const string &key, const char *defaultValueIfNotFound=NULL) const; int getInt(const string &key, const char *defaultValueIfNotFound=NULL) const;

View File

@ -50,7 +50,7 @@ string Properties::gameVersion = "";
void Properties::load(const string &path, bool clearCurrentProperties) { void Properties::load(const string &path, bool clearCurrentProperties) {
char lineBuffer[maxLine]=""; char lineBuffer[maxLine]="";
string line, key, value; string line, key, value, original_value;
size_t pos=0; size_t pos=0;
this->path= path; this->path= path;
@ -74,6 +74,7 @@ void Properties::load(const string &path, bool clearCurrentProperties) {
if(clearCurrentProperties == true) { if(clearCurrentProperties == true) {
propertyMap.clear(); propertyMap.clear();
propertyMapTmp.clear();
} }
while(fileStream.eof() == false) { while(fileStream.eof() == false) {
@ -125,25 +126,30 @@ void Properties::load(const string &path, bool clearCurrentProperties) {
if(pos != string::npos){ if(pos != string::npos){
key= line.substr(0, pos); key= line.substr(0, pos);
value= line.substr(pos+1); value= line.substr(pos+1);
original_value = value;
if(applyTagsToValue(value) == true) { if(applyTagsToValue(value) == true) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Property key [%s] now has value [%s]\n",key.c_str(),value.c_str()); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Property key [%s] now has value [%s] original_value [%s]\n",key.c_str(),value.c_str(),original_value.c_str());
} }
bool replaceExisting = false; bool replaceExisting = false;
if(propertyMap.find(key) != propertyMap.end()) { if(propertyMap.find(key) != propertyMap.end()) {
replaceExisting = true; replaceExisting = true;
} }
propertyMap[key] = value; propertyMap[key] = original_value;
propertyMapTmp[key] = value;
if(replaceExisting == false) { if(replaceExisting == false) {
propertyVector.push_back(PropertyPair(key, value)); propertyVector.push_back(PropertyPair(key, original_value));
propertyVectorTmp.push_back(PropertyPair(key, value));
} }
else { else {
for(unsigned int i = 0; i < propertyVector.size(); ++i) { for(unsigned int i = 0; i < propertyVector.size(); ++i) {
PropertyPair &currentPair = propertyVector[i]; PropertyPair &currentPair = propertyVector[i];
if(currentPair.first == key) { if(currentPair.first == key) {
currentPair.second = value; currentPair.second = original_value;
propertyVectorTmp[i].second = value;
break; break;
} }
} }
@ -345,7 +351,19 @@ void Properties::save(const string &path){
void Properties::clear(){ void Properties::clear(){
propertyMap.clear(); propertyMap.clear();
propertyMapTmp.clear();
propertyVector.clear(); propertyVector.clear();
propertyVectorTmp.clear();
}
int Properties::getPropertyCount() const {
return (int)propertyVectorTmp.size();
}
string Properties::getKey(int i) const {
return propertyVectorTmp[i].first;
}
string Properties::getString(int i) const {
return propertyVectorTmp[i].second;
} }
bool Properties::getBool(const string &key, const char *defaultValueIfNotFound) const{ bool Properties::getBool(const string &key, const char *defaultValueIfNotFound) const{
@ -401,9 +419,8 @@ float Properties::getFloat(const string &key, float min, float max, const char *
} }
const string Properties::getString(const string &key, const char *defaultValueIfNotFound) const{ const string Properties::getString(const string &key, const char *defaultValueIfNotFound) const{
PropertyMap::const_iterator it; PropertyMap::const_iterator it = propertyMapTmp.find(key);
it= propertyMap.find(key); if(it == propertyMapTmp.end()) {
if(it==propertyMap.end()){
if(defaultValueIfNotFound != NULL) { if(defaultValueIfNotFound != NULL) {
//printf("In [%s::%s - %d]defaultValueIfNotFound = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,defaultValueIfNotFound); //printf("In [%s::%s - %d]defaultValueIfNotFound = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,defaultValueIfNotFound);
return string(defaultValueIfNotFound); return string(defaultValueIfNotFound);
@ -438,9 +455,8 @@ const string Properties::getRandomKey(const bool realrandom) const{
} }
bool Properties::hasString(const string &key) const { bool Properties::hasString(const string &key) const {
PropertyMap::const_iterator it; PropertyMap::const_iterator it = propertyMapTmp.find(key);
it= propertyMap.find(key); if(it == propertyMapTmp.end()) {
if(it == propertyMap.end()) {
return false; return false;
} }
return true; return true;
@ -461,12 +477,16 @@ void Properties::setFloat(const string &key, float value){
void Properties::setString(const string &key, const string &value){ void Properties::setString(const string &key, const string &value){
propertyMap.erase(key); propertyMap.erase(key);
propertyMap.insert(PropertyPair(key, value)); propertyMap.insert(PropertyPair(key, value));
propertyMapTmp.erase(key);
propertyMapTmp.insert(PropertyPair(key, value));
} }
string Properties::toString(){ string Properties::toString(){
string rStr; string rStr;
for(PropertyMap::iterator pi= propertyMap.begin(); pi!=propertyMap.end(); ++pi) for(PropertyMap::iterator pi= propertyMapTmp.begin(); pi!=propertyMapTmp.end(); ++pi)
rStr+= pi->first + "=" + pi->second + "\n"; rStr+= pi->first + "=" + pi->second + "\n";
return rStr; return rStr;
@ -509,9 +529,8 @@ float Properties::getFloat(const char *key, const char *defaultValueIfNotFound)
} }
const string Properties::getString(const char *key, const char *defaultValueIfNotFound) const{ const string Properties::getString(const char *key, const char *defaultValueIfNotFound) const{
PropertyMap::const_iterator it; PropertyMap::const_iterator it = propertyMapTmp.find(key);
it= propertyMap.find(key); if(it == propertyMapTmp.end()) {
if(it==propertyMap.end()){
if(defaultValueIfNotFound != NULL) { if(defaultValueIfNotFound != NULL) {
//printf("In [%s::%s - %d]defaultValueIfNotFound = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,defaultValueIfNotFound); //printf("In [%s::%s - %d]defaultValueIfNotFound = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,defaultValueIfNotFound);
return string(defaultValueIfNotFound); return string(defaultValueIfNotFound);