From eff156a1dcfdee20441d24ca2d21a94783ce9d0f Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 13 Jun 2008 20:57:07 +0100 Subject: [PATCH] Fix config file bugs --- src/ConfigFile.cpp | 5 +++++ src/Main.cpp | 10 ++++++---- src/Options.cpp | 30 +++++++++++++++++++++++++++++- src/Options.hpp | 3 +++ 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/ConfigFile.cpp b/src/ConfigFile.cpp index 23e8e8f..602d73e 100644 --- a/src/ConfigFile.cpp +++ b/src/ConfigFile.cpp @@ -31,6 +31,8 @@ ConfigFile::ConfigFile(string filename) break; cout << "key=" << key << " value=" << value << endl; + + settings[key] = value; } ifs.close(); @@ -41,6 +43,8 @@ ConfigFile::~ConfigFile() if (dirty) { ofstream of((GetConfigDir() + filename).c_str()); + cout << "Writing config file" << endl; + for (map::iterator it = settings.begin(); it != settings.end(); ++it) { @@ -110,6 +114,7 @@ bool ConfigFile::get_bool(const string &key, bool def) void ConfigFile::put(string key, string value) { + cout << "put " << key << "=" << value << endl; settings[key] = value; dirty = true; } diff --git a/src/Main.cpp b/src/Main.cpp index 0b2ba5c..268d654 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -40,10 +40,12 @@ int main(int argc, char **argv) const int DEFAULT_VRES = 600; const int DEFAULT_FSCREEN = false; - ConfigFile cfile; - width = cfile.get_int("hres", DEFAULT_HRES); - height = cfile.get_int("vres", DEFAULT_VRES); - fullscreen = cfile.get_bool("fullscreen", DEFAULT_FSCREEN); + { + ConfigFile cfile; + width = cfile.get_int("hres", DEFAULT_HRES); + height = cfile.get_int("vres", DEFAULT_VRES); + fullscreen = cfile.get_bool("fullscreen", DEFAULT_FSCREEN); + } #ifdef WIN32 // Work out colour depth diff --git a/src/Options.cpp b/src/Options.cpp index f93bcd5..8d12bc5 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -95,7 +95,19 @@ void Options::ProcessMain() void Options::Apply() { - + for (ItemListIt it = items.begin(); it != items.end(); ++it) { + if ((*it).name == "Fullscreen") { + cout << "Set fullscreen" << endl; + cfile.put("fullscreen", (*it).active == 0); + } + if ((*it).name == "Resolution") { + int hres, vres; + + ParseResolutionString((*it).values[(*it).active], &hres, &vres); + + cout << "set res " << hres << "x" << vres << endl; + } + } } void Options::ProcessFadeOut() @@ -202,3 +214,19 @@ void Options::Display() DisplayItems(); } +string Options::MakeResolutionString(int hres, int vres) const +{ + ostringstream ss; + ss << hres << "x" << vres; + return ss.str(); +} + +void Options::ParseResolutionString(const string &str, int *hres, int *vres) const +{ + char x; + istringstream ss(str); + ss >> *hres; + ss >> x; + assert(x == 'x'); + ss >> *vres; +} diff --git a/src/Options.hpp b/src/Options.hpp index 284684e..5f8bc23 100644 --- a/src/Options.hpp +++ b/src/Options.hpp @@ -39,6 +39,9 @@ private: void DisplayHelpText(); void DisplayItems(); + string MakeResolutionString(int hres, int vres) const; + void ParseResolutionString(const string &str, int *hres, int *vres) const; + void Apply(); static const double FADE_SPEED; -- 2.39.2