more code for searchpath system

git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@146 4df4b0f3-56ce-47cb-b001-ed939b7d65a6
This commit is contained in:
albertzeyer
2009-07-24 14:36:34 +00:00
parent 4ca87c10e1
commit bb08df4b19
4 changed files with 51 additions and 21 deletions

View File

@@ -18,7 +18,6 @@
#ifdef _MSC_VER
#pragma warning(disable: 4786) // WARNING: identifier XXX was truncated to 255 characters in the debug info
#pragma warning(disable: 4503) // WARNING: decorated name length exceeded, name was truncated
@@ -423,19 +422,19 @@ bool GetExactFileName(const std::string& abs_searchname, std::string& filename)
searchpathlist basesearchpaths;
void InitBaseSearchPaths() {
basesearchpaths.clear();
#if defined(MACOSX)
AddToFileList(&basesearchpaths, "${HOME}/Library/Application Support/OpenLieroX");
#if defined(__APPLE__)
AddToFileList(&basesearchpaths, "${HOME}/Library/Application Support/Commander Genius");
AddToFileList(&basesearchpaths, ".");
AddToFileList(&basesearchpaths, "${BIN}/../Resources/gamedir");
AddToFileList(&basesearchpaths, SYSTEM_DATA_DIR"/OpenLieroX");
AddToFileList(&basesearchpaths, "${BIN}/../Resources/data");
AddToFileList(&basesearchpaths, SYSTEM_DATA_DIR"/commandergenius");
#elif defined(WIN32)
AddToFileList(&basesearchpaths, "${HOME}/OpenLieroX");
AddToFileList(&basesearchpaths, "${HOME}/Commander Genius");
AddToFileList(&basesearchpaths, ".");
AddToFileList(&basesearchpaths, "${BIN}");
#else // all other systems (Linux, *BSD, OS/2, ...)
AddToFileList(&basesearchpaths, "${HOME}/.OpenLieroX");
AddToFileList(&basesearchpaths, "${HOME}/.CommanderGenius");
AddToFileList(&basesearchpaths, ".");
AddToFileList(&basesearchpaths, SYSTEM_DATA_DIR"/OpenLieroX"); // no use of ${SYSTEM_DATA}, because it is uncommon and could cause confusion to the user
AddToFileList(&basesearchpaths, SYSTEM_DATA_DIR"/commandergenius"); // no use of ${SYSTEM_DATA}, because it is uncommon and could cause confusion to the user
#endif
}

View File

@@ -11,7 +11,7 @@
#include <cstdio>
#include <cstdlib>
#define CONFIGFILENAME "genius.cfg"
std::string CONFIGFILENAME = "genius.cfg";
CParser::CParser() {
@@ -41,7 +41,7 @@ bool CParser::loadParseFile() // Open, read the list and close the file
{
FILE *fp;
if((fp=fopen(CONFIGFILENAME,"rt")))
if((fp=fopen(CONFIGFILENAME.c_str(),"rt")))
{
while(!feof(fp))
{
@@ -52,12 +52,9 @@ bool CParser::loadParseFile() // Open, read the list and close the file
fclose(fp);
return true;
}
else
{
g_pLogFile->ftextOut(GREEN,"Parser : The file has not been found. When CKP is trying to save the file it will create a new one.");
return false;
}
g_pLogFile->ftextOut(GREEN,"Parser : The file has not been found. When CKP is trying to save the file it will create a new one.");
return false;
}
// Close the text which was parsed. This will also copy all stuff of the memory to the file.
@@ -65,7 +62,7 @@ bool CParser::saveParseFile() // open, write on the file and close
{
FILE *fp;
if((fp=fopen(CONFIGFILENAME,"wt")))
if((fp=fopen(CONFIGFILENAME.c_str(),"wt")))
{
for(std::list<std::string>::iterator i=m_filebuffer.begin() ; i != m_filebuffer.end() ; ++i )
fprintf(fp,"%s\n",i->c_str());
@@ -73,11 +70,9 @@ bool CParser::saveParseFile() // open, write on the file and close
fclose(fp);
return true;
}
else
{
g_pLogFile->ftextOut(RED,"Parser : Error opening the file for write operations. Check your permissions or if the disk is full");
return false;
}
g_pLogFile->ftextOut(RED,"Parser : Error opening the file for write operations. Check your permissions or if the disk is full");
return false;
}
// read the value of the to be seeked keyword and returns it as an int.

View File

@@ -13,6 +13,8 @@
#include <string>
#include <cstdio>
extern std::string CONFIGFILENAME;
class CParser {
public:
CParser();

View File

@@ -10,6 +10,40 @@
#include "CSettings.h"
#include "CVideoDriver.h"
#include "sound/CSound.h"
#include "../FindFile.h"
#include "../ConfigHandler.h"
void InitSearchPaths() {
// have to set to find the config at some of the default places
InitBaseSearchPaths();
std::string value;
int i = 1;
while(true) {
if(!ReadString(CONFIGFILENAME, "FileHandling", "SearchPath" + itoa(i,10), value, ""))
break;
AddToFileList(&tSearchPaths, value);
i++;
}
// add the basesearchpaths to the searchpathlist as they should be saved in the end
for(searchpathlist::const_iterator p1 = basesearchpaths.begin(); p1 != basesearchpaths.end(); i++,p1++) {
AddToFileList(&tSearchPaths, *p1);
}
// print the searchpaths, this may be very usefull for the user
notes << "I have now the following searchpaths (in this order):\n";
for(searchpathlist::const_iterator p2 = tSearchPaths.begin(); p2 != tSearchPaths.end(); p2++) {
std::string path = *p2;
ReplaceFileVariables(path);
notes << " " << path << "\n";
}
notes << " And that's all." << endl;
}
CSettings::CSettings() {
// TODO Auto-generated constructor stub