From fbd626baf69da248f64e0545d635799469a7a09e Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Fri, 30 Mar 2012 20:59:44 +0200 Subject: [PATCH 01/12] mwiniimporter --- CMakeLists.txt | 7 +++++- apps/mwiniimporter/CMakeLists.txt | 21 +++++++++++++++++ apps/mwiniimporter/importer.cpp | 6 +++++ apps/mwiniimporter/importer.hpp | 17 ++++++++++++++ apps/mwiniimporter/main.cpp | 39 +++++++++++++++++++++++++++++++ apps/mwiniimporter/main.hpp | 11 +++++++++ 6 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 apps/mwiniimporter/CMakeLists.txt create mode 100644 apps/mwiniimporter/importer.cpp create mode 100644 apps/mwiniimporter/importer.hpp create mode 100644 apps/mwiniimporter/main.cpp create mode 100644 apps/mwiniimporter/main.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f007dbcc..552a6997a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -305,7 +305,7 @@ if(DPKG_PROGRAM) Data files from the original game is required to run it.") SET(CPACK_DEBIAN_PACKAGE_NAME "openmw") SET(CPACK_DEBIAN_PACKAGE_VERSION "${VERSION_STRING}") - SET(CPACK_PACKAGE_EXECUTABLES "openmw;OpenMW esmtool;Esmtool omwlauncher;OMWLauncher") + SET(CPACK_PACKAGE_EXECUTABLES "openmw;OpenMW esmtool;Esmtool omwlauncher;OMWLauncher mwiniimporter;MWiniImporter") SET(CPACK_DEBIAN_PACKAGE_DEPENDS "nvidia-cg-toolkit (>= 2.1), libboost-filesystem1.46.1 (>= 1.46.1), libboost-program-options1.46.1 (>= 1.46.1), libboost-system1.46.1 (>= 1.46.1), libboost-thread1.46.1 (>= 1.46.1), libc6 (>= 2.11.2), libfreetype6 (>= 2.2.1), libgcc1 (>= 1:4.1.1), libmpg123-0 (>= 1.12.1), libois-1.3.0 (>= 1.3.0), libopenal1 (>= 1:1.12.854), libsndfile1 (>= 1.0.23), libstdc++6 (>= 4.4.5), libuuid1 (>= 2.17.2), libqtgui4 (>= 4.7.0)") SET(CPACK_DEBIAN_PACKAGE_SECTION "Games") @@ -391,6 +391,11 @@ if (BUILD_LAUNCHER) add_subdirectory( apps/launcher ) endif() +option(BUILD_MWINIIMPORTER "build MWiniImporter inspector" ON) +if (BUILD_MWINIIMPORTER) + add_subdirectory( apps/mwiniimporter ) +endif() + if (WIN32) if (MSVC) if (USE_DEBUG_CONSOLE) diff --git a/apps/mwiniimporter/CMakeLists.txt b/apps/mwiniimporter/CMakeLists.txt new file mode 100644 index 000000000..1d7b7b624 --- /dev/null +++ b/apps/mwiniimporter/CMakeLists.txt @@ -0,0 +1,21 @@ +set(MWINIIMPORT + main.cpp + importer.cpp +) + +set(MWINIIMPORT_HEADER + main.hpp + importer.hpp +) + +source_group(launcher FILES ${MWINIIMPORT} ${MWINIIMPORT_HEADER}) + +add_executable(mwiniimport + ${MWINIIMPORT} +) + +target_link_libraries(mwiniimport + ${Boost_LIBRARIES} + components +) + diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp new file mode 100644 index 000000000..225b1667c --- /dev/null +++ b/apps/mwiniimporter/importer.cpp @@ -0,0 +1,6 @@ +#include "importer.hpp" + +void MwIniImporter::test() { + +} + diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp new file mode 100644 index 000000000..026ed55bf --- /dev/null +++ b/apps/mwiniimporter/importer.hpp @@ -0,0 +1,17 @@ +#ifndef MWINIIMPORTER_IMPORTER +#define MWINIIMPORTER_IMPORTER 1 + +#include + +class MwIniImporter { + + public: + void test(); + + private: + + +}; + + +#endif diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp new file mode 100644 index 000000000..46cb37e7f --- /dev/null +++ b/apps/mwiniimporter/main.cpp @@ -0,0 +1,39 @@ +#include "main.hpp" +#include "importer.hpp" + +int main(int argc, char *argv[]) { + + bpo::options_description desc("Syntax: mwiniimporter \nAllowed options"); + desc.add_options() + ("help,h", "produce help message") + ("in,i", bpo::value()->required(), "morrowind.ini input file") + ("out,o", bpo::value()->required(), "openmw.cfg output file") + ; + + bpo::variables_map vm; + try { + bpo::store(boost::program_options::parse_command_line(argc, argv, desc), vm); + bpo::notify(vm); + + } + catch(std::exception& e) { + std::cout << "Error:" << e.what() << std::endl; + return -1; + } + catch(...) { + std::cout << "Error" << std::endl; + return -1; + } + + if(vm.count("help")) { + std::cout << desc; + return 0; + } + + std::cout << "in:" << vm["in"].as() << std::endl; + + MwIniImporter importer; + importer.test(); + + return 0; +} diff --git a/apps/mwiniimporter/main.hpp b/apps/mwiniimporter/main.hpp new file mode 100644 index 000000000..f93de7b07 --- /dev/null +++ b/apps/mwiniimporter/main.hpp @@ -0,0 +1,11 @@ +#ifndef MWINIIMPORTER_MAIN +#define MWINIIMPORTER_MAIN 1 + +#include +#include +#include + +namespace bpo = boost::program_options; + + +#endif From c160bc708091039cccdea53bc584704713193852 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Fri, 30 Mar 2012 22:58:54 +0200 Subject: [PATCH 02/12] works, sort of --- apps/mwiniimporter/CMakeLists.txt | 1 - apps/mwiniimporter/importer.cpp | 94 ++++++++++++++++++++++++++++++- apps/mwiniimporter/importer.hpp | 18 +++++- apps/mwiniimporter/main.cpp | 58 +++++++++++++++---- apps/mwiniimporter/main.hpp | 11 ---- 5 files changed, 155 insertions(+), 27 deletions(-) delete mode 100644 apps/mwiniimporter/main.hpp diff --git a/apps/mwiniimporter/CMakeLists.txt b/apps/mwiniimporter/CMakeLists.txt index 1d7b7b624..2a8c0f5fe 100644 --- a/apps/mwiniimporter/CMakeLists.txt +++ b/apps/mwiniimporter/CMakeLists.txt @@ -4,7 +4,6 @@ set(MWINIIMPORT ) set(MWINIIMPORT_HEADER - main.hpp importer.hpp ) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 225b1667c..d0cfe4a04 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -1,6 +1,96 @@ #include "importer.hpp" +#include +#include +#include -void MwIniImporter::test() { - +void MwIniImporter::setVerbose(bool verbose) { + mVerbose = verbose; } +strmap MwIniImporter::loadIniFile(std::string filename) { + std::cout << "load ini file: " << filename << std::endl; + + std::map map; + boost::iostreams::streamfile(filename.c_str()); + + std::string line; + while (std::getline(file, line)) { + + // ignore sections for now + if(line.empty() || line[0] == ';' || line[0] == '[') { + continue; + } + + int pos = line.find("="); + if(pos < 1) { + throw IniParseException(); + } + + map.insert(std::pair( + line.substr(0,pos), line.substr(pos+1) + )); + } + + return map; +} + +strmap MwIniImporter::loadCfgFile(std::string filename) { + std::cout << "load cfg file: " << filename << std::endl; + + std::map map; + boost::iostreams::streamfile(filename.c_str()); + + std::string 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 + int comment_pos = line.find("#"); + if(comment_pos > 0) { + line = line.substr(0,comment_pos); + } + + if(line.empty()) { + continue; + } + + int pos = line.find("="); + if(pos < 1) { + throw IniParseException(); + } + + map.insert(std::pair( + line.substr(0,pos), line.substr(pos+1) + )); + } + + return map; +} + +void MwIniImporter::merge(strmap &cfg, strmap &ini) { + strmap::iterator ini_it; + for(strmap::iterator it=cfg.begin(); it != cfg.end(); it++) { + ini_it = ini.find(it->first); + + // found a key in both files + if(ini_it != ini.end()) { + cfg.erase(it); + cfg.insert(std::pair( + ini_it->first, ini_it->second + )); + } + } +} + +void MwIniImporter::writeToFile(std::string file, strmap &cfg) { + boost::iostreams::stream out(file); + + for(strmap::iterator it=cfg.begin(); it != cfg.end(); it++) { + out << (it->first) << "=" << (it->second) << std::endl; + } +} + + diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index 026ed55bf..1933830f2 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -2,14 +2,28 @@ #define MWINIIMPORTER_IMPORTER 1 #include +#include +#include + +typedef std::map strmap; + +class IniParseException : public std::exception { + virtual const char* what() const throw() { + return "unexpected end of line"; + } +}; class MwIniImporter { public: - void test(); + void setVerbose(bool verbose); + strmap loadIniFile(std::string filename); + strmap loadCfgFile(std::string filename); + void merge(strmap &cfg, strmap &ini); + void writeToFile(std::string file, strmap &cfg); private: - + bool mVerbose; }; diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 46cb37e7f..fa7a5c512 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -1,39 +1,75 @@ -#include "main.hpp" #include "importer.hpp" +#include +#include +#include +#include + +namespace bpo = boost::program_options; + int main(int argc, char *argv[]) { bpo::options_description desc("Syntax: mwiniimporter \nAllowed options"); desc.add_options() ("help,h", "produce help message") - ("in,i", bpo::value()->required(), "morrowind.ini input file") - ("out,o", bpo::value()->required(), "openmw.cfg output file") + ("verbose,v", "verbose output") + ("ini,i", bpo::value()->required(), "morrowind.ini file") + ("cfg,c", bpo::value()->required(), "openmw.cfg file") + ("output,o", bpo::value()->default_value(""), "openmw.cfg file") ; bpo::variables_map vm; try { bpo::store(boost::program_options::parse_command_line(argc, argv, desc), vm); + + // parse help before calling notify because we dont want it to throw an error if help is set + if(vm.count("help")) { + std::cout << desc; + return 0; + } + bpo::notify(vm); } catch(std::exception& e) { - std::cout << "Error:" << e.what() << std::endl; + std::cerr << "Error:" << e.what() << std::endl; return -1; } catch(...) { - std::cout << "Error" << std::endl; - return -1; + std::cerr << "Error" << std::endl; + return -2; } - if(vm.count("help")) { - std::cout << desc; - return 0; + std::string iniFile = vm["ini"].as(); + std::string cfgFile = vm["cfg"].as(); + + // if no output is given, write back to cfg file + std::string outputFile(vm["output"].as()); + if(vm["output"].defaulted()) { + outputFile = vm["cfg"].as(); } - std::cout << "in:" << vm["in"].as() << std::endl; + if(!boost::filesystem::exists(iniFile)) { + std::cerr << "ini file does not exist" << std::endl; + return -3; + } + if(!boost::filesystem::exists(cfgFile)) { + std::cerr << "cfg file does not exist" << std::endl; + return -4; + } MwIniImporter importer; - importer.test(); + importer.setVerbose(vm.count("verbose")); + + std::mapini = importer.loadIniFile(iniFile); + std::mapcfg = importer.loadCfgFile(cfgFile); + + importer.merge(cfg, ini); + + std::cout << "write to: " << outputFile << std::endl; + importer.writeToFile(outputFile, cfg); return 0; } + + diff --git a/apps/mwiniimporter/main.hpp b/apps/mwiniimporter/main.hpp deleted file mode 100644 index f93de7b07..000000000 --- a/apps/mwiniimporter/main.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef MWINIIMPORTER_MAIN -#define MWINIIMPORTER_MAIN 1 - -#include -#include -#include - -namespace bpo = boost::program_options; - - -#endif From 849c3a9bececfdeba8495f09dc057f62236027e8 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Fri, 30 Mar 2012 23:12:52 +0200 Subject: [PATCH 03/12] add the section to the ini-keys --- apps/mwiniimporter/importer.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index d0cfe4a04..f662f42d6 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -10,6 +10,7 @@ void MwIniImporter::setVerbose(bool verbose) { strmap MwIniImporter::loadIniFile(std::string filename) { std::cout << "load ini file: " << filename << std::endl; + std::string section(""); std::map map; boost::iostreams::streamfile(filename.c_str()); @@ -17,17 +18,25 @@ strmap MwIniImporter::loadIniFile(std::string filename) { while (std::getline(file, line)) { // ignore sections for now - if(line.empty() || line[0] == ';' || line[0] == '[') { + if(line.empty() || line[0] == ';') { continue; } + if(line[0] == '[') { + if(line.length() > 2) { + section = line.substr(1, line.length()-3); + continue; + } + throw IniParseException(); + } + int pos = line.find("="); if(pos < 1) { throw IniParseException(); } map.insert(std::pair( - line.substr(0,pos), line.substr(pos+1) + section + " " + line.substr(0,pos), line.substr(pos+1) )); } From 6eb3281c4c504dfc2d6398156ee5c449772325c8 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 31 Mar 2012 11:36:51 +0200 Subject: [PATCH 04/12] boost fix --- apps/mwiniimporter/main.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index fa7a5c512..059703ea8 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -13,23 +13,23 @@ int main(int argc, char *argv[]) { desc.add_options() ("help,h", "produce help message") ("verbose,v", "verbose output") - ("ini,i", bpo::value()->required(), "morrowind.ini file") - ("cfg,c", bpo::value()->required(), "openmw.cfg file") + ("ini,i", bpo::value(), "morrowind.ini file") + ("cfg,c", bpo::value(), "openmw.cfg file") ("output,o", bpo::value()->default_value(""), "openmw.cfg file") ; - + bpo::variables_map vm; try { bpo::store(boost::program_options::parse_command_line(argc, argv, desc), vm); - + // parse help before calling notify because we dont want it to throw an error if help is set if(vm.count("help")) { std::cout << desc; return 0; } - + bpo::notify(vm); - + } catch(std::exception& e) { std::cerr << "Error:" << e.what() << std::endl; @@ -39,16 +39,16 @@ int main(int argc, char *argv[]) { std::cerr << "Error" << std::endl; return -2; } - + std::string iniFile = vm["ini"].as(); std::string cfgFile = vm["cfg"].as(); - + // if no output is given, write back to cfg file std::string outputFile(vm["output"].as()); if(vm["output"].defaulted()) { outputFile = vm["cfg"].as(); } - + if(!boost::filesystem::exists(iniFile)) { std::cerr << "ini file does not exist" << std::endl; return -3; @@ -57,19 +57,17 @@ int main(int argc, char *argv[]) { std::cerr << "cfg file does not exist" << std::endl; return -4; } - + MwIniImporter importer; importer.setVerbose(vm.count("verbose")); - + std::mapini = importer.loadIniFile(iniFile); std::mapcfg = importer.loadCfgFile(cfgFile); - + importer.merge(cfg, ini); - + std::cout << "write to: " << outputFile << std::endl; importer.writeToFile(outputFile, cfg); - + return 0; } - - From e35670c6cba25e055b6cda9dc2e3ad2ae005997d Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 31 Mar 2012 14:28:19 +0200 Subject: [PATCH 05/12] ignore syntax errors and empty lines; fixed merge function --- apps/mwiniimporter/importer.cpp | 37 +++++++++++++++------------------ apps/mwiniimporter/importer.hpp | 14 ++++++------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index f662f42d6..9a76adeed 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -25,19 +25,16 @@ strmap MwIniImporter::loadIniFile(std::string filename) { if(line[0] == '[') { if(line.length() > 2) { section = line.substr(1, line.length()-3); - continue; } - throw IniParseException(); + continue; } int pos = line.find("="); if(pos < 1) { - throw IniParseException(); + continue; } - map.insert(std::pair( - section + " " + line.substr(0,pos), line.substr(pos+1) - )); + map.insert(STRPAIR(section + ":" + line.substr(0,pos), line.substr(pos+1))); } return map; @@ -68,32 +65,32 @@ strmap MwIniImporter::loadCfgFile(std::string filename) { int pos = line.find("="); if(pos < 1) { - throw IniParseException(); + continue; } - map.insert(std::pair( - line.substr(0,pos), line.substr(pos+1) - )); + map.insert(STRPAIR(line.substr(0,pos), line.substr(pos+1))); } return map; } void MwIniImporter::merge(strmap &cfg, strmap &ini) { - strmap::iterator ini_it; - for(strmap::iterator it=cfg.begin(); it != cfg.end(); it++) { - ini_it = ini.find(it->first); - - // found a key in both files - if(ini_it != ini.end()) { - cfg.erase(it); - cfg.insert(std::pair( - ini_it->first, ini_it->second - )); + strmap::iterator cfgIt; + strmap::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(STRPAIR(it->first, iniIt->second)); + } } } } +bool MwIniImporter::specialMerge(std::string cfgKey, std::string iniKey, strmap cfg, strmap ini) { + return false; +} + void MwIniImporter::writeToFile(std::string file, strmap &cfg) { boost::iostreams::stream out(file); diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index 1933830f2..3ab1d892e 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -5,17 +5,16 @@ #include #include -typedef std::map strmap; -class IniParseException : public std::exception { - virtual const char* what() const throw() { - return "unexpected end of line"; - } -}; +typedef std::map strmap; +#define STRPAIR std::make_pair class MwIniImporter { public: + MwIniImporter() { + mMergeMap.insert(STRPAIR("fps", "General:Show FPS")); + }; void setVerbose(bool verbose); strmap loadIniFile(std::string filename); strmap loadCfgFile(std::string filename); @@ -23,8 +22,9 @@ class MwIniImporter { void writeToFile(std::string file, strmap &cfg); private: + bool specialMerge(std::string cfgKey, std::string iniKey, strmap cfg, strmap ini); bool mVerbose; - + strmap mMergeMap; }; From b7635b3d4a12bacf31a0c4d7aad92bfaacd2b711 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 31 Mar 2012 14:34:00 +0200 Subject: [PATCH 06/12] pass maps by reference --- apps/mwiniimporter/importer.cpp | 2 +- apps/mwiniimporter/importer.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 9a76adeed..041712b21 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -87,7 +87,7 @@ void MwIniImporter::merge(strmap &cfg, strmap &ini) { } } -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; } diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index 3ab1d892e..d0034a13d 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -22,7 +22,7 @@ class MwIniImporter { void writeToFile(std::string file, strmap &cfg); 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); bool mVerbose; strmap mMergeMap; }; From ceedae4a1af3c155f31221376ac9ef66c3e9dca8 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 31 Mar 2012 16:54:53 +0200 Subject: [PATCH 07/12] technical corrections --- apps/mwiniimporter/importer.cpp | 18 +++++++++++++++--- apps/mwiniimporter/importer.hpp | 5 +---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 041712b21..09088774b 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -3,6 +3,18 @@ #include #include +MwIniImporter::MwIniImporter() { + const char *map[][2] = + { + { "fps", "General:Show FPS" }, + { 0, 0 } + }; + + for(int i=0; map[i][0]; i++) { + mMergeMap.insert(std::make_pair(map[i][0], map[i][1])); + } +} + void MwIniImporter::setVerbose(bool verbose) { mVerbose = verbose; } @@ -34,7 +46,7 @@ strmap MwIniImporter::loadIniFile(std::string filename) { continue; } - map.insert(STRPAIR(section + ":" + line.substr(0,pos), line.substr(pos+1))); + map.insert(std::make_pair(section + ":" + line.substr(0,pos), line.substr(pos+1))); } return map; @@ -68,7 +80,7 @@ strmap MwIniImporter::loadCfgFile(std::string filename) { continue; } - map.insert(STRPAIR(line.substr(0,pos), line.substr(pos+1))); + map.insert(std::make_pair(line.substr(0,pos), line.substr(pos+1))); } return map; @@ -81,7 +93,7 @@ void MwIniImporter::merge(strmap &cfg, strmap &ini) { if((iniIt = ini.find(it->second)) != ini.end()) { cfg.erase(it->first); if(!this->specialMerge(it->first, it->second, cfg, ini)) { - cfg.insert(STRPAIR(it->first, iniIt->second)); + cfg.insert(std::make_pair(it->first, iniIt->second)); } } } diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index d0034a13d..ad5aaacde 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -7,14 +7,11 @@ typedef std::map strmap; -#define STRPAIR std::make_pair class MwIniImporter { public: - MwIniImporter() { - mMergeMap.insert(STRPAIR("fps", "General:Show FPS")); - }; + MwIniImporter(); void setVerbose(bool verbose); strmap loadIniFile(std::string filename); strmap loadCfgFile(std::string filename); From 653fbdd10cf83a3d361b7017b6e491d6df7aa67a Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 31 Mar 2012 18:24:43 +0200 Subject: [PATCH 08/12] 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); From 092de45924ec2c263049e9fe46757892fb93c039 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 31 Mar 2012 18:28:48 +0200 Subject: [PATCH 09/12] std::map to std::multimap --- apps/mwiniimporter/importer.cpp | 4 ++-- apps/mwiniimporter/importer.hpp | 2 +- apps/mwiniimporter/main.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 7532bf1da..a92eee725 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -26,7 +26,7 @@ strmap MwIniImporter::loadIniFile(std::string filename) { std::cout << "load ini file: " << filename << std::endl; std::string section(""); - std::map map; + std::multimap map; boost::iostreams::streamfile(filename.c_str()); std::string line; @@ -58,7 +58,7 @@ strmap MwIniImporter::loadIniFile(std::string filename) { strmap MwIniImporter::loadCfgFile(std::string filename) { std::cout << "load cfg file: " << filename << std::endl; - std::map map; + std::multimap map; boost::iostreams::streamfile(filename.c_str()); std::string line; diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index 13cb02ee6..3c85fd25a 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -6,7 +6,7 @@ #include -typedef std::map strmap; +typedef std::multimap strmap; class MwIniImporter { diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 87225432d..5eba95961 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -62,8 +62,8 @@ int main(int argc, char *argv[]) { MwIniImporter importer; importer.setVerbose(vm.count("verbose")); - std::mapini = importer.loadIniFile(iniFile); - std::mapcfg = importer.loadCfgFile(cfgFile); + std::multimapini = importer.loadIniFile(iniFile); + std::multimapcfg = importer.loadCfgFile(cfgFile); importer.merge(cfg, ini); From 6d875dfd54105505c62f831717632e6c9eeaad12 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 31 Mar 2012 21:06:48 +0200 Subject: [PATCH 10/12] handle master/plugin properly --- apps/mwiniimporter/importer.cpp | 120 ++++++++++++++------------------ apps/mwiniimporter/importer.hpp | 10 ++- apps/mwiniimporter/main.cpp | 14 ++-- 3 files changed, 69 insertions(+), 75 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index a92eee725..937073632 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include MwIniImporter::MwIniImporter() { const char *map[][2] = @@ -26,17 +27,12 @@ strmap MwIniImporter::loadIniFile(std::string filename) { std::cout << "load ini file: " << filename << std::endl; std::string section(""); - std::multimap map; + std::map map; boost::iostreams::streamfile(filename.c_str()); std::string line; while (std::getline(file, line)) { - // ignore sections for now - if(line.empty() || line[0] == ';') { - continue; - } - if(line[0] == '[') { if(line.length() > 2) { section = line.substr(1, line.length()-3); @@ -44,6 +40,15 @@ strmap MwIniImporter::loadIniFile(std::string filename) { continue; } + int comment_pos = line.find(";"); + if(comment_pos > 0) { + line = line.substr(0,comment_pos); + } + + if(line.empty()) { + continue; + } + int pos = line.find("="); if(pos < 1) { continue; @@ -58,16 +63,12 @@ strmap MwIniImporter::loadIniFile(std::string filename) { strmap MwIniImporter::loadCfgFile(std::string filename) { std::cout << "load cfg file: " << filename << std::endl; - std::multimap map; + std::map map; boost::iostreams::streamfile(filename.c_str()); std::string 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 int comment_pos = line.find("#"); if(comment_pos > 0) { @@ -102,67 +103,50 @@ 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; } -void MwIniImporter::writeToFile(std::string file, strmap &cfg) { - boost::iostreams::stream out(file); +void MwIniImporter::importGameFiles(strmap &cfg, strmap &ini, std::vector &esmFiles, std::vector &espFiles) { + 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 &out, std::vector &esmFiles, std::vector &espFiles) { + for(std::vector::iterator it=esmFiles.begin(); it != esmFiles.end(); it++) { + out << "master=" << *it << std::endl; + } + for(std::vector::iterator it=espFiles.begin(); it != espFiles.end(); it++) { + out << "plugin=" << *it << std::endl; + } +} + +void MwIniImporter::writeToFile(boost::iostreams::stream &out, strmap &cfg) { + cfg.erase("master"); + cfg.erase("plugin"); for(strmap::iterator it=cfg.begin(); it != cfg.end(); it++) { out << (it->first) << "=" << (it->second) << std::endl; diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index 3c85fd25a..d7250f5e2 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -1,12 +1,15 @@ #ifndef MWINIIMPORTER_IMPORTER #define MWINIIMPORTER_IMPORTER 1 +#include +#include #include #include +#include #include -typedef std::multimap strmap; +typedef std::map strmap; class MwIniImporter { @@ -16,8 +19,9 @@ 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); + void importGameFiles(strmap &cfg, strmap &ini, std::vector &esmFiles, std::vector &espFiles); + void writeGameFiles(boost::iostreams::stream &out, std::vector &esmFiles, std::vector &espFiles); + void writeToFile(boost::iostreams::stream &out, strmap &cfg); private: bool specialMerge(std::string cfgKey, std::string iniKey, strmap &cfg, strmap &ini); diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 5eba95961..7426e71ea 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -58,21 +58,27 @@ int main(int argc, char *argv[]) { std::cerr << "cfg file does not exist" << std::endl; return -4; } + MwIniImporter importer; importer.setVerbose(vm.count("verbose")); + boost::iostreams::stream file(outputFile); - std::multimapini = importer.loadIniFile(iniFile); - std::multimapcfg = importer.loadCfgFile(cfgFile); + std::mapini = importer.loadIniFile(iniFile); + std::mapcfg = importer.loadCfgFile(cfgFile); importer.merge(cfg, ini); if(vm.count("game-files")) { - importer.importGameFiles(cfg, ini); + std::vector esmFiles; + std::vector espFiles; + + importer.importGameFiles(cfg, ini, esmFiles, espFiles); + importer.writeGameFiles(file, esmFiles, espFiles); } std::cout << "write to: " << outputFile << std::endl; - importer.writeToFile(outputFile, cfg); + importer.writeToFile(file, cfg); return 0; } From 1d596d6c722ac579e527b785ff6b393d8375f3b6 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 31 Mar 2012 22:48:50 +0200 Subject: [PATCH 11/12] use std::map > instead of std::map --- apps/mwiniimporter/importer.cpp | 103 ++++++++++++++++++++------------ apps/mwiniimporter/importer.hpp | 20 +++---- apps/mwiniimporter/main.cpp | 11 +--- 3 files changed, 78 insertions(+), 56 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 937073632..f7ddb2bf0 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -23,11 +23,11 @@ void MwIniImporter::setVerbose(bool verbose) { mVerbose = verbose; } -strmap MwIniImporter::loadIniFile(std::string filename) { +MwIniImporter::multistrmap MwIniImporter::loadIniFile(std::string filename) { std::cout << "load ini file: " << filename << std::endl; std::string section(""); - std::map map; + MwIniImporter::multistrmap map; boost::iostreams::streamfile(filename.c_str()); std::string line; @@ -54,16 +54,23 @@ strmap MwIniImporter::loadIniFile(std::string filename) { continue; } - map.insert(std::make_pair(section + ":" + line.substr(0,pos), line.substr(pos+1))); + std::string key(section + ":" + line.substr(0,pos)); + std::string value(line.substr(pos+1)); + + multistrmap::iterator it; + if((it = map.find(key)) == map.end()) { + map.insert( std::make_pair > (key, std::vector() ) ); + } + map[key].push_back(value); } return map; } -strmap MwIniImporter::loadCfgFile(std::string filename) { +MwIniImporter::multistrmap MwIniImporter::loadCfgFile(std::string filename) { std::cout << "load cfg file: " << filename << std::endl; - std::map map; + MwIniImporter::multistrmap map; boost::iostreams::streamfile(filename.c_str()); std::string line; @@ -84,34 +91,43 @@ strmap MwIniImporter::loadCfgFile(std::string filename) { continue; } - map.insert(std::make_pair(line.substr(0,pos), line.substr(pos+1))); + std::string key(line.substr(0,pos)); + std::string value(line.substr(pos+1)); + + multistrmap::iterator it; + if((it = map.find(key)) == map.end()) { + map.insert( std::make_pair > (key, std::vector() ) ); + } + map[key].push_back(value); } return map; } -void MwIniImporter::merge(strmap &cfg, strmap &ini) { - strmap::iterator cfgIt; - strmap::iterator iniIt; +void MwIniImporter::merge(multistrmap &cfg, multistrmap &ini) { + multistrmap::iterator cfgIt; + 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)); + cfg.insert(std::make_pair >(it->first, iniIt->second)); } } } } -bool MwIniImporter::specialMerge(std::string cfgKey, std::string iniKey, strmap &cfg, strmap &ini) { +bool MwIniImporter::specialMerge(std::string cfgKey, std::string iniKey, multistrmap &cfg, multistrmap &ini) { return false; } -void MwIniImporter::importGameFiles(strmap &cfg, strmap &ini, std::vector &esmFiles, std::vector &espFiles) { +void MwIniImporter::importGameFiles(multistrmap &cfg, multistrmap &ini) { + std::vector esmFiles; + std::vector espFiles; std::string baseGameFile("Game Files:GameFile"); std::string gameFile(""); - strmap::iterator it = ini.begin(); + multistrmap::iterator it = ini.begin(); for(int i=0; it != ini.end(); i++) { gameFile = baseGameFile; gameFile.append(1,i+'0'); @@ -121,35 +137,48 @@ void MwIniImporter::importGameFiles(strmap &cfg, strmap &ini, std::vectorsecond.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); + for(std::vector::iterator entry = it->second.begin(); entry!=it->second.end(); entry++) { + std::string filetype(entry->substr(entry->length()-4, 3)); + std::transform(filetype.begin(), filetype.end(), filetype.begin(), ::tolower); + + if(filetype.compare("esm") == 0) { + esmFiles.push_back(*entry); + } + else if(filetype.compare("esp") == 0) { + espFiles.push_back(*entry); + } } gameFile = ""; } -} - -void MwIniImporter::writeGameFiles(boost::iostreams::stream &out, std::vector &esmFiles, std::vector &espFiles) { - for(std::vector::iterator it=esmFiles.begin(); it != esmFiles.end(); it++) { - out << "master=" << *it << std::endl; - } - for(std::vector::iterator it=espFiles.begin(); it != espFiles.end(); it++) { - out << "plugin=" << *it << std::endl; - } -} - -void MwIniImporter::writeToFile(boost::iostreams::stream &out, strmap &cfg) { - cfg.erase("master"); - cfg.erase("plugin"); - for(strmap::iterator it=cfg.begin(); it != cfg.end(); it++) { - out << (it->first) << "=" << (it->second) << std::endl; + if(!esmFiles.empty()) { + multistrmap::iterator it; + cfg.erase("master"); + cfg.insert( std::make_pair > ("master", std::vector() ) ); + + for(std::vector::iterator it=esmFiles.begin(); it!=esmFiles.end(); it++) { + cfg["master"].push_back(*it); + } + } + + if(!espFiles.empty()) { + multistrmap::iterator it; + cfg.erase("plugin"); + cfg.insert( std::make_pair > ("plugin", std::vector() ) ); + + for(std::vector::iterator it=espFiles.begin(); it!=espFiles.end(); it++) { + cfg["plugin"].push_back(*it); + } + } +} + +void MwIniImporter::writeToFile(boost::iostreams::stream &out, multistrmap &cfg) { + + for(multistrmap::iterator it=cfg.begin(); it != cfg.end(); it++) { + for(std::vector::iterator entry=it->second.begin(); entry != it->second.end(); entry++) { + out << (it->first) << "=" << (*entry) << std::endl; + } } } diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index d7250f5e2..454dc209a 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -8,23 +8,21 @@ #include #include - -typedef std::map strmap; - class MwIniImporter { - public: + typedef std::map strmap; + typedef std::map > multistrmap; + MwIniImporter(); void setVerbose(bool verbose); - strmap loadIniFile(std::string filename); - strmap loadCfgFile(std::string filename); - void merge(strmap &cfg, strmap &ini); - void importGameFiles(strmap &cfg, strmap &ini, std::vector &esmFiles, std::vector &espFiles); - void writeGameFiles(boost::iostreams::stream &out, std::vector &esmFiles, std::vector &espFiles); - void writeToFile(boost::iostreams::stream &out, strmap &cfg); + multistrmap loadIniFile(std::string filename); + multistrmap loadCfgFile(std::string filename); + void merge(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, strmap &cfg, strmap &ini); + bool specialMerge(std::string cfgKey, std::string iniKey, multistrmap &cfg, multistrmap &ini); bool mVerbose; strmap mMergeMap; }; diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 7426e71ea..9a6e61645 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -59,22 +59,17 @@ int main(int argc, char *argv[]) { return -4; } - MwIniImporter importer; importer.setVerbose(vm.count("verbose")); boost::iostreams::stream file(outputFile); - std::mapini = importer.loadIniFile(iniFile); - std::mapcfg = importer.loadCfgFile(cfgFile); + MwIniImporter::multistrmap ini = importer.loadIniFile(iniFile); + MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile); importer.merge(cfg, ini); if(vm.count("game-files")) { - std::vector esmFiles; - std::vector espFiles; - - importer.importGameFiles(cfg, ini, esmFiles, espFiles); - importer.writeGameFiles(file, esmFiles, espFiles); + importer.importGameFiles(cfg, ini); } std::cout << "write to: " << outputFile << std::endl; From a2a7539fd55b2a4480c36575f0814d4180215146 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 31 Mar 2012 23:15:33 +0200 Subject: [PATCH 12/12] fix for more than 10 game files; delete both master and plugin settings if called with --game-files --- apps/mwiniimporter/importer.cpp | 36 +++++++++++++++++---------------- apps/mwiniimporter/importer.hpp | 1 + 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index f7ddb2bf0..a82240a8a 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -6,6 +6,7 @@ #include #include #include +#include MwIniImporter::MwIniImporter() { const char *map[][2] = @@ -23,6 +24,12 @@ void MwIniImporter::setVerbose(bool verbose) { mVerbose = verbose; } +std::string MwIniImporter::numberToString(int n) { + std::stringstream str; + str << n; + return str.str(); +} + MwIniImporter::multistrmap MwIniImporter::loadIniFile(std::string filename) { std::cout << "load ini file: " << filename << std::endl; @@ -130,7 +137,7 @@ void MwIniImporter::importGameFiles(multistrmap &cfg, multistrmap &ini) { multistrmap::iterator it = ini.begin(); for(int i=0; it != ini.end(); i++) { gameFile = baseGameFile; - gameFile.append(1,i+'0'); + gameFile.append(this->numberToString(i)); it = ini.find(gameFile); if(it == ini.end()) { @@ -152,24 +159,19 @@ void MwIniImporter::importGameFiles(multistrmap &cfg, multistrmap &ini) { gameFile = ""; } - if(!esmFiles.empty()) { - multistrmap::iterator it; - cfg.erase("master"); - cfg.insert( std::make_pair > ("master", std::vector() ) ); - - for(std::vector::iterator it=esmFiles.begin(); it!=esmFiles.end(); it++) { - cfg["master"].push_back(*it); - } + multistrmap::iterator it; + cfg.erase("master"); + cfg.insert( std::make_pair > ("master", std::vector() ) ); + + for(std::vector::iterator it=esmFiles.begin(); it!=esmFiles.end(); it++) { + cfg["master"].push_back(*it); } - if(!espFiles.empty()) { - multistrmap::iterator it; - cfg.erase("plugin"); - cfg.insert( std::make_pair > ("plugin", std::vector() ) ); - - for(std::vector::iterator it=espFiles.begin(); it!=espFiles.end(); it++) { - cfg["plugin"].push_back(*it); - } + cfg.erase("plugin"); + cfg.insert( std::make_pair > ("plugin", std::vector() ) ); + + for(std::vector::iterator it=espFiles.begin(); it!=espFiles.end(); it++) { + cfg["plugin"].push_back(*it); } } diff --git a/apps/mwiniimporter/importer.hpp b/apps/mwiniimporter/importer.hpp index 454dc209a..988f10255 100644 --- a/apps/mwiniimporter/importer.hpp +++ b/apps/mwiniimporter/importer.hpp @@ -23,6 +23,7 @@ class MwIniImporter { private: bool specialMerge(std::string cfgKey, std::string iniKey, multistrmap &cfg, multistrmap &ini); + std::string numberToString(int n); bool mVerbose; strmap mMergeMap; };