From 6e19076dc55b20bdd71a9ba4e680dee5018721ed Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 2 Apr 2012 17:07:18 +0200 Subject: [PATCH] fallback for ini importer --- apps/mwiniimporter/importer.cpp | 39 ++++++++++++++++++++++++++++----- apps/mwiniimporter/importer.hpp | 4 +++- apps/mwiniimporter/main.cpp | 9 ++++++-- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 08b05f417..80ec4a5fd 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -14,10 +14,19 @@ MwIniImporter::MwIniImporter() { { "fps", "General:Show FPS" }, { 0, 0 } }; + const char *fallback[][2] = { + { "Weather_Sunrise_Time", "Weather:Sunrise Time" }, + { "Weather_Sunset_Time", "Weather:Sunset Time" }, + { 0, 0 } + }; for(int i=0; map[i][0]; i++) { mMergeMap.insert(std::make_pair(map[i][0], map[i][1])); } + + for(int i=0; fallback[i][0]; i++) { + mMergeFallback.insert(std::make_pair(fallback[i][0], fallback[i][1])); + } } void MwIniImporter::setVerbose(bool verbose) { @@ -116,16 +125,36 @@ void MwIniImporter::merge(multistrmap &cfg, multistrmap &ini) { multistrmap::iterator iniIt; for(strmap::iterator it=mMergeMap.begin(); it!=mMergeMap.end(); it++) { if((iniIt = ini.find(it->second)) != ini.end()) { - cfg.erase(it->first); - if(!this->specialMerge(it->first, it->second, cfg, ini)) { - cfg.insert(std::make_pair >(it->first, iniIt->second)); + for(std::vector::iterator vc = iniIt->second.begin(); vc != iniIt->second.end(); vc++) { + cfg.erase(it->first); + insertMultistrmap(cfg, it->first, *vc); } } } } -bool MwIniImporter::specialMerge(std::string cfgKey, std::string iniKey, multistrmap &cfg, multistrmap &ini) { - return false; +void MwIniImporter::mergeFallback(multistrmap &cfg, multistrmap &ini) { + cfg.erase("fallback"); + + multistrmap::iterator cfgIt; + multistrmap::iterator iniIt; + for(strmap::iterator it=mMergeFallback.begin(); it!=mMergeFallback.end(); it++) { + if((iniIt = ini.find(it->second)) != ini.end()) { + for(std::vector::iterator vc = iniIt->second.begin(); vc != iniIt->second.end(); vc++) { + std::string value("\""); + value.append(it->first).append("=").append(vc->substr(0,vc->length()-1)).append("\""); + insertMultistrmap(cfg, "fallback", value); + } + } + } +}; + +void MwIniImporter::insertMultistrmap(multistrmap &cfg, std::string key, std::string value) { + multistrmap::iterator it = cfg.find(key); + if(it == cfg.end()) { + cfg.insert(std::make_pair >(key, std::vector() )); + } + cfg[key].push_back(value); } void MwIniImporter::importGameFiles(multistrmap &cfg, multistrmap &ini) { diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index 988f10255..9ef7b6703 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -18,14 +18,16 @@ class MwIniImporter { multistrmap loadIniFile(std::string filename); multistrmap loadCfgFile(std::string filename); void merge(multistrmap &cfg, multistrmap &ini); + void mergeFallback(multistrmap &cfg, multistrmap &ini); void importGameFiles(multistrmap &cfg, multistrmap &ini); void writeToFile(boost::iostreams::stream &out, multistrmap &cfg); private: - bool specialMerge(std::string cfgKey, std::string iniKey, multistrmap &cfg, multistrmap &ini); + void insertMultistrmap(multistrmap &cfg, std::string key, std::string value); std::string numberToString(int n); bool mVerbose; strmap mMergeMap; + strmap mMergeFallback; }; diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 836f84eb0..c5409b812 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -16,6 +16,7 @@ int main(int argc, char *argv[]) { ("ini,i", bpo::value(), "morrowind.ini file") ("cfg,c", bpo::value(), "openmw.cfg file") ("output,o", bpo::value()->default_value(""), "openmw.cfg file") + ("fallback,f", "import fallback settings") ("game-files,g", "import esm and esp files") ; @@ -44,7 +45,7 @@ int main(int argc, char *argv[]) { std::cerr << "cfg file does not exist" << std::endl; return -4; } - + MwIniImporter importer; importer.setVerbose(vm.count("verbose")); @@ -52,7 +53,11 @@ int main(int argc, char *argv[]) { MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile); importer.merge(cfg, ini); - + + if(vm.count("fallback")) { + importer.mergeFallback(cfg, ini); + } + if(vm.count("game-files")) { importer.importGameFiles(cfg, ini); }