1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

76 lines
2.2 KiB
C++
Raw Normal View History

2012-03-30 20:59:44 +02:00
#include "importer.hpp"
2012-03-30 22:58:54 +02:00
#include <iostream>
#include <string>
#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>
namespace bpo = boost::program_options;
2012-03-30 20:59:44 +02:00
int main(int argc, char *argv[]) {
bpo::options_description desc("Syntax: mwiniimporter <options>\nAllowed options");
desc.add_options()
("help,h", "produce help message")
2012-03-30 22:58:54 +02:00
("verbose,v", "verbose output")
("ini,i", bpo::value<std::string>()->required(), "morrowind.ini file")
("cfg,c", bpo::value<std::string>()->required(), "openmw.cfg file")
("output,o", bpo::value<std::string>()->default_value(""), "openmw.cfg file")
2012-03-30 20:59:44 +02:00
;
bpo::variables_map vm;
try {
bpo::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
2012-03-30 22:58:54 +02:00
// 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;
}
2012-03-30 20:59:44 +02:00
bpo::notify(vm);
}
catch(std::exception& e) {
2012-03-30 22:58:54 +02:00
std::cerr << "Error:" << e.what() << std::endl;
2012-03-30 20:59:44 +02:00
return -1;
}
catch(...) {
2012-03-30 22:58:54 +02:00
std::cerr << "Error" << std::endl;
return -2;
2012-03-30 20:59:44 +02:00
}
2012-03-30 22:58:54 +02:00
std::string iniFile = vm["ini"].as<std::string>();
std::string cfgFile = vm["cfg"].as<std::string>();
// if no output is given, write back to cfg file
std::string outputFile(vm["output"].as<std::string>());
if(vm["output"].defaulted()) {
outputFile = vm["cfg"].as<std::string>();
2012-03-30 20:59:44 +02:00
}
2012-03-30 22:58:54 +02:00
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;
}
2012-03-30 20:59:44 +02:00
MwIniImporter importer;
2012-03-30 22:58:54 +02:00
importer.setVerbose(vm.count("verbose"));
std::map<std::string, std::string>ini = importer.loadIniFile(iniFile);
std::map<std::string, std::string>cfg = importer.loadCfgFile(cfgFile);
importer.merge(cfg, ini);
std::cout << "write to: " << outputFile << std::endl;
importer.writeToFile(outputFile, cfg);
2012-03-30 20:59:44 +02:00
return 0;
}
2012-03-30 22:58:54 +02:00