mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
handle master/plugin properly
This commit is contained in:
parent
092de45924
commit
6d875dfd54
3 changed files with 69 additions and 75 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
MwIniImporter::MwIniImporter() {
|
MwIniImporter::MwIniImporter() {
|
||||||
const char *map[][2] =
|
const char *map[][2] =
|
||||||
|
@ -26,17 +27,12 @@ strmap MwIniImporter::loadIniFile(std::string filename) {
|
||||||
std::cout << "load ini file: " << filename << std::endl;
|
std::cout << "load ini file: " << filename << std::endl;
|
||||||
|
|
||||||
std::string section("");
|
std::string section("");
|
||||||
std::multimap<std::string, std::string> map;
|
std::map<std::string, std::string> map;
|
||||||
boost::iostreams::stream<boost::iostreams::file_source>file(filename.c_str());
|
boost::iostreams::stream<boost::iostreams::file_source>file(filename.c_str());
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(file, line)) {
|
while (std::getline(file, line)) {
|
||||||
|
|
||||||
// ignore sections for now
|
|
||||||
if(line.empty() || line[0] == ';') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(line[0] == '[') {
|
if(line[0] == '[') {
|
||||||
if(line.length() > 2) {
|
if(line.length() > 2) {
|
||||||
section = line.substr(1, line.length()-3);
|
section = line.substr(1, line.length()-3);
|
||||||
|
@ -44,6 +40,15 @@ strmap MwIniImporter::loadIniFile(std::string filename) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int comment_pos = line.find(";");
|
||||||
|
if(comment_pos > 0) {
|
||||||
|
line = line.substr(0,comment_pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(line.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int pos = line.find("=");
|
int pos = line.find("=");
|
||||||
if(pos < 1) {
|
if(pos < 1) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -58,16 +63,12 @@ strmap MwIniImporter::loadIniFile(std::string filename) {
|
||||||
strmap MwIniImporter::loadCfgFile(std::string filename) {
|
strmap MwIniImporter::loadCfgFile(std::string filename) {
|
||||||
std::cout << "load cfg file: " << filename << std::endl;
|
std::cout << "load cfg file: " << filename << std::endl;
|
||||||
|
|
||||||
std::multimap<std::string, std::string> map;
|
std::map<std::string, std::string> map;
|
||||||
boost::iostreams::stream<boost::iostreams::file_source>file(filename.c_str());
|
boost::iostreams::stream<boost::iostreams::file_source>file(filename.c_str());
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(file, line)) {
|
while (std::getline(file, line)) {
|
||||||
|
|
||||||
if(line[0] == '[') { // section
|
|
||||||
continue; // ignore for now
|
|
||||||
}
|
|
||||||
|
|
||||||
// we cant say comment by only looking at first char anymore
|
// we cant say comment by only looking at first char anymore
|
||||||
int comment_pos = line.find("#");
|
int comment_pos = line.find("#");
|
||||||
if(comment_pos > 0) {
|
if(comment_pos > 0) {
|
||||||
|
@ -102,67 +103,50 @@ 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) {
|
bool MwIniImporter::specialMerge(std::string cfgKey, std::string iniKey, strmap &cfg, strmap &ini) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwIniImporter::writeToFile(std::string file, strmap &cfg) {
|
void MwIniImporter::importGameFiles(strmap &cfg, strmap &ini, std::vector<std::string> &esmFiles, std::vector<std::string> &espFiles) {
|
||||||
boost::iostreams::stream<boost::iostreams::file_sink> out(file);
|
std::string baseGameFile("Game Files:GameFile");
|
||||||
|
std::string gameFile("");
|
||||||
|
|
||||||
|
strmap::iterator it = ini.begin();
|
||||||
|
for(int i=0; it != ini.end(); i++) {
|
||||||
|
gameFile = baseGameFile;
|
||||||
|
gameFile.append(1,i+'0');
|
||||||
|
|
||||||
|
it = ini.find(gameFile);
|
||||||
|
if(it == ini.end()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string filetype(it->second.substr(it->second.length()-4, 3));
|
||||||
|
std::transform(filetype.begin(), filetype.end(), filetype.begin(), ::tolower);
|
||||||
|
|
||||||
|
if(filetype.compare("esm") == 0) {
|
||||||
|
esmFiles.push_back(it->second);
|
||||||
|
}
|
||||||
|
else if(filetype.compare("esp") == 0) {
|
||||||
|
espFiles.push_back(it->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
gameFile = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MwIniImporter::writeGameFiles(boost::iostreams::stream<boost::iostreams::file_sink> &out, std::vector<std::string> &esmFiles, std::vector<std::string> &espFiles) {
|
||||||
|
for(std::vector<std::string>::iterator it=esmFiles.begin(); it != esmFiles.end(); it++) {
|
||||||
|
out << "master=" << *it << std::endl;
|
||||||
|
}
|
||||||
|
for(std::vector<std::string>::iterator it=espFiles.begin(); it != espFiles.end(); it++) {
|
||||||
|
out << "plugin=" << *it << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MwIniImporter::writeToFile(boost::iostreams::stream<boost::iostreams::file_sink> &out, strmap &cfg) {
|
||||||
|
cfg.erase("master");
|
||||||
|
cfg.erase("plugin");
|
||||||
|
|
||||||
for(strmap::iterator it=cfg.begin(); it != cfg.end(); it++) {
|
for(strmap::iterator it=cfg.begin(); it != cfg.end(); it++) {
|
||||||
out << (it->first) << "=" << (it->second) << std::endl;
|
out << (it->first) << "=" << (it->second) << std::endl;
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
#ifndef MWINIIMPORTER_IMPORTER
|
#ifndef MWINIIMPORTER_IMPORTER
|
||||||
#define MWINIIMPORTER_IMPORTER 1
|
#define MWINIIMPORTER_IMPORTER 1
|
||||||
|
|
||||||
|
#include <boost/iostreams/device/file.hpp>
|
||||||
|
#include <boost/iostreams/stream.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
|
|
||||||
typedef std::multimap<std::string, std::string> strmap;
|
typedef std::map<std::string, std::string> strmap;
|
||||||
|
|
||||||
class MwIniImporter {
|
class MwIniImporter {
|
||||||
|
|
||||||
|
@ -16,8 +19,9 @@ class MwIniImporter {
|
||||||
strmap loadIniFile(std::string filename);
|
strmap loadIniFile(std::string filename);
|
||||||
strmap loadCfgFile(std::string filename);
|
strmap loadCfgFile(std::string filename);
|
||||||
void merge(strmap &cfg, strmap &ini);
|
void merge(strmap &cfg, strmap &ini);
|
||||||
void importGameFiles(strmap &cfg, strmap &ini);
|
void importGameFiles(strmap &cfg, strmap &ini, std::vector<std::string> &esmFiles, std::vector<std::string> &espFiles);
|
||||||
void writeToFile(std::string file, strmap &cfg);
|
void writeGameFiles(boost::iostreams::stream<boost::iostreams::file_sink> &out, std::vector<std::string> &esmFiles, std::vector<std::string> &espFiles);
|
||||||
|
void writeToFile(boost::iostreams::stream<boost::iostreams::file_sink> &out, strmap &cfg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool specialMerge(std::string cfgKey, std::string iniKey, strmap &cfg, strmap &ini);
|
bool specialMerge(std::string cfgKey, std::string iniKey, strmap &cfg, strmap &ini);
|
||||||
|
|
|
@ -58,21 +58,27 @@ int main(int argc, char *argv[]) {
|
||||||
std::cerr << "cfg file does not exist" << std::endl;
|
std::cerr << "cfg file does not exist" << std::endl;
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MwIniImporter importer;
|
MwIniImporter importer;
|
||||||
importer.setVerbose(vm.count("verbose"));
|
importer.setVerbose(vm.count("verbose"));
|
||||||
|
boost::iostreams::stream<boost::iostreams::file_sink> file(outputFile);
|
||||||
|
|
||||||
std::multimap<std::string, std::string>ini = importer.loadIniFile(iniFile);
|
std::map<std::string, std::string>ini = importer.loadIniFile(iniFile);
|
||||||
std::multimap<std::string, std::string>cfg = importer.loadCfgFile(cfgFile);
|
std::map<std::string, std::string>cfg = importer.loadCfgFile(cfgFile);
|
||||||
|
|
||||||
importer.merge(cfg, ini);
|
importer.merge(cfg, ini);
|
||||||
|
|
||||||
if(vm.count("game-files")) {
|
if(vm.count("game-files")) {
|
||||||
importer.importGameFiles(cfg, ini);
|
std::vector<std::string> esmFiles;
|
||||||
|
std::vector<std::string> espFiles;
|
||||||
|
|
||||||
|
importer.importGameFiles(cfg, ini, esmFiles, espFiles);
|
||||||
|
importer.writeGameFiles(file, esmFiles, espFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "write to: " << outputFile << std::endl;
|
std::cout << "write to: " << outputFile << std::endl;
|
||||||
importer.writeToFile(outputFile, cfg);
|
importer.writeToFile(file, cfg);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue