mirror of
https://github.com/glest/glest-source.git
synced 2025-08-18 22:21:18 +02:00
- added support for special tags in ini file strings in preparation for storing userdata in ~/.megaglest
This commit is contained in:
@@ -813,6 +813,28 @@ string extractDirectoryPathFromFile(string filename) {
|
||||
return path;
|
||||
}
|
||||
|
||||
string extractLastDirectoryFromPath(string Path) {
|
||||
string result = Path;
|
||||
size_t lastDirectory = Path.find_last_of("/\\");
|
||||
if (lastDirectory == string::npos) {
|
||||
result = Path;
|
||||
}
|
||||
else {
|
||||
if(Path.length() > lastDirectory + 1) {
|
||||
result = Path.erase( 0, lastDirectory + 1);
|
||||
}
|
||||
else {
|
||||
for(int i = lastDirectory-1; i >= 0; --i) {
|
||||
if(Path[i] == '/' || Path[i] == '\\' && i > 0) {
|
||||
result = Path.erase( 0, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
string extractExtension(const string& filepath) {
|
||||
size_t lastPoint = filepath.find_last_of('.');
|
||||
size_t lastDirectory = filepath.find_last_of("/\\");
|
||||
@@ -823,18 +845,13 @@ string extractExtension(const string& filepath) {
|
||||
return filepath.substr(lastPoint+1);
|
||||
}
|
||||
|
||||
void createDirectoryPaths(string Path)
|
||||
{
|
||||
void createDirectoryPaths(string Path) {
|
||||
char DirName[256]="";
|
||||
const char *path = Path.c_str();
|
||||
char *dirName = DirName;
|
||||
while(*path)
|
||||
{
|
||||
while(*path) {
|
||||
//if (('\\' == *path) || ('/' == *path))
|
||||
if ('/' == *path)
|
||||
{
|
||||
//if (':' != *(path-1))
|
||||
{
|
||||
if ('/' == *path) {
|
||||
#ifdef WIN32
|
||||
int result = _mkdir(DirName);
|
||||
#elif defined(__GNUC__)
|
||||
@@ -843,7 +860,6 @@ void createDirectoryPaths(string Path)
|
||||
#error "Your compiler needs to support mkdir!"
|
||||
#endif
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] DirName [%s] result = %d, errno = %d\n",__FILE__,__FUNCTION__,__LINE__,DirName,result,errno);
|
||||
}
|
||||
}
|
||||
*dirName++ = *path++;
|
||||
*dirName = '\0';
|
||||
@@ -1092,10 +1108,16 @@ bool isKeyDown(int virtualKey) {
|
||||
|
||||
string replaceAll(string& context, const string& from, const string& to) {
|
||||
size_t lookHere = 0;
|
||||
size_t foundHere;
|
||||
while((foundHere = context.find(from, lookHere)) != string::npos) {
|
||||
context.replace(foundHere, from.size(), to);
|
||||
lookHere = foundHere + to.size();
|
||||
size_t foundHere = 0;
|
||||
if((foundHere = context.find(from, lookHere)) != string::npos) {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Replacing context [%s] from [%s] to [%s]\n",context.c_str(),from.c_str(),to.c_str());
|
||||
|
||||
while((foundHere = context.find(from, lookHere)) != string::npos) {
|
||||
context.replace(foundHere, from.size(), to);
|
||||
lookHere = foundHere + to.size();
|
||||
}
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("New context [%s]\n",context.c_str());
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
@@ -17,9 +17,11 @@
|
||||
|
||||
#include "conversion.h"
|
||||
#include "util.h"
|
||||
#include "platform_common.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Shared::PlatformCommon;
|
||||
|
||||
namespace Shared{ namespace Util{
|
||||
|
||||
@@ -66,6 +68,10 @@ void Properties::load(const string &path){
|
||||
if(pos != string::npos){
|
||||
key= line.substr(0, pos);
|
||||
value= line.substr(pos+1);
|
||||
|
||||
if(applyTagsToValue(value) == true) {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Property key [%s] now has value [%s]\n",key.c_str(),value.c_str());
|
||||
}
|
||||
propertyMap.insert(PropertyPair(key, value));
|
||||
propertyVector.push_back(PropertyPair(key, value));
|
||||
}
|
||||
@@ -75,6 +81,29 @@ void Properties::load(const string &path){
|
||||
fileStream.close();
|
||||
}
|
||||
|
||||
bool Properties::applyTagsToValue(string &value) {
|
||||
string originalValue = value;
|
||||
|
||||
char *homeDir = NULL;
|
||||
#ifdef WIN32
|
||||
homeDir = getenv("USERPROFILE");
|
||||
#else
|
||||
homeDir = getenv("HOME");
|
||||
#endif
|
||||
replaceAll(value, "~/", (homeDir != NULL ? homeDir : ""));
|
||||
replaceAll(value, "$HOME", (homeDir != NULL ? homeDir : ""));
|
||||
replaceAll(value, "%%HOME%%", (homeDir != NULL ? homeDir : ""));
|
||||
replaceAll(value, "%%USERPROFILE%%",(homeDir != NULL ? homeDir : ""));
|
||||
replaceAll(value, "%%HOMEPATH%%", (homeDir != NULL ? homeDir : ""));
|
||||
|
||||
char *username = NULL;
|
||||
username = getenv("USERNAME");
|
||||
replaceAll(value, "$USERNAME", (username != NULL ? username : ""));
|
||||
replaceAll(value, "%%USERNAME%%", (username != NULL ? username : ""));
|
||||
|
||||
return (originalValue != value);
|
||||
}
|
||||
|
||||
void Properties::save(const string &path){
|
||||
ofstream fileStream;
|
||||
|
||||
|
Reference in New Issue
Block a user