fallback for ini importer

actorid
Sebastian Wick 13 years ago
parent 16674ad141
commit 6e19076dc5

@ -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<std::string, std::string>(map[i][0], map[i][1]));
}
for(int i=0; fallback[i][0]; i++) {
mMergeFallback.insert(std::make_pair<std::string, std::string>(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<std::string, std::vector<std::string> >(it->first, iniIt->second));
for(std::vector<std::string>::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<std::string>::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<std::string, std::vector<std::string> >(key, std::vector<std::string>() ));
}
cfg[key].push_back(value);
}
void MwIniImporter::importGameFiles(multistrmap &cfg, multistrmap &ini) {

@ -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<boost::iostreams::file_sink> &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;
};

@ -16,6 +16,7 @@ int main(int argc, char *argv[]) {
("ini,i", bpo::value<std::string>(), "morrowind.ini file")
("cfg,c", bpo::value<std::string>(), "openmw.cfg file")
("output,o", bpo::value<std::string>()->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);
}

Loading…
Cancel
Save