initialising searchpath system and some cleanup

git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@148 4df4b0f3-56ce-47cb-b001-ed939b7d65a6
This commit is contained in:
albertzeyer
2009-07-24 15:05:36 +00:00
parent dcc4c9b777
commit 60bce8a456
7 changed files with 65 additions and 45 deletions

View File

@@ -26,7 +26,8 @@
#include "FindFile.h"
#include "StringUtils.h"
#include "Debug.h"
#include "ConfigHandler.h"
#include "sdl/CSettings.h"
#ifdef WIN32
# ifndef _WIN32_IE
@@ -68,6 +69,38 @@
#endif
void InitSearchPaths() {
// have to set to find the config at some of the default places
InitBaseSearchPaths();
int i = 1;
while(true) {
std::string value;
if(!ReadString(CONFIGFILENAME, "FileHandling", "SearchPath" + itoa(i), 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;
}
searchpathlist tSearchPaths;

View File

@@ -163,6 +163,7 @@ inline bool GetExactFileName(const std::string& abs_searchname, std::string& fil
extern searchpathlist basesearchpaths;
void InitBaseSearchPaths();
void InitSearchPaths();
// this does a search on all searchpaths for the file and returns the first one found
// if none was found, NULL will be returned

View File

@@ -8,13 +8,13 @@
#include "CParser.h"
#include "../CLogFile.h"
#include "../StringUtils.h"
#include "../sdl/CSettings.h"
#include <cstdio>
#include <cstdlib>
std::string CONFIGFILENAME = "genius.cfg";
CParser::CParser() {
m_configfile = CONFIGFILENAME;
m_isOpen = false;
}
@@ -41,7 +41,7 @@ bool CParser::loadParseFile() // Open, read the list and close the file
{
FILE *fp;
if((fp=fopen(CONFIGFILENAME.c_str(),"rt")))
if((fp=fopen(m_configfile.c_str(),"rt")))
{
while(!feof(fp))
{
@@ -62,7 +62,7 @@ bool CParser::saveParseFile() // open, write on the file and close
{
FILE *fp;
if((fp=fopen(CONFIGFILENAME.c_str(),"wt")))
if((fp=fopen(m_configfile.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());

View File

@@ -13,8 +13,6 @@
#include <string>
#include <cstdio>
extern std::string CONFIGFILENAME;
class CParser {
public:
CParser();
@@ -39,6 +37,7 @@ public:
bool isOpen() {return m_isOpen;}
private:
std::string m_configfile;
bool m_isOpen;
std::list<std::string> m_filebuffer;

View File

@@ -47,6 +47,8 @@
#include "CGame.h"
#include "CGraphics.h"
#include "sdl/CSettings.h"
#include "FindFile.h"
int IntroCanceled;
int NessieObjectHandle;
@@ -56,7 +58,7 @@ int DemoSprite;
int framebyframe;
int fps=0, curfps=0;
stOption *options;
stOption *options = NULL;
unsigned int demo_RLERunLen;
@@ -66,10 +68,10 @@ unsigned int demo_data_index;
char QuitState = NO_QUIT;
stString strings[MAX_STRINGS+1];
int numStrings;
int numStrings = 0;
int demomode;
FILE *demofile;
FILE *demofile = NULL;
char ScreenIsScrolling;
int gunfiretimer, gunfirefreq;
@@ -94,9 +96,9 @@ stMap map;
unsigned int AnimTileInUse[ATILEINUSE_SIZEX][ATILEINUSE_SIZEY];
stTile tiles[MAX_TILES+1];
int numtiles;
int **TileProperty; // This version will replace the old stTile Structure and save memory
int **TileProperty = NULL; // This version will replace the old stTile Structure and save memory
unsigned char tiledata[MAX_TILES+1][16][16];
stSprite *sprites;
stSprite *sprites = NULL;
stBitmap bitmaps[MAX_BITMAPS+1];
stObject objects[MAX_OBJECTS+1];
char font[MAX_FONT+1][8][8];
@@ -117,14 +119,25 @@ const char *why_term_ptr = "No reason given.";
int main(int argc, char *argv[])
{
banner(); // Intro on the text-console.
if(argc >= 1) {
size_t slashpos = findLastPathSep(binary_dir);
if(slashpos != std::string::npos) {
binary_dir.erase(slashpos);
binary_dir = SystemNativeToUtf8(binary_dir);
} else
binary_dir = ".";
} else
binary_dir = ".";
InitSearchPaths();
stCloneKeenPlus CKP; // This is the future main structure of CloneKeen. It will be one variable which controls all
// the program instead of having global variables around somewhere.
g_pLogFile->CreateLogfile("CGLog.html");
banner(); // Intro on the text-console.
CGame Game;
Game.preallocateCKP(&CKP);

View File

@@ -14,35 +14,7 @@
#include "../ConfigHandler.h"
void InitSearchPaths() {
// have to set to find the config at some of the default places
InitBaseSearchPaths();
int i = 1;
while(true) {
std::string value;
if(!ReadString(CONFIGFILENAME, "FileHandling", "SearchPath" + itoa(i), 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;
}
std::string CONFIGFILENAME = "genius.cfg";
CSettings::CSettings() {
@@ -92,8 +64,8 @@ short CSettings::saveDrvCfg(void)
return retval;
}
short CSettings::loadDrvCfg(void)
{
short CSettings::loadDrvCfg()
{
short retval = 0;
CParser Parser;

View File

@@ -8,6 +8,8 @@
#ifndef CSETTINGS_H_
#define CSETTINGS_H_
extern std::string CONFIGFILENAME;
enum e_OptionKeywords
{ OPT_FULLYAUTOMATIC, OPT_SUPERPOGO,
OPT_ALLOWPKING, OPT_CHEATS,