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:
@@ -26,7 +26,8 @@
|
|||||||
#include "FindFile.h"
|
#include "FindFile.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
#include "Debug.h"
|
#include "Debug.h"
|
||||||
|
#include "ConfigHandler.h"
|
||||||
|
#include "sdl/CSettings.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
# ifndef _WIN32_IE
|
# ifndef _WIN32_IE
|
||||||
@@ -68,6 +69,38 @@
|
|||||||
#endif
|
#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;
|
searchpathlist tSearchPaths;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ inline bool GetExactFileName(const std::string& abs_searchname, std::string& fil
|
|||||||
|
|
||||||
extern searchpathlist basesearchpaths;
|
extern searchpathlist basesearchpaths;
|
||||||
void InitBaseSearchPaths();
|
void InitBaseSearchPaths();
|
||||||
|
void InitSearchPaths();
|
||||||
|
|
||||||
// this does a search on all searchpaths for the file and returns the first one found
|
// this does a search on all searchpaths for the file and returns the first one found
|
||||||
// if none was found, NULL will be returned
|
// if none was found, NULL will be returned
|
||||||
|
|||||||
@@ -8,13 +8,13 @@
|
|||||||
#include "CParser.h"
|
#include "CParser.h"
|
||||||
#include "../CLogFile.h"
|
#include "../CLogFile.h"
|
||||||
#include "../StringUtils.h"
|
#include "../StringUtils.h"
|
||||||
|
#include "../sdl/CSettings.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
std::string CONFIGFILENAME = "genius.cfg";
|
|
||||||
|
|
||||||
|
|
||||||
CParser::CParser() {
|
CParser::CParser() {
|
||||||
|
m_configfile = CONFIGFILENAME;
|
||||||
m_isOpen = false;
|
m_isOpen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ bool CParser::loadParseFile() // Open, read the list and close the file
|
|||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if((fp=fopen(CONFIGFILENAME.c_str(),"rt")))
|
if((fp=fopen(m_configfile.c_str(),"rt")))
|
||||||
{
|
{
|
||||||
while(!feof(fp))
|
while(!feof(fp))
|
||||||
{
|
{
|
||||||
@@ -62,7 +62,7 @@ bool CParser::saveParseFile() // open, write on the file and close
|
|||||||
{
|
{
|
||||||
FILE *fp;
|
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 )
|
for(std::list<std::string>::iterator i=m_filebuffer.begin() ; i != m_filebuffer.end() ; ++i )
|
||||||
fprintf(fp,"%s\n",i->c_str());
|
fprintf(fp,"%s\n",i->c_str());
|
||||||
|
|||||||
@@ -13,8 +13,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
extern std::string CONFIGFILENAME;
|
|
||||||
|
|
||||||
class CParser {
|
class CParser {
|
||||||
public:
|
public:
|
||||||
CParser();
|
CParser();
|
||||||
@@ -39,6 +37,7 @@ public:
|
|||||||
bool isOpen() {return m_isOpen;}
|
bool isOpen() {return m_isOpen;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string m_configfile;
|
||||||
bool m_isOpen;
|
bool m_isOpen;
|
||||||
|
|
||||||
std::list<std::string> m_filebuffer;
|
std::list<std::string> m_filebuffer;
|
||||||
|
|||||||
27
src/main.cpp
27
src/main.cpp
@@ -47,6 +47,8 @@
|
|||||||
#include "CGame.h"
|
#include "CGame.h"
|
||||||
#include "CGraphics.h"
|
#include "CGraphics.h"
|
||||||
#include "sdl/CSettings.h"
|
#include "sdl/CSettings.h"
|
||||||
|
#include "FindFile.h"
|
||||||
|
|
||||||
|
|
||||||
int IntroCanceled;
|
int IntroCanceled;
|
||||||
int NessieObjectHandle;
|
int NessieObjectHandle;
|
||||||
@@ -56,7 +58,7 @@ int DemoSprite;
|
|||||||
int framebyframe;
|
int framebyframe;
|
||||||
int fps=0, curfps=0;
|
int fps=0, curfps=0;
|
||||||
|
|
||||||
stOption *options;
|
stOption *options = NULL;
|
||||||
|
|
||||||
|
|
||||||
unsigned int demo_RLERunLen;
|
unsigned int demo_RLERunLen;
|
||||||
@@ -66,10 +68,10 @@ unsigned int demo_data_index;
|
|||||||
char QuitState = NO_QUIT;
|
char QuitState = NO_QUIT;
|
||||||
|
|
||||||
stString strings[MAX_STRINGS+1];
|
stString strings[MAX_STRINGS+1];
|
||||||
int numStrings;
|
int numStrings = 0;
|
||||||
|
|
||||||
int demomode;
|
int demomode;
|
||||||
FILE *demofile;
|
FILE *demofile = NULL;
|
||||||
|
|
||||||
char ScreenIsScrolling;
|
char ScreenIsScrolling;
|
||||||
int gunfiretimer, gunfirefreq;
|
int gunfiretimer, gunfirefreq;
|
||||||
@@ -94,9 +96,9 @@ stMap map;
|
|||||||
unsigned int AnimTileInUse[ATILEINUSE_SIZEX][ATILEINUSE_SIZEY];
|
unsigned int AnimTileInUse[ATILEINUSE_SIZEX][ATILEINUSE_SIZEY];
|
||||||
stTile tiles[MAX_TILES+1];
|
stTile tiles[MAX_TILES+1];
|
||||||
int numtiles;
|
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];
|
unsigned char tiledata[MAX_TILES+1][16][16];
|
||||||
stSprite *sprites;
|
stSprite *sprites = NULL;
|
||||||
stBitmap bitmaps[MAX_BITMAPS+1];
|
stBitmap bitmaps[MAX_BITMAPS+1];
|
||||||
stObject objects[MAX_OBJECTS+1];
|
stObject objects[MAX_OBJECTS+1];
|
||||||
char font[MAX_FONT+1][8][8];
|
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[])
|
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
|
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.
|
// the program instead of having global variables around somewhere.
|
||||||
|
|
||||||
g_pLogFile->CreateLogfile("CGLog.html");
|
g_pLogFile->CreateLogfile("CGLog.html");
|
||||||
|
|
||||||
banner(); // Intro on the text-console.
|
|
||||||
|
|
||||||
CGame Game;
|
CGame Game;
|
||||||
Game.preallocateCKP(&CKP);
|
Game.preallocateCKP(&CKP);
|
||||||
|
|
||||||
|
|||||||
@@ -14,35 +14,7 @@
|
|||||||
#include "../ConfigHandler.h"
|
#include "../ConfigHandler.h"
|
||||||
|
|
||||||
|
|
||||||
void InitSearchPaths() {
|
std::string CONFIGFILENAME = "genius.cfg";
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CSettings::CSettings() {
|
CSettings::CSettings() {
|
||||||
@@ -92,8 +64,8 @@ short CSettings::saveDrvCfg(void)
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
short CSettings::loadDrvCfg(void)
|
short CSettings::loadDrvCfg()
|
||||||
{
|
{
|
||||||
short retval = 0;
|
short retval = 0;
|
||||||
CParser Parser;
|
CParser Parser;
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#ifndef CSETTINGS_H_
|
#ifndef CSETTINGS_H_
|
||||||
#define CSETTINGS_H_
|
#define CSETTINGS_H_
|
||||||
|
|
||||||
|
extern std::string CONFIGFILENAME;
|
||||||
|
|
||||||
enum e_OptionKeywords
|
enum e_OptionKeywords
|
||||||
{ OPT_FULLYAUTOMATIC, OPT_SUPERPOGO,
|
{ OPT_FULLYAUTOMATIC, OPT_SUPERPOGO,
|
||||||
OPT_ALLOWPKING, OPT_CHEATS,
|
OPT_ALLOWPKING, OPT_CHEATS,
|
||||||
|
|||||||
Reference in New Issue
Block a user