2015-01-20 22:59:11 +00:00
|
|
|
#include <iostream>
|
2022-05-23 19:36:53 +00:00
|
|
|
#include <filesystem>
|
2015-01-20 22:59:11 +00:00
|
|
|
|
2015-01-16 23:11:36 +00:00
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
|
2015-01-30 14:11:27 +00:00
|
|
|
#include <components/files/configurationmanager.hpp>
|
|
|
|
|
2015-01-16 23:11:36 +00:00
|
|
|
#include "importer.hpp"
|
|
|
|
|
|
|
|
namespace bpo = boost::program_options;
|
|
|
|
|
|
|
|
|
2015-01-22 18:04:59 +00:00
|
|
|
int main(int argc, char** argv)
|
2015-01-16 23:11:36 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
bpo::options_description desc("Syntax: openmw-essimporter <options> infile.ess outfile.omwsave\nAllowed options");
|
|
|
|
bpo::positional_options_description p_desc;
|
|
|
|
desc.add_options()
|
|
|
|
("help,h", "produce help message")
|
2022-08-06 16:09:50 +00:00
|
|
|
("mwsave,m", bpo::value<Files::MaybeQuotedPath>(), "morrowind .ess save file")
|
|
|
|
("output,o", bpo::value<Files::MaybeQuotedPath>(), "output file (.omwsave)")
|
2015-01-16 23:11:36 +00:00
|
|
|
("compare,c", "compare two .ess files")
|
2015-01-30 14:11:27 +00:00
|
|
|
("encoding", boost::program_options::value<std::string>()->default_value("win1252"), "encoding of the save file")
|
2015-01-16 23:11:36 +00:00
|
|
|
;
|
|
|
|
p_desc.add("mwsave", 1).add("output", 1);
|
2022-01-13 22:10:09 +00:00
|
|
|
Files::ConfigurationManager::addCommonOptions(desc);
|
2015-01-16 23:11:36 +00:00
|
|
|
|
2015-01-30 14:11:27 +00:00
|
|
|
bpo::variables_map variables;
|
2015-01-16 23:11:36 +00:00
|
|
|
|
|
|
|
bpo::parsed_options parsed = bpo::command_line_parser(argc, argv)
|
|
|
|
.options(desc)
|
|
|
|
.positional(p_desc)
|
|
|
|
.run();
|
|
|
|
|
2015-01-30 14:11:27 +00:00
|
|
|
bpo::store(parsed, variables);
|
2015-01-16 23:11:36 +00:00
|
|
|
|
2015-01-30 14:11:27 +00:00
|
|
|
if(variables.count("help") || !variables.count("mwsave") || !variables.count("output")) {
|
2015-01-16 23:11:36 +00:00
|
|
|
std::cout << desc;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-30 14:11:27 +00:00
|
|
|
bpo::notify(variables);
|
|
|
|
|
2015-01-30 21:11:26 +00:00
|
|
|
Files::ConfigurationManager cfgManager(true);
|
2015-01-30 14:11:27 +00:00
|
|
|
cfgManager.readConfiguration(variables, desc);
|
2015-01-16 23:11:36 +00:00
|
|
|
|
2022-08-06 16:09:50 +00:00
|
|
|
const auto essFile = variables["mwsave"].as<Files::MaybeQuotedPath>();
|
|
|
|
const auto outputFile = variables["output"].as<Files::MaybeQuotedPath>();
|
2015-01-30 14:11:27 +00:00
|
|
|
std::string encoding = variables["encoding"].as<std::string>();
|
2015-01-16 23:11:36 +00:00
|
|
|
|
2015-01-30 14:11:27 +00:00
|
|
|
ESSImport::Importer importer(essFile, outputFile, encoding);
|
2015-01-16 23:11:36 +00:00
|
|
|
|
2015-01-30 14:11:27 +00:00
|
|
|
if (variables.count("compare"))
|
2015-01-16 23:11:36 +00:00
|
|
|
importer.compare();
|
|
|
|
else
|
2015-01-22 22:28:31 +00:00
|
|
|
{
|
2022-08-06 16:09:50 +00:00
|
|
|
static constexpr std::u8string_view ext{u8".omwsave"};
|
|
|
|
const auto length = outputFile.native().size();
|
|
|
|
if (std::filesystem::exists(outputFile)
|
|
|
|
&& (length < ext.size() || outputFile.u8string().substr(length-ext.size()) != ext))
|
2015-01-22 22:28:31 +00:00
|
|
|
{
|
|
|
|
throw std::runtime_error("Output file already exists and does not end in .omwsave. Did you mean to use --compare?");
|
|
|
|
}
|
2015-01-16 23:11:36 +00:00
|
|
|
importer.run();
|
2015-01-22 22:28:31 +00:00
|
|
|
}
|
2015-01-16 23:11:36 +00:00
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
|
|
|
std::cerr << "Error: " << e.what() << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|