From 081c8c86157ac0ed0cef5c35cb51c52240e94978 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 30 Jan 2015 15:11:27 +0100 Subject: [PATCH] ESSImport: convert to utf8, based on encoding setting in openmw.cfg --- apps/essimporter/importer.cpp | 9 ++++++--- apps/essimporter/importer.hpp | 3 ++- apps/essimporter/main.cpp | 23 +++++++++++++++-------- components/esm/cellref.cpp | 2 +- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/apps/essimporter/importer.cpp b/apps/essimporter/importer.cpp index 8f6563dee..bd994cf48 100644 --- a/apps/essimporter/importer.cpp +++ b/apps/essimporter/importer.cpp @@ -21,6 +21,8 @@ #include #include +#include + #include "importercontext.hpp" #include "converter.hpp" @@ -44,9 +46,10 @@ namespace namespace ESSImport { - Importer::Importer(const std::string &essfile, const std::string &outfile) + Importer::Importer(const std::string &essfile, const std::string &outfile, const std::string &encoding) : mEssFile(essfile) , mOutFile(outfile) + , mEncoding(encoding) { } @@ -188,10 +191,10 @@ namespace ESSImport Ogre::LogManager logman; Ogre::Root root; - // TODO: set up encoding on ESMReader based on openmw.cfg / --encoding switch - + ToUTF8::Utf8Encoder encoder(ToUTF8::calculateEncoding(mEncoding)); ESM::ESMReader esm; esm.open(mEssFile); + esm.setEncoder(&encoder); Context context; diff --git a/apps/essimporter/importer.hpp b/apps/essimporter/importer.hpp index eb199b6df..ccacd7972 100644 --- a/apps/essimporter/importer.hpp +++ b/apps/essimporter/importer.hpp @@ -9,7 +9,7 @@ namespace ESSImport class Importer { public: - Importer(const std::string& essfile, const std::string& outfile); + Importer(const std::string& essfile, const std::string& outfile, const std::string& encoding); void run(); @@ -18,6 +18,7 @@ namespace ESSImport private: std::string mEssFile; std::string mOutFile; + std::string mEncoding; }; } diff --git a/apps/essimporter/main.cpp b/apps/essimporter/main.cpp index d467e053e..ae4b36ecd 100644 --- a/apps/essimporter/main.cpp +++ b/apps/essimporter/main.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include "importer.hpp" namespace bpo = boost::program_options; @@ -23,31 +25,36 @@ int main(int argc, char** argv) ("mwsave,m", bpo::value(), "morrowind .ess save file") ("output,o", bpo::value(), "output file (.omwsave)") ("compare,c", "compare two .ess files") + ("encoding", boost::program_options::value()->default_value("win1252"), "encoding of the save file") ; p_desc.add("mwsave", 1).add("output", 1); - bpo::variables_map vm; + bpo::variables_map variables; bpo::parsed_options parsed = bpo::command_line_parser(argc, argv) .options(desc) .positional(p_desc) .run(); - bpo::store(parsed, vm); + bpo::store(parsed, variables); - if(vm.count("help") || !vm.count("mwsave") || !vm.count("output")) { + if(variables.count("help") || !variables.count("mwsave") || !variables.count("output")) { std::cout << desc; return 0; } - bpo::notify(vm); + bpo::notify(variables); + + Files::ConfigurationManager cfgManager; + cfgManager.readConfiguration(variables, desc); - std::string essFile = vm["mwsave"].as(); - std::string outputFile = vm["output"].as(); + std::string essFile = variables["mwsave"].as(); + std::string outputFile = variables["output"].as(); + std::string encoding = variables["encoding"].as(); - ESSImport::Importer importer(essFile, outputFile); + ESSImport::Importer importer(essFile, outputFile, encoding); - if (vm.count("compare")) + if (variables.count("compare")) importer.compare(); else { diff --git a/components/esm/cellref.cpp b/components/esm/cellref.cpp index dfc3052ee..0dd2987b5 100644 --- a/components/esm/cellref.cpp +++ b/components/esm/cellref.cpp @@ -153,7 +153,7 @@ void ESM::CellRef::blank() mLockLevel = 0; mKey.clear(); mTrap.clear(); - mReferenceBlocked = 0; + mReferenceBlocked = -1; mTeleport = false; for (int i=0; i<3; ++i)