From e2b348de9620c23695064f585d7ea4600b2abe88 Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Mon, 31 Dec 2012 16:44:22 +0100 Subject: [PATCH 1/3] mwiniimporter: fix line ending problem --- 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 dda8fd8ba5..30822516ee 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -660,10 +660,19 @@ MwIniImporter::multistrmap MwIniImporter::loadIniFile(std::string filename) { std::string line; while (std::getline(file, line)) { + // unify Unix-style and Windows file ending + if (!(line.empty()) && (line[line.length()-1]) == '\r') { + line = line.substr(0, line.length()-1); + } + if(line[0] == '[') { - if(line.length() > 2) { - section = line.substr(1, line.length()-2); + int pos = line.find(']'); + if(pos < 2) { + std::cout << "Warning: ini file wrongly formatted (" << line << "). Line ignored." << std::endl; + continue; } + + section = line.substr(1, line.find(']')-1); continue; } From e9a464c9f7463c175f38e4966600ef3f839f68d1 Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Mon, 31 Dec 2012 16:45:24 +0100 Subject: [PATCH 2/3] mwiniimporter: remove fallback values for Cursors --- apps/mwiniimporter/importer.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 30822516ee..c15818ae3a 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -146,13 +146,6 @@ MwIniImporter::MwIniImporter() "FontColor:color_negative", "FontColor:color_count", - // cursors - "Cursors:Cursor 0", - "Cursors:Cursor 1", - "Cursors:Cursor 2", - "Cursors:Cursor 3", - "Cursors:Cursor 4", - // level up messages "Level Up:Level2", "Level Up:Level3", From 2a7336c310eb668015e39265c5e4f4f2d1216edb Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Tue, 1 Jan 2013 21:59:30 +0100 Subject: [PATCH 3/3] mwiniimporter: handle ini file encodings Use components/to_utf8 to handle encodings. Add an --encoding option for choosing between win1250, win1251 and win1252 encodings for the imported ini file. --- apps/mwiniimporter/importer.cpp | 15 +++++++++++++++ apps/mwiniimporter/importer.hpp | 5 +++++ apps/mwiniimporter/main.cpp | 9 +++++++++ 3 files changed, 29 insertions(+) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index c15818ae3a..def70615bc 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -653,6 +653,8 @@ MwIniImporter::multistrmap MwIniImporter::loadIniFile(std::string filename) { std::string line; while (std::getline(file, line)) { + line = toUTF8(line); + // unify Unix-style and Windows file ending if (!(line.empty()) && (line[line.length()-1]) == '\r') { line = line.substr(0, line.length()-1); @@ -826,3 +828,16 @@ void MwIniImporter::writeToFile(boost::iostreams::stream #include +#include "../../components/to_utf8/to_utf8.hpp" + class MwIniImporter { public: typedef std::map strmap; typedef std::map > multistrmap; MwIniImporter(); + void setInputEncoding(const ToUTF8::FromType& encoding); void setVerbose(bool verbose); multistrmap loadIniFile(std::string filename); multistrmap loadCfgFile(std::string filename); @@ -25,9 +28,11 @@ class MwIniImporter { private: void insertMultistrmap(multistrmap &cfg, std::string key, std::string value); std::string numberToString(int n); + std::string toUTF8(const std::string &str); bool mVerbose; strmap mMergeMap; std::vector mMergeFallback; + ToUTF8::FromType mEncoding; }; diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 234d7d57d4..e90f26dd2c 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -18,6 +18,11 @@ int main(int argc, char *argv[]) { ("cfg,c", bpo::value(), "openmw.cfg file") ("output,o", bpo::value()->default_value(""), "openmw.cfg file") ("game-files,g", "import esm and esp files") + ("encoding,e", bpo::value()-> default_value("win1252"), + "Character encoding used in OpenMW game messages:\n" + "\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n" + "\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n" + "\n\twin1252 - Western European (Latin) alphabet, used by default") ; p_desc.add("ini", 1).add("cfg", 1); @@ -57,6 +62,10 @@ int main(int argc, char *argv[]) { MwIniImporter importer; importer.setVerbose(vm.count("verbose")); + // Font encoding settings + std::string encoding(vm["encoding"].as()); + importer.setInputEncoding(ToUTF8::calculateEncoding(encoding)); + MwIniImporter::multistrmap ini = importer.loadIniFile(iniFile); MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile);