From 88fe079f95e16cd8e0e1f3184d968690ce4c6b91 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Fri, 17 Jan 2025 00:53:19 +0000 Subject: [PATCH 1/4] Don't mangle settings with the comment character in their value '#' is a valid character in setting values - it's only a comment if it's the first non-" \t\r\n" character on a line. Making the comment ignoring match the parser we use elsewhere should avoid mangling data. --- apps/mwiniimporter/importer.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index 8c7c238b4a..cc38eed211 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -352,12 +352,10 @@ MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const std::filesystem::pat std::string line; while (std::getline(file, line)) { - - // we cant say comment by only looking at first char anymore - int comment_pos = static_cast(line.find('#')); - if (comment_pos > 0) + // ignore comments - keep in sync with configfileparser.cpp + if (line.find('#') == line.find_first_not_of(" \t\r\n")) { - line = line.substr(0, comment_pos); + continue; } if (line.empty()) From e345fca99a4fe987bb9a13aa9ee7a79e6191a2a2 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Fri, 17 Jan 2025 01:21:24 +0000 Subject: [PATCH 2/4] trim_ws, too --- apps/mwiniimporter/importer.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index cc38eed211..c3b23eff5c 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -11,6 +11,23 @@ namespace sfs = std::filesystem; +namespace +{ + // from configfileparser.cpp + std::string trim_ws(const std::string& s) + { + std::string::size_type n, n2; + n = s.find_first_not_of(" \t\r\n"); + if (n == std::string::npos) + return std::string(); + else + { + n2 = s.find_last_not_of(" \t\r\n"); + return s.substr(n, n2 - n + 1); + } + } +} + MwIniImporter::MwIniImporter() : mVerbose(false) , mEncoding(ToUTF8::WINDOWS_1250) @@ -371,6 +388,8 @@ MwIniImporter::multistrmap MwIniImporter::loadCfgFile(const std::filesystem::pat std::string key(line.substr(0, pos)); std::string value(line.substr(pos + 1)); + key = trim_ws(key); + value = trim_ws(key); if (map.find(key) == map.end()) { From 33553c0cf7aeebd334a1a5c7b6e857251409451f Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Fri, 17 Jan 2025 01:34:08 +0000 Subject: [PATCH 3/4] Handle encoding a bit more cleverly * use the value from the existing openmw.cfg if it exists and we weren't told to use something else on the command line * write the value to openmw.cfg if it wasn't there or we've overridden it --- apps/mwiniimporter/main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 0beb2b38cc..b934d0967e 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -126,12 +126,20 @@ int wmain(int argc, wchar_t* wargv[]) MwIniImporter importer; importer.setVerbose(vm.count("verbose") != 0); + MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile); + // Font encoding settings - std::string encoding(vm["encoding"].as()); + std::string encoding; + if (vm["encoding"].defaulted() && cfg.contains("encoding") && !cfg["encoding"].empty()) + encoding = cfg["encoding"].back(); + else + { + encoding = vm["encoding"].as(); + cfg["encoding"] = {encoding}; + } importer.setInputEncoding(ToUTF8::calculateEncoding(encoding)); MwIniImporter::multistrmap ini = importer.loadIniFile(iniFile); - MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile); if (!vm.count("fonts")) { From 84c497b1fb4ca4d254e3b2c5daa6e5e9b5eb214d Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Fri, 17 Jan 2025 01:45:09 +0000 Subject: [PATCH 4/4] capitulate --- apps/mwiniimporter/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index b934d0967e..6e4242cb4e 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -135,7 +135,7 @@ int wmain(int argc, wchar_t* wargv[]) else { encoding = vm["encoding"].as(); - cfg["encoding"] = {encoding}; + cfg["encoding"] = { encoding }; } importer.setInputEncoding(ToUTF8::calculateEncoding(encoding));