forked from mirror/openmw-tes3mp
Merge pull request #316 from TES3MP/master
Add master commits up to 17 Oct 2017
This commit is contained in:
commit
b20df4b7cd
3 changed files with 83 additions and 21 deletions
|
@ -90,16 +90,16 @@ std::pair<Files::PathContainer, std::vector<std::string> > CS::Editor::readConfi
|
|||
boost::program_options::options_description desc("Syntax: openmw-cs <options>\nAllowed options");
|
||||
|
||||
desc.add_options()
|
||||
("data", boost::program_options::value<Files::PathContainer>()->default_value(Files::PathContainer(), "data")->multitoken()->composing())
|
||||
("data-local", boost::program_options::value<std::string>()->default_value(""))
|
||||
("data", boost::program_options::value<Files::EscapePathContainer>()->default_value(Files::EscapePathContainer(), "data")->multitoken()->composing())
|
||||
("data-local", boost::program_options::value<Files::EscapeHashString>()->default_value(""))
|
||||
("fs-strict", boost::program_options::value<bool>()->implicit_value(true)->default_value(false))
|
||||
("encoding", boost::program_options::value<std::string>()->default_value("win1252"))
|
||||
("resources", boost::program_options::value<std::string>()->default_value("resources"))
|
||||
("fallback-archive", boost::program_options::value<std::vector<std::string> >()->
|
||||
default_value(std::vector<std::string>(), "fallback-archive")->multitoken())
|
||||
("encoding", boost::program_options::value<Files::EscapeHashString>()->default_value("win1252"))
|
||||
("resources", boost::program_options::value<Files::EscapeHashString>()->default_value("resources"))
|
||||
("fallback-archive", boost::program_options::value<Files::EscapeStringVector>()->
|
||||
default_value(Files::EscapeStringVector(), "fallback-archive")->multitoken())
|
||||
("fallback", boost::program_options::value<FallbackMap>()->default_value(FallbackMap(), "")
|
||||
->multitoken()->composing(), "fallback values")
|
||||
("script-blacklist", boost::program_options::value<std::vector<std::string> >()->default_value(std::vector<std::string>(), "")
|
||||
("script-blacklist", boost::program_options::value<Files::EscapeStringVector>()->default_value(Files::EscapeStringVector(), "")
|
||||
->multitoken(), "exclude specified script from the verifier (if the use of the blacklist is enabled)")
|
||||
("script-blacklist-use", boost::program_options::value<bool>()->implicit_value(true)
|
||||
->default_value(true), "enable script blacklisting");
|
||||
|
@ -109,24 +109,24 @@ std::pair<Files::PathContainer, std::vector<std::string> > CS::Editor::readConfi
|
|||
mCfgMgr.readConfiguration(variables, desc, quiet);
|
||||
|
||||
mDocumentManager.setEncoding (
|
||||
ToUTF8::calculateEncoding (variables["encoding"].as<std::string>()));
|
||||
ToUTF8::calculateEncoding (variables["encoding"].as<Files::EscapeHashString>().toStdString()));
|
||||
|
||||
mDocumentManager.setResourceDir (mResources = variables["resources"].as<std::string>());
|
||||
mDocumentManager.setResourceDir (mResources = variables["resources"].as<Files::EscapeHashString>().toStdString());
|
||||
|
||||
mDocumentManager.setFallbackMap (variables["fallback"].as<FallbackMap>().mMap);
|
||||
|
||||
if (variables["script-blacklist-use"].as<bool>())
|
||||
mDocumentManager.setBlacklistedScripts (
|
||||
variables["script-blacklist"].as<std::vector<std::string> >());
|
||||
variables["script-blacklist"].as<Files::EscapeStringVector>().toStdStringVector());
|
||||
|
||||
mFsStrict = variables["fs-strict"].as<bool>();
|
||||
|
||||
Files::PathContainer dataDirs, dataLocal;
|
||||
if (!variables["data"].empty()) {
|
||||
dataDirs = Files::PathContainer(variables["data"].as<Files::PathContainer>());
|
||||
dataDirs = Files::PathContainer(Files::EscapePath::toPathContainer(variables["data"].as<Files::EscapePathContainer>()));
|
||||
}
|
||||
|
||||
std::string local = variables["data-local"].as<std::string>();
|
||||
std::string local = variables["data-local"].as<Files::EscapeHashString>().toStdString();
|
||||
if (!local.empty()) {
|
||||
dataLocal.push_back(Files::PathContainer::value_type(local));
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ std::pair<Files::PathContainer, std::vector<std::string> > CS::Editor::readConfi
|
|||
mFileDialog.addFiles(path);
|
||||
}
|
||||
|
||||
return std::make_pair (dataDirs, variables["fallback-archive"].as<std::vector<std::string> >());
|
||||
return std::make_pair (dataDirs, variables["fallback-archive"].as<Files::EscapeStringVector>().toStdStringVector());
|
||||
}
|
||||
|
||||
void CS::Editor::createGame()
|
||||
|
|
|
@ -55,7 +55,6 @@ void Config::GameSettings::validatePaths()
|
|||
|
||||
for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) {
|
||||
QString path = QString::fromUtf8(it->string().c_str());
|
||||
path.remove(QChar('\"'));
|
||||
|
||||
QDir dir(path);
|
||||
if (dir.exists())
|
||||
|
@ -64,6 +63,11 @@ void Config::GameSettings::validatePaths()
|
|||
|
||||
// Do the same for data-local
|
||||
QString local = mSettings.value(QString("data-local"));
|
||||
if (local.at(0) == QChar('\"'))
|
||||
{
|
||||
local.remove(0, 1);
|
||||
local.chop(1);
|
||||
}
|
||||
|
||||
if (local.isEmpty())
|
||||
return;
|
||||
|
@ -76,7 +80,6 @@ void Config::GameSettings::validatePaths()
|
|||
|
||||
if (!dataDirs.empty()) {
|
||||
QString path = QString::fromUtf8(dataDirs.front().string().c_str());
|
||||
path.remove(QChar('\"'));
|
||||
|
||||
QDir dir(path);
|
||||
if (dir.exists())
|
||||
|
@ -120,6 +123,28 @@ bool Config::GameSettings::readFile(QTextStream &stream, QMap<QString, QString>
|
|||
// Don't remove existing data entries
|
||||
if (key != QLatin1String("data"))
|
||||
settings.remove(key);
|
||||
else
|
||||
{
|
||||
// 'data=...' line, so needs processing to deal with ampersands and quotes
|
||||
// The following is based on boost::io::detail::quoted_manip.hpp, but calling those functions did not work as there are too may QStrings involved
|
||||
QChar delim = '\"';
|
||||
QChar escape = '&';
|
||||
|
||||
if (value.at(0) == delim)
|
||||
{
|
||||
QString valueOriginal = value;
|
||||
value = "";
|
||||
|
||||
for (QString::const_iterator it = valueOriginal.begin() + 1; it != valueOriginal.end(); ++it)
|
||||
{
|
||||
if (*it == escape)
|
||||
++it;
|
||||
else if (*it == delim)
|
||||
break;
|
||||
value += *it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QStringList values = cache.values(key);
|
||||
values.append(settings.values(key));
|
||||
|
@ -152,9 +177,31 @@ bool Config::GameSettings::writeFile(QTextStream &stream)
|
|||
while (i.hasPrevious()) {
|
||||
i.previous();
|
||||
|
||||
// 'data=...' lines need quotes and ampersands escaping to match how boost::filesystem::path uses boost::io::quoted
|
||||
if (i.key() == QLatin1String("data"))
|
||||
{
|
||||
stream << i.key() << "=";
|
||||
|
||||
// The following is based on boost::io::detail::quoted_manip.hpp, but calling those functions did not work as there are too may QStrings involved
|
||||
QChar delim = '\"';
|
||||
QChar escape = '&';
|
||||
QString string = i.value();
|
||||
|
||||
stream << delim;
|
||||
for (QString::const_iterator it = string.begin(); it != string.end(); ++it)
|
||||
{
|
||||
if (*it == delim || *it == escape)
|
||||
stream << escape;
|
||||
stream << *it;
|
||||
}
|
||||
stream << delim;
|
||||
|
||||
stream << '\n';
|
||||
continue;
|
||||
}
|
||||
|
||||
// Quote paths with spaces
|
||||
if (i.key() == QLatin1String("data")
|
||||
|| i.key() == QLatin1String("data-local")
|
||||
if (i.key() == QLatin1String("data-local")
|
||||
|| i.key() == QLatin1String("resources"))
|
||||
{
|
||||
if (i.value().contains(QChar(' ')))
|
||||
|
@ -358,9 +405,26 @@ bool Config::GameSettings::writeFileWithComments(QFile &file)
|
|||
{
|
||||
it.previous();
|
||||
|
||||
if (it.key() == QLatin1String("data"))
|
||||
{
|
||||
settingLine = it.key() + "=";
|
||||
|
||||
// The following is based on boost::io::detail::quoted_manip.hpp, but calling those functions did not work as there are too may QStrings involved
|
||||
QChar delim = '\"';
|
||||
QChar escape = '&';
|
||||
QString string = it.value();
|
||||
|
||||
settingLine += delim;
|
||||
for (QString::const_iterator iter = string.begin(); iter != string.end(); ++iter)
|
||||
{
|
||||
if (*iter == delim || *iter == escape)
|
||||
settingLine += escape;
|
||||
settingLine += *iter;
|
||||
}
|
||||
settingLine += delim;
|
||||
}
|
||||
// Quote paths with spaces
|
||||
if ((it.key() == QLatin1String("data")
|
||||
|| it.key() == QLatin1String("data-local")
|
||||
else if ((it.key() == QLatin1String("data-local")
|
||||
|| it.key() == QLatin1String("resources")) && it.value().contains(QChar(' ')))
|
||||
{
|
||||
QString stripped = it.value();
|
||||
|
|
|
@ -75,8 +75,6 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs, bool cre
|
|||
for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it)
|
||||
{
|
||||
path = it->string();
|
||||
boost::erase_all(path, "\"");
|
||||
*it = boost::filesystem::path(path);
|
||||
|
||||
// Check if path contains a token
|
||||
if (!path.empty() && *path.begin() == '?')
|
||||
|
|
Loading…
Reference in a new issue