From 653fbdd10cf83a3d361b7017b6e491d6df7aa67a Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 31 Mar 2012 18:24:43 +0200 Subject: [PATCH] master/plugin support; needs multimap instead of map --- apps/mwiniimporter/importer.cpp | 58 +++++++++++++++++++++++++++++++++ apps/mwiniimporter/importer.hpp | 1 + apps/mwiniimporter/main.cpp | 5 +++ 3 files changed, 64 insertions(+) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 09088774b..7532bf1da 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -2,6 +2,9 @@ #include #include #include +#include +#include +#include MwIniImporter::MwIniImporter() { const char *map[][2] = @@ -99,6 +102,61 @@ void MwIniImporter::merge(strmap &cfg, strmap &ini) { } } +void MwIniImporter::importGameFiles(strmap &cfg, strmap &ini) { + std::vector esmFiles; + std::string baseEsm("Game Files:GameFile"); + std::string esmFile(""); + + strmap::iterator it = ini.begin(); + for(int i=0; it != ini.end(); i++) { + esmFile = baseEsm; + esmFile.append(1,i+'0'); + + it = ini.find(esmFile); + if(it == ini.end()) { + break; + } + + std::cout << "found EMS file: " << it->second << std::endl; + esmFiles.push_back(it->second); + esmFile = ""; + } + + + std::vector bsaFiles; + std::string baseBsa("Archives:Archive "); + std::string bsaFile(""); + + it = ini.begin(); + for(int i=0; it != ini.end(); i++) { + bsaFile = baseBsa; + bsaFile.append(1,i+'0'); + + it = ini.find(bsaFile); + if(it == ini.end()) { + break; + } + + std::cout << "found BSA file: " << it->second << std::endl; + bsaFiles.push_back(it->second); + bsaFile = ""; + } + + if(!esmFiles.empty()) { + cfg.erase("master"); + for(std::vector::iterator it = esmFiles.begin(); it != esmFiles.end(); it++) { + cfg.insert(std::make_pair("master", *it)); + } + } + + if(!bsaFile.empty()) { + cfg.erase("plugin"); + for(std::vector::iterator it = bsaFiles.begin(); it != bsaFiles.end(); it++) { + cfg.insert(std::make_pair("plugin", *it)); + } + } +} + bool MwIniImporter::specialMerge(std::string cfgKey, std::string iniKey, strmap &cfg, strmap &ini) { return false; } diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index ad5aaacde..13cb02ee6 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -16,6 +16,7 @@ class MwIniImporter { strmap loadIniFile(std::string filename); strmap loadCfgFile(std::string filename); void merge(strmap &cfg, strmap &ini); + void importGameFiles(strmap &cfg, strmap &ini); void writeToFile(std::string file, strmap &cfg); private: diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 059703ea8..87225432d 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") + ("game-files,g", "import esm and esp files") ; bpo::variables_map vm; @@ -65,6 +66,10 @@ int main(int argc, char *argv[]) { std::mapcfg = importer.loadCfgFile(cfgFile); importer.merge(cfg, ini); + + if(vm.count("game-files")) { + importer.importGameFiles(cfg, ini); + } std::cout << "write to: " << outputFile << std::endl; importer.writeToFile(outputFile, cfg);