From 95d2c7ea5ca603548f79c19c8a0dc665aa5c233f Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Wed, 20 Jul 2016 02:48:57 +0100 Subject: [PATCH] Attempt to unescape characters when constructing file paths, introducing compilation errors. --- apps/openmw/main.cpp | 4 ++-- components/fallback/validate.hpp | 18 +++++++++++++++++ components/files/configurationmanager.cpp | 24 +++++++++++++++++++++++ components/files/configurationmanager.hpp | 5 +++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index f54905a2c7..64b74276ed 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -76,7 +76,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat desc.add_options() ("help", "print help message") ("version", "print version information and quit") - ("data", bpo::value()->default_value(Files::PathContainer(), "data") + ("data", bpo::value()->default_value(Files::EscapePathContainer(), "data") ->multitoken()->composing(), "set data directories (later directories have higher priority)") ("data-local", bpo::value()->default_value(""), @@ -193,7 +193,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat // directory settings engine.enableFSStrict(variables["fs-strict"].as()); - Files::PathContainer dataDirs(variables["data"].as()); + Files::PathContainer dataDirs(variables["data"].as().mContainer); std::string local(variables["data-local"].as().toStdString()); if (!local.empty()) diff --git a/components/fallback/validate.hpp b/components/fallback/validate.hpp index d82ef5770e..4f0933e6e9 100644 --- a/components/fallback/validate.hpp +++ b/components/fallback/validate.hpp @@ -4,6 +4,7 @@ #include #include +#include // Parses and validates a fallback map from boost program_options. // Note: for boost to pick up the validate function, you need to pull in the namespace e.g. @@ -66,6 +67,23 @@ namespace Files { for (std::vector::const_iterator it = tokens.begin(); it != tokens.end(); ++it) eSV->mVector.push_back(EscapeHashString(*it)); } + + struct EscapePathContainer { + PathContainer mContainer; + }; + + std::istream & operator>> (std::istream & istream, EscapePathContainer & escapePathContainer) + { + std::cout << "The new dodgy operator>> is being used" << std::endl; + + boost::iostreams::filtering_istream filteredStream; + filteredStream.push(unescape_hash_filter()); + filteredStream.push(istream); + + filteredStream >> escapePathContainer.mContainer; + + return istream; + } } #endif diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 3a7f579496..bbac627318 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -237,6 +237,30 @@ int escape_hash_filter::get(Source & src) return retval; } +template +int unescape_hash_filter::get(Source & src) +{ + int character = boost::iostreams::get(src); + if (character == escape_hash_filter::sEscape) + { + int nextChar = boost::iostreams::get(src); + switch (nextChar) + { + case escape_hash_filter::sEscapeIdentifier: + return escape_hash_filter::sEscape; + break; + case escape_hash_filter::sHashIdentifier: + return '#'; + break; + default: + return '?'; + break; + } + } + else + return character; +} + std::string EscapeHashString::processString(const std::string & str) { std::string temp = boost::replace_all_copy(str, std::string() + (char)escape_hash_filter::sEscape + (char)escape_hash_filter::sHashIdentifier, "#"); diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index 3ce995983a..d31ac1ecd3 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -88,6 +88,11 @@ struct escape_hash_filter : public boost::iostreams::input_filter bool mFinishLine; }; +struct unescape_hash_filter : public boost::iostreams::input_filter +{ + template int get(Source & src); +}; + /** * \class EscapeHashString */