You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/apps/mwiniimporter/main.cpp

85 lines
2.5 KiB
C++

13 years ago
#include "importer.hpp"
13 years ago
#include <iostream>
#include <string>
#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>
namespace bpo = boost::program_options;
13 years ago
int main(int argc, char *argv[]) {
bpo::options_description desc("Syntax: mwiniimporter <options>\nAllowed options");
desc.add_options()
("help,h", "produce help message")
13 years ago
("verbose,v", "verbose output")
13 years ago
("ini,i", bpo::value<std::string>(), "morrowind.ini file")
("cfg,c", bpo::value<std::string>(), "openmw.cfg file")
13 years ago
("output,o", bpo::value<std::string>()->default_value(""), "openmw.cfg file")
("game-files,g", "import esm and esp files")
13 years ago
;
13 years ago
13 years ago
bpo::variables_map vm;
try {
bpo::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
13 years ago
13 years ago
// 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;
}
13 years ago
13 years ago
bpo::notify(vm);
13 years ago
13 years ago
}
catch(std::exception& e) {
13 years ago
std::cerr << "Error:" << e.what() << std::endl;
13 years ago
return -1;
}
catch(...) {
13 years ago
std::cerr << "Error" << std::endl;
return -2;
13 years ago
}
13 years ago
13 years ago
std::string iniFile = vm["ini"].as<std::string>();
std::string cfgFile = vm["cfg"].as<std::string>();
13 years ago
13 years ago
// 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>();
13 years ago
}
13 years ago
13 years ago
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;
}
13 years ago
13 years ago
MwIniImporter importer;
13 years ago
importer.setVerbose(vm.count("verbose"));
boost::iostreams::stream<boost::iostreams::file_sink> file(outputFile);
13 years ago
std::map<std::string, std::string>ini = importer.loadIniFile(iniFile);
std::map<std::string, std::string>cfg = importer.loadCfgFile(cfgFile);
13 years ago
13 years ago
importer.merge(cfg, ini);
if(vm.count("game-files")) {
std::vector<std::string> esmFiles;
std::vector<std::string> espFiles;
importer.importGameFiles(cfg, ini, esmFiles, espFiles);
importer.writeGameFiles(file, esmFiles, espFiles);
}
13 years ago
13 years ago
std::cout << "write to: " << outputFile << std::endl;
importer.writeToFile(file, cfg);
13 years ago
13 years ago
return 0;
}