Skip to content

Commit

Permalink
master/plugin support; needs multimap instead of map
Browse files Browse the repository at this point in the history
  • Loading branch information
swick committed Mar 31, 2012
1 parent ceedae4 commit 653fbdd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
58 changes: 58 additions & 0 deletions apps/mwiniimporter/importer.cpp
Expand Up @@ -2,6 +2,9 @@
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/stream.hpp>
#include <iostream>
#include <string>
#include <map>
#include <vector>

MwIniImporter::MwIniImporter() {
const char *map[][2] =
Expand Down Expand Up @@ -99,6 +102,61 @@ void MwIniImporter::merge(strmap &cfg, strmap &ini) {
}
}

void MwIniImporter::importGameFiles(strmap &cfg, strmap &ini) {
std::vector<std::string> 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<std::string> 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<std::string>::iterator it = esmFiles.begin(); it != esmFiles.end(); it++) {
cfg.insert(std::make_pair<std::string, std::string>("master", *it));
}
}

if(!bsaFile.empty()) {
cfg.erase("plugin");
for(std::vector<std::string>::iterator it = bsaFiles.begin(); it != bsaFiles.end(); it++) {
cfg.insert(std::make_pair<std::string, std::string>("plugin", *it));
}
}
}

bool MwIniImporter::specialMerge(std::string cfgKey, std::string iniKey, strmap &cfg, strmap &ini) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions apps/mwiniimporter/importer.hpp
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions apps/mwiniimporter/main.cpp
Expand Up @@ -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")
("game-files,g", "import esm and esp files")
;

bpo::variables_map vm;
Expand Down Expand Up @@ -65,6 +66,10 @@ int main(int argc, char *argv[]) {
std::map<std::string, std::string>cfg = 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);
Expand Down

0 comments on commit 653fbdd

Please sign in to comment.