diff options
author | Stijn Buys <ingar@osirion.org> | 2008-02-22 21:53:36 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-02-22 21:53:36 +0000 |
commit | 9b041ac2e075bfb3a30397a8acdc5432860d2c84 (patch) | |
tree | 2c89930bc7fe38a6d3c80440222dd005e21e1320 /src/core/application.cc | |
parent | 71b6b902732bfc0c53033d58f91a6b1e70e8371f (diff) |
save and load configuration implemented
Diffstat (limited to 'src/core/application.cc')
-rw-r--r-- | src/core/application.cc | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/core/application.cc b/src/core/application.cc index b55df34..7d6f62a 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -10,6 +10,7 @@ #include <iostream> #include <vector> #include <sstream> +#include <fstream> #include "sys/sys.h" #include "math/mathlib.h" @@ -152,11 +153,15 @@ void Application::init() filesystem::init(); CommandBuffer::init(); - // dedicated server has set this to 1 Cvar::sv_dedicated = Cvar::get("sv_dedicated", "0", Cvar::ReadOnly); // client can set this to 1 Cvar::sv_private = Cvar::get("sv_private", "0"); + + // load save cvars + load_config(); + + // framerate settings Cvar::sv_framerate = Cvar::get("sv_framerate", "25"); // network settings @@ -186,6 +191,8 @@ void Application::shutdown() application_game = 0; } + save_config(); + // remove our engine functions Func::remove("print"); Func::remove("help"); @@ -272,4 +279,44 @@ void Application::frame(float seconds) disconnect(); } +void Application::save_config() +{ + std::string filename(filesystem::writedir); + filename.append("config.txt"); + std::ofstream ofs(filename.c_str()); + + if (!ofs.is_open()) { + con_warn << "Could not write " << filename << std::endl; + return; + } + + std::map<std::string, Cvar*>::iterator it; + for (it = Cvar::registry.begin(); it != Cvar::registry.end(); it++) { + + if (((*it).second->flags() & Cvar::Archive) == Cvar::Archive) + ofs << "set " << (*it).first << " " << (*it).second->str() << std::endl; + } + ofs.close(); +} + +void Application::load_config() +{ + std::string filename(filesystem::writedir); + filename.append("config.txt"); + std::ifstream ifs(filename.c_str(), std::ifstream::in); + + if (!ifs.is_open()) { + con_warn << "Could not read " << filename << std::endl; + return; + } + + char line[MAXCMDSIZE]; + while (ifs.getline(line, MAXCMDSIZE-1)) { + cmd() << line << "\n"; + + } + + // execute commands in the buffer + CommandBuffer::exec(); +} } |