mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-02 23:08:00 +03:00
Allow paths with trailing data, emmitting a warning
This commit is contained in:
parent
9be606a40d
commit
8fb0b5846e
7 changed files with 113 additions and 65 deletions
|
@ -138,10 +138,10 @@ void mergeComposingVariables(boost::program_options::variables_map& first, boost
|
|||
boost::any& firstValue = firstPosition->second.value();
|
||||
const boost::any& secondValue = second[name].value();
|
||||
|
||||
if (firstValue.type() == typeid(Files::PathContainer))
|
||||
if (firstValue.type() == typeid(Files::ReluctantPathContainer))
|
||||
{
|
||||
auto& firstPathContainer = boost::any_cast<Files::PathContainer&>(firstValue);
|
||||
const auto& secondPathContainer = boost::any_cast<const Files::PathContainer&>(secondValue);
|
||||
auto& firstPathContainer = boost::any_cast<Files::ReluctantPathContainer&>(firstValue);
|
||||
const auto& secondPathContainer = boost::any_cast<const Files::ReluctantPathContainer&>(secondValue);
|
||||
|
||||
firstPathContainer.insert(firstPathContainer.end(), secondPathContainer.begin(), secondPathContainer.end());
|
||||
}
|
||||
|
@ -317,4 +317,22 @@ void parseConfig(std::istream& stream, boost::program_options::variables_map& va
|
|||
);
|
||||
}
|
||||
|
||||
std::istream& operator>> (std::istream& istream, ReluctantPath& reluctantPath)
|
||||
{
|
||||
// Read from stream using boost::filesystem::path rules, then discard anything remaining.
|
||||
// This prevents boost::program_options getting upset that we've not consumed the whole stream.
|
||||
istream >> static_cast<boost::filesystem::path&>(reluctantPath);
|
||||
if (istream && !istream.eof() && istream.peek() != EOF)
|
||||
{
|
||||
std::string remainder(std::istreambuf_iterator(istream), {});
|
||||
Log(Debug::Warning) << "Trailing data in path setting. Used '" << reluctantPath.string() << "' but '" << remainder << "' remained";
|
||||
}
|
||||
return istream;
|
||||
}
|
||||
|
||||
PathContainer asPathContainer(const ReluctantPathContainer& reluctantPathContainer)
|
||||
{
|
||||
return PathContainer(reluctantPathContainer.begin(), reluctantPathContainer.end());
|
||||
}
|
||||
|
||||
} /* namespace Cfg */
|
||||
|
|
|
@ -77,6 +77,18 @@ void parseArgs(int argc, const char* const argv[], boost::program_options::varia
|
|||
void parseConfig(std::istream& stream, boost::program_options::variables_map& variables,
|
||||
boost::program_options::options_description& description);
|
||||
|
||||
class ReluctantPath : public boost::filesystem::path
|
||||
{
|
||||
public:
|
||||
operator boost::filesystem::path() { return *this; }
|
||||
};
|
||||
|
||||
std::istream& operator>> (std::istream& istream, ReluctantPath& reluctantPath);
|
||||
|
||||
typedef std::vector<ReluctantPath> ReluctantPathContainer;
|
||||
|
||||
PathContainer asPathContainer(const ReluctantPathContainer& reluctantPathContainer);
|
||||
|
||||
} /* namespace Cfg */
|
||||
|
||||
#endif /* COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue