From af0d399103e86964862286f9248589f140874f08 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Sat, 9 Oct 2021 01:49:08 +0100 Subject: [PATCH] Purge all uses of Escape Hash types --- apps/opencs/editor.cpp | 26 ++++----- apps/openmw/main.cpp | 54 +++++++++---------- apps/openmw_test_suite/mwworld/test_store.cpp | 12 ++--- components/files/configfileparser.cpp | 4 +- components/files/configurationmanager.cpp | 23 ++++---- 5 files changed, 58 insertions(+), 61 deletions(-) diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 3f53a523f4..b437a36201 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -88,16 +88,16 @@ std::pair > CS::Editor::readConfi boost::program_options::options_description desc("Syntax: openmw-cs \nAllowed options"); desc.add_options() - ("data", boost::program_options::value()->default_value(Files::EscapePathContainer(), "data")->multitoken()->composing()) - ("data-local", boost::program_options::value()->default_value(Files::EscapePath(), "")) + ("data", boost::program_options::value()->default_value(Files::PathContainer(), "data")->multitoken()->composing()) + ("data-local", boost::program_options::value()->default_value(Files::PathContainer::value_type(), "")) ("fs-strict", boost::program_options::value()->implicit_value(true)->default_value(false)) - ("encoding", boost::program_options::value()->default_value("win1252")) - ("resources", boost::program_options::value()->default_value(Files::EscapePath(), "resources")) - ("fallback-archive", boost::program_options::value()-> - default_value(Files::EscapeStringVector(), "fallback-archive")->multitoken()) + ("encoding", boost::program_options::value()->default_value("win1252")) + ("resources", boost::program_options::value()->default_value(boost::filesystem::path(), "resources")) + ("fallback-archive", boost::program_options::value>()-> + default_value(std::vector(), "fallback-archive")->multitoken()) ("fallback", boost::program_options::value()->default_value(FallbackMap(), "") ->multitoken()->composing(), "fallback values") - ("script-blacklist", boost::program_options::value()->default_value(Files::EscapeStringVector(), "") + ("script-blacklist", boost::program_options::value>()->default_value(std::vector(), "") ->multitoken(), "exclude specified script from the verifier (if the use of the blacklist is enabled)") ("script-blacklist-use", boost::program_options::value()->implicit_value(true) ->default_value(true), "enable script blacklisting"); @@ -108,24 +108,24 @@ std::pair > CS::Editor::readConfi Fallback::Map::init(variables["fallback"].as().mMap); - mEncodingName = variables["encoding"].as().toStdString(); + mEncodingName = variables["encoding"].as(); mDocumentManager.setEncoding(ToUTF8::calculateEncoding(mEncodingName)); mFileDialog.setEncoding (QString::fromUtf8(mEncodingName.c_str())); - mDocumentManager.setResourceDir (mResources = variables["resources"].as().mPath); + mDocumentManager.setResourceDir (mResources = variables["resources"].as()); if (variables["script-blacklist-use"].as()) mDocumentManager.setBlacklistedScripts ( - variables["script-blacklist"].as().toStdStringVector()); + variables["script-blacklist"].as>()); mFsStrict = variables["fs-strict"].as(); Files::PathContainer dataDirs, dataLocal; if (!variables["data"].empty()) { - dataDirs = Files::PathContainer(Files::EscapePath::toPathContainer(variables["data"].as())); + dataDirs = variables["data"].as(); } - Files::PathContainer::value_type local(variables["data-local"].as().mPath); + Files::PathContainer::value_type local(variables["data-local"].as()); if (!local.empty()) dataLocal.push_back(local); @@ -155,7 +155,7 @@ std::pair > CS::Editor::readConfi mFileDialog.addFiles(path); } - return std::make_pair (dataDirs, variables["fallback-archive"].as().toStdStringVector()); + return std::make_pair (dataDirs, variables["fallback-archive"].as>()); } void CS::Editor::createGame() diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index de0fb0df03..5de177a907 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -45,31 +45,31 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("help", "print help message") ("version", "print version information and quit") - ("replace", bpo::value()->default_value(Files::EscapeStringVector(), "") + ("replace", bpo::value()->default_value(StringsVector(), "") ->multitoken()->composing(), "settings where the values from the current source should replace those from lower-priority sources instead of being appended") - ("data", bpo::value()->default_value(Files::EscapePathContainer(), "data") + ("data", bpo::value()->default_value(Files::PathContainer(), "data") ->multitoken()->composing(), "set data directories (later directories have higher priority)") - ("data-local", bpo::value()->default_value(Files::EscapePath(), ""), + ("data-local", bpo::value()->default_value(Files::PathContainer::value_type(), ""), "set local data directory (highest priority)") - ("fallback-archive", bpo::value()->default_value(Files::EscapeStringVector(), "fallback-archive") + ("fallback-archive", bpo::value()->default_value(StringsVector(), "fallback-archive") ->multitoken()->composing(), "set fallback BSA archives (later archives have higher priority)") - ("resources", bpo::value()->default_value(Files::EscapePath(), "resources"), + ("resources", bpo::value()->default_value(boost::filesystem::path(), "resources"), "set resources directory") - ("start", bpo::value()->default_value(""), + ("start", bpo::value()->default_value(""), "set initial cell") - ("content", bpo::value()->default_value(Files::EscapeStringVector(), "") + ("content", bpo::value()->default_value(StringsVector(), "") ->multitoken()->composing(), "content file(s): esm/esp, or omwgame/omwaddon") - ("groundcover", bpo::value()->default_value(Files::EscapeStringVector(), "") + ("groundcover", bpo::value()->default_value(StringsVector(), "") ->multitoken()->composing(), "groundcover content file(s): esm/esp, or omwgame/omwaddon") - ("lua-scripts", bpo::value()->default_value(Files::EscapeStringVector(), "") + ("lua-scripts", bpo::value()->default_value(StringsVector(), "") ->multitoken()->composing(), "file(s) with a list of global Lua scripts: omwscripts") ("no-sound", bpo::value()->implicit_value(true) @@ -84,7 +84,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("script-console", bpo::value()->implicit_value(true) ->default_value(false), "enable console-only script functionality") - ("script-run", bpo::value()->default_value(""), + ("script-run", bpo::value()->default_value(""), "select a file containing a list of console commands that is executed on startup") ("script-warn", bpo::value()->implicit_value (1) @@ -94,13 +94,13 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat "\t1 - show warning but consider script as correctly compiled anyway\n" "\t2 - treat warnings as errors") - ("script-blacklist", bpo::value()->default_value(Files::EscapeStringVector(), "") + ("script-blacklist", bpo::value()->default_value(StringsVector(), "") ->multitoken()->composing(), "ignore the specified script (if the use of the blacklist is enabled)") ("script-blacklist-use", bpo::value()->implicit_value(true) ->default_value(true), "enable script blacklisting") - ("load-savegame", bpo::value()->default_value(Files::EscapePath(), ""), + ("load-savegame", bpo::value()->default_value(boost::filesystem::path(), ""), "load a save game file on game startup (specify an absolute filename or a filename relative to the current working directory)") ("skip-menu", bpo::value()->implicit_value(true) @@ -112,7 +112,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("fs-strict", bpo::value()->implicit_value(true) ->default_value(false), "strict file system handling (no case folding)") - ("encoding", bpo::value()-> + ("encoding", 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" @@ -153,7 +153,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat { cfgMgr.readConfiguration(variables, desc, true); - Version::Version v = Version::getOpenmwVersion(variables["resources"].as().mPath.string()); + Version::Version v = Version::getOpenmwVersion(variables["resources"].as().string()); getRawStdout() << v.describe() << std::endl; return false; } @@ -162,38 +162,38 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat cfgMgr.readConfiguration(variables, desc); cfgMgr.mergeComposingVariables(variables, composingVariables, desc); - Version::Version v = Version::getOpenmwVersion(variables["resources"].as().mPath.string()); + Version::Version v = Version::getOpenmwVersion(variables["resources"].as().string()); Log(Debug::Info) << v.describe(); engine.setGrabMouse(!variables["no-grab"].as()); // Font encoding settings - std::string encoding(variables["encoding"].as().toStdString()); + std::string encoding(variables["encoding"].as()); Log(Debug::Info) << ToUTF8::encodingUsingMessage(encoding); engine.setEncoding(ToUTF8::calculateEncoding(encoding)); // directory settings engine.enableFSStrict(variables["fs-strict"].as()); - Files::PathContainer dataDirs(Files::EscapePath::toPathContainer(variables["data"].as())); + Files::PathContainer dataDirs(variables["data"].as()); - Files::PathContainer::value_type local(variables["data-local"].as().mPath); + Files::PathContainer::value_type local(variables["data-local"].as()); if (!local.empty()) dataDirs.push_back(local); cfgMgr.processPaths(dataDirs); - engine.setResourceDir(variables["resources"].as().mPath); + engine.setResourceDir(variables["resources"].as()); engine.setDataDirs(dataDirs); // fallback archives - StringsVector archives = variables["fallback-archive"].as().toStdStringVector(); + StringsVector archives = variables["fallback-archive"].as(); for (StringsVector::const_iterator it = archives.begin(); it != archives.end(); ++it) { engine.addArchive(*it); } - StringsVector content = variables["content"].as().toStdStringVector(); + StringsVector content = variables["content"].as(); if (content.empty()) { Log(Debug::Error) << "No content file given (esm/esp, nor omwgame/omwaddon). Aborting..."; @@ -214,18 +214,18 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.addContentFile(file); } - StringsVector groundcover = variables["groundcover"].as().toStdStringVector(); + StringsVector groundcover = variables["groundcover"].as(); for (auto& file : groundcover) { engine.addGroundcoverFile(file); } - StringsVector luaScriptLists = variables["lua-scripts"].as().toStdStringVector(); + StringsVector luaScriptLists = variables["lua-scripts"].as(); for (const auto& file : luaScriptLists) engine.addLuaScriptListFile(file); // startup-settings - engine.setCell(variables["start"].as().toStdString()); + engine.setCell(variables["start"].as()); engine.setSkipMenu (variables["skip-menu"].as(), variables["new-game"].as()); if (!variables["skip-menu"].as() && variables["new-game"].as()) Log(Debug::Warning) << "Warning: new-game used without skip-menu -> ignoring it"; @@ -234,11 +234,11 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setCompileAll(variables["script-all"].as()); engine.setCompileAllDialogue(variables["script-all-dialogue"].as()); engine.setScriptConsoleMode (variables["script-console"].as()); - engine.setStartupScript (variables["script-run"].as().toStdString()); + engine.setStartupScript (variables["script-run"].as()); engine.setWarningsMode (variables["script-warn"].as()); - engine.setScriptBlacklist (variables["script-blacklist"].as().toStdStringVector()); + engine.setScriptBlacklist (variables["script-blacklist"].as()); engine.setScriptBlacklistUse (variables["script-blacklist-use"].as()); - engine.setSaveGameFile (variables["load-savegame"].as().mPath.string()); + engine.setSaveGameFile (variables["load-savegame"].as().string()); // other settings Fallback::Map::init(variables["fallback"].as().mMap); diff --git a/apps/openmw_test_suite/mwworld/test_store.cpp b/apps/openmw_test_suite/mwworld/test_store.cpp index f3b2bb3dcb..13a9ebee9c 100644 --- a/apps/openmw_test_suite/mwworld/test_store.cpp +++ b/apps/openmw_test_suite/mwworld/test_store.cpp @@ -59,10 +59,10 @@ struct ContentFileTest : public ::testing::Test boost::program_options::options_description desc("Allowed options"); desc.add_options() - ("data", boost::program_options::value()->default_value(Files::EscapePathContainer(), "data")->multitoken()->composing()) - ("content", boost::program_options::value()->default_value(Files::EscapeStringVector(), "") + ("data", boost::program_options::value()->default_value(Files::PathContainer(), "data")->multitoken()->composing()) + ("content", boost::program_options::value>()->default_value(std::vector(), "") ->multitoken()->composing(), "content file(s): esm/esp, or omwgame/omwaddon") - ("data-local", boost::program_options::value()->default_value(Files::EscapePath(), "")); + ("data-local", boost::program_options::value()->default_value(Files::PathContainer::value_type(), "")); boost::program_options::notify(variables); @@ -70,10 +70,10 @@ struct ContentFileTest : public ::testing::Test Files::PathContainer dataDirs, dataLocal; if (!variables["data"].empty()) { - dataDirs = Files::EscapePath::toPathContainer(variables["data"].as()); + dataDirs = variables["data"].as(); } - Files::PathContainer::value_type local(variables["data-local"].as().mPath); + Files::PathContainer::value_type local(variables["data-local"].as()); if (!local.empty()) { dataLocal.push_back(local); } @@ -86,7 +86,7 @@ struct ContentFileTest : public ::testing::Test Files::Collections collections (dataDirs, true); - std::vector contentFiles = variables["content"].as().toStdStringVector(); + std::vector contentFiles = variables["content"].as>(); for (auto & contentFile : contentFiles) mContentFiles.push_back(collections.getPath(contentFile)); } diff --git a/components/files/configfileparser.cpp b/components/files/configfileparser.cpp index fe98ea11d2..7fcc033157 100644 --- a/components/files/configfileparser.cpp +++ b/components/files/configfileparser.cpp @@ -158,8 +158,8 @@ namespace Files while (this->getline(s)) { // strip '#' comments and whitespace - if ((n = s.find('#')) != std::string::npos) - s = s.substr(0, n); + if (s.find('#') == s.find_first_not_of(" \t\r\n")) + continue; s = trim_ws(s); if (!s.empty()) { diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 7fd134cf0f..8aa6853237 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -108,7 +108,7 @@ void ConfigurationManager::mergeComposingVariables(boost::program_options::varia auto replace = second["replace"]; if (!replace.defaulted() && !replace.empty()) { - std::vector replaceVector = replace.as().toStdStringVector(); + std::vector replaceVector = replace.as>(); replacedVariables.insert(replaceVector.begin(), replaceVector.end()); } } @@ -137,19 +137,19 @@ void ConfigurationManager::mergeComposingVariables(boost::program_options::varia boost::any& firstValue = firstPosition->second.value(); const boost::any& secondValue = second[name].value(); - if (firstValue.type() == typeid(Files::EscapePathContainer)) + if (firstValue.type() == typeid(Files::PathContainer)) { - auto& firstPathContainer = boost::any_cast(firstValue); - const auto& secondPathContainer = boost::any_cast(secondValue); + auto& firstPathContainer = boost::any_cast(firstValue); + const auto& secondPathContainer = boost::any_cast(secondValue); firstPathContainer.insert(firstPathContainer.end(), secondPathContainer.begin(), secondPathContainer.end()); } - else if (firstValue.type() == typeid(Files::EscapeStringVector)) + else if (firstValue.type() == typeid(std::vector)) { - auto& firstVector = boost::any_cast(firstValue); - const auto& secondVector = boost::any_cast(secondValue); + auto& firstVector = boost::any_cast&>(firstValue); + const auto& secondVector = boost::any_cast&>(secondValue); - firstVector.mVector.insert(firstVector.mVector.end(), secondVector.mVector.begin(), secondVector.mVector.end()); + firstVector.insert(firstVector.end(), secondVector.begin(), secondVector.end()); } else if (firstValue.type() == typeid(Fallback::FallbackMap)) { @@ -234,11 +234,8 @@ bool ConfigurationManager::loadConfig(const boost::filesystem::path& path, if (!mSilent) Log(Debug::Info) << "Loading config file: " << cfgFile.string(); - boost::filesystem::ifstream configFileStreamUnfiltered(cfgFile); - boost::iostreams::filtering_istream configFileStream; - configFileStream.push(escape_hash_filter()); - configFileStream.push(configFileStreamUnfiltered); - if (configFileStreamUnfiltered.is_open()) + boost::filesystem::ifstream configFileStream(cfgFile); + if (configFileStream.is_open()) { boost::program_options::store(Files::parse_config_file( configFileStream, description, true), variables);