From 60bce8a45673e11a8a4e4e0223246b39fb104a50 Mon Sep 17 00:00:00 2001 From: albertzeyer Date: Fri, 24 Jul 2009 15:05:36 +0000 Subject: [PATCH] initialising searchpath system and some cleanup git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@148 4df4b0f3-56ce-47cb-b001-ed939b7d65a6 --- src/FindFile.cpp | 35 ++++++++++++++++++++++++++++++++++- src/FindFile.h | 1 + src/fileio/CParser.cpp | 8 ++++---- src/fileio/CParser.h | 3 +-- src/main.cpp | 27 ++++++++++++++++++++------- src/sdl/CSettings.cpp | 34 +++------------------------------- src/sdl/CSettings.h | 2 ++ 7 files changed, 65 insertions(+), 45 deletions(-) diff --git a/src/FindFile.cpp b/src/FindFile.cpp index 50d320282..19b24618c 100644 --- a/src/FindFile.cpp +++ b/src/FindFile.cpp @@ -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; diff --git a/src/FindFile.h b/src/FindFile.h index 23d3e6532..bd08d8827 100644 --- a/src/FindFile.h +++ b/src/FindFile.h @@ -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 diff --git a/src/fileio/CParser.cpp b/src/fileio/CParser.cpp index 8983e4973..5938fc6a4 100644 --- a/src/fileio/CParser.cpp +++ b/src/fileio/CParser.cpp @@ -8,13 +8,13 @@ #include "CParser.h" #include "../CLogFile.h" #include "../StringUtils.h" +#include "../sdl/CSettings.h" #include #include -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::iterator i=m_filebuffer.begin() ; i != m_filebuffer.end() ; ++i ) fprintf(fp,"%s\n",i->c_str()); diff --git a/src/fileio/CParser.h b/src/fileio/CParser.h index 0864385b0..d9fb02735 100644 --- a/src/fileio/CParser.h +++ b/src/fileio/CParser.h @@ -13,8 +13,6 @@ #include #include -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 m_filebuffer; diff --git a/src/main.cpp b/src/main.cpp index 513904263..93f63f3b1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); diff --git a/src/sdl/CSettings.cpp b/src/sdl/CSettings.cpp index 0b9a90cd1..a53b15c49 100644 --- a/src/sdl/CSettings.cpp +++ b/src/sdl/CSettings.cpp @@ -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; diff --git a/src/sdl/CSettings.h b/src/sdl/CSettings.h index f60dd206e..37ccdd1dd 100644 --- a/src/sdl/CSettings.h +++ b/src/sdl/CSettings.h @@ -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,