mirror of
https://github.com/glest/glest-source.git
synced 2025-08-09 09:56:30 +02:00
- added support for special tags in ini file strings in preparation for storing userdata in ~/.megaglest
This commit is contained in:
@@ -678,9 +678,6 @@ string Config::toString(){
|
|||||||
|
|
||||||
vector<string> Config::getPathListForType(PathType type, string scenarioDir) {
|
vector<string> Config::getPathListForType(PathType type, string scenarioDir) {
|
||||||
vector<string> pathList;
|
vector<string> pathList;
|
||||||
|
|
||||||
//#include "game_constants.h"
|
|
||||||
//#include "game_util.h"
|
|
||||||
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
||||||
|
|
||||||
string userData = getString("UserData_Root","");
|
string userData = getString("UserData_Root","");
|
||||||
@@ -688,30 +685,44 @@ vector<string> Config::getPathListForType(PathType type, string scenarioDir) {
|
|||||||
if(userData[userData.size()-1] != '/' && userData[userData.size()-1] != '\\') {
|
if(userData[userData.size()-1] != '/' && userData[userData.size()-1] != '\\') {
|
||||||
userData += '/';
|
userData += '/';
|
||||||
}
|
}
|
||||||
userData=data_path+userData;
|
if(data_path == "") {
|
||||||
|
userData = data_path + userData;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("extractLastDirectoryFromPath(userData) [%s] from userData [%s]\n",extractLastDirectoryFromPath(userData).c_str(),userData.c_str());
|
||||||
|
userData = data_path + extractLastDirectoryFromPath(userData);
|
||||||
|
}
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] userData path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userData.c_str());
|
||||||
|
|
||||||
if(isdir(userData.c_str()) == false) {
|
if(isdir(userData.c_str()) == false) {
|
||||||
createDirectoryPaths(userData);
|
createDirectoryPaths(userData);
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] creating path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userData.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
string userDataMaps = userData + GameConstants::folder_path_maps;
|
string userDataMaps = userData + GameConstants::folder_path_maps;
|
||||||
if(isdir(userDataMaps.c_str()) == false) {
|
if(isdir(userDataMaps.c_str()) == false) {
|
||||||
createDirectoryPaths(userDataMaps);
|
createDirectoryPaths(userDataMaps);
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] creating path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userDataMaps.c_str());
|
||||||
}
|
}
|
||||||
string userDataScenarios = userData + GameConstants::folder_path_scenarios;
|
string userDataScenarios = userData + GameConstants::folder_path_scenarios;
|
||||||
if(isdir(userDataScenarios.c_str()) == false) {
|
if(isdir(userDataScenarios.c_str()) == false) {
|
||||||
createDirectoryPaths(userDataScenarios);
|
createDirectoryPaths(userDataScenarios);
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] creating path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userDataScenarios.c_str());
|
||||||
}
|
}
|
||||||
string userDataTechs = userData + GameConstants::folder_path_techs;
|
string userDataTechs = userData + GameConstants::folder_path_techs;
|
||||||
if(isdir(userDataTechs.c_str()) == false) {
|
if(isdir(userDataTechs.c_str()) == false) {
|
||||||
createDirectoryPaths(userDataTechs);
|
createDirectoryPaths(userDataTechs);
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] creating path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userDataTechs.c_str());
|
||||||
}
|
}
|
||||||
string userDataTilesets = userData + GameConstants::folder_path_tilesets;
|
string userDataTilesets = userData + GameConstants::folder_path_tilesets;
|
||||||
if(isdir(userDataTilesets.c_str()) == false) {
|
if(isdir(userDataTilesets.c_str()) == false) {
|
||||||
createDirectoryPaths(userDataTilesets);
|
createDirectoryPaths(userDataTilesets);
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] creating path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userDataTilesets.c_str());
|
||||||
}
|
}
|
||||||
string userDataTutorials = userData + GameConstants::folder_path_tutorials;
|
string userDataTutorials = userData + GameConstants::folder_path_tutorials;
|
||||||
if(isdir(userDataTutorials.c_str()) == false) {
|
if(isdir(userDataTutorials.c_str()) == false) {
|
||||||
createDirectoryPaths(userDataTutorials);
|
createDirectoryPaths(userDataTutorials);
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] creating path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userDataTutorials.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(scenarioDir != "") {
|
if(scenarioDir != "") {
|
||||||
|
@@ -122,6 +122,7 @@ vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(co
|
|||||||
void createDirectoryPaths(string Path);
|
void createDirectoryPaths(string Path);
|
||||||
string extractFileFromDirectoryPath(string filename);
|
string extractFileFromDirectoryPath(string filename);
|
||||||
string extractDirectoryPathFromFile(string filename);
|
string extractDirectoryPathFromFile(string filename);
|
||||||
|
string extractLastDirectoryFromPath(string Path);
|
||||||
string extractExtension(const string& filename);
|
string extractExtension(const string& filename);
|
||||||
|
|
||||||
void getFullscreenVideoModes(list<ModeInfo> *modeinfos);
|
void getFullscreenVideoModes(list<ModeInfo> *modeinfos);
|
||||||
|
@@ -32,7 +32,7 @@ namespace Shared{ namespace Util{
|
|||||||
|
|
||||||
class Properties{
|
class Properties{
|
||||||
private:
|
private:
|
||||||
static const int maxLine= 1024;
|
static const int maxLine= 4096;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef pair<string, string> PropertyPair;
|
typedef pair<string, string> PropertyPair;
|
||||||
@@ -44,6 +44,7 @@ private:
|
|||||||
PropertyMap propertyMap;
|
PropertyMap propertyMap;
|
||||||
string path;
|
string path;
|
||||||
|
|
||||||
|
bool applyTagsToValue(string &value);
|
||||||
public:
|
public:
|
||||||
void clear();
|
void clear();
|
||||||
void load(const string &path);
|
void load(const string &path);
|
||||||
|
@@ -813,6 +813,28 @@ string extractDirectoryPathFromFile(string filename) {
|
|||||||
return path;
|
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) {
|
string extractExtension(const string& filepath) {
|
||||||
size_t lastPoint = filepath.find_last_of('.');
|
size_t lastPoint = filepath.find_last_of('.');
|
||||||
size_t lastDirectory = 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);
|
return filepath.substr(lastPoint+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void createDirectoryPaths(string Path)
|
void createDirectoryPaths(string Path) {
|
||||||
{
|
|
||||||
char DirName[256]="";
|
char DirName[256]="";
|
||||||
const char *path = Path.c_str();
|
const char *path = Path.c_str();
|
||||||
char *dirName = DirName;
|
char *dirName = DirName;
|
||||||
while(*path)
|
while(*path) {
|
||||||
{
|
|
||||||
//if (('\\' == *path) || ('/' == *path))
|
//if (('\\' == *path) || ('/' == *path))
|
||||||
if ('/' == *path)
|
if ('/' == *path) {
|
||||||
{
|
|
||||||
//if (':' != *(path-1))
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
int result = _mkdir(DirName);
|
int result = _mkdir(DirName);
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
@@ -843,7 +860,6 @@ void createDirectoryPaths(string Path)
|
|||||||
#error "Your compiler needs to support mkdir!"
|
#error "Your compiler needs to support mkdir!"
|
||||||
#endif
|
#endif
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] DirName [%s] result = %d, errno = %d\n",__FILE__,__FUNCTION__,__LINE__,DirName,result,errno);
|
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++ = *path++;
|
||||||
*dirName = '\0';
|
*dirName = '\0';
|
||||||
@@ -1092,10 +1108,16 @@ bool isKeyDown(int virtualKey) {
|
|||||||
|
|
||||||
string replaceAll(string& context, const string& from, const string& to) {
|
string replaceAll(string& context, const string& from, const string& to) {
|
||||||
size_t lookHere = 0;
|
size_t lookHere = 0;
|
||||||
size_t foundHere;
|
size_t foundHere = 0;
|
||||||
while((foundHere = context.find(from, lookHere)) != string::npos) {
|
if((foundHere = context.find(from, lookHere)) != string::npos) {
|
||||||
context.replace(foundHere, from.size(), to);
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Replacing context [%s] from [%s] to [%s]\n",context.c_str(),from.c_str(),to.c_str());
|
||||||
lookHere = foundHere + to.size();
|
|
||||||
|
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;
|
return context;
|
||||||
}
|
}
|
||||||
|
@@ -17,9 +17,11 @@
|
|||||||
|
|
||||||
#include "conversion.h"
|
#include "conversion.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "platform_common.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace Shared::PlatformCommon;
|
||||||
|
|
||||||
namespace Shared{ namespace Util{
|
namespace Shared{ namespace Util{
|
||||||
|
|
||||||
@@ -66,6 +68,10 @@ void Properties::load(const string &path){
|
|||||||
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);
|
||||||
|
|
||||||
|
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));
|
propertyMap.insert(PropertyPair(key, value));
|
||||||
propertyVector.push_back(PropertyPair(key, value));
|
propertyVector.push_back(PropertyPair(key, value));
|
||||||
}
|
}
|
||||||
@@ -75,6 +81,29 @@ void Properties::load(const string &path){
|
|||||||
fileStream.close();
|
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){
|
void Properties::save(const string &path){
|
||||||
ofstream fileStream;
|
ofstream fileStream;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user