1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 15:35:23 +00:00

Make path settings have path type

This commit is contained in:
AnyOldName3 2020-10-23 15:34:41 +01:00
parent f57851587d
commit 538314b03a
3 changed files with 34 additions and 54 deletions

View File

@ -89,10 +89,10 @@ std::pair<Files::PathContainer, std::vector<std::string> > CS::Editor::readConfi
desc.add_options()
("data", boost::program_options::value<Files::EscapePathContainer>()->default_value(Files::EscapePathContainer(), "data")->multitoken()->composing())
("data-local", boost::program_options::value<Files::EscapeHashString>()->default_value(""))
("data-local", boost::program_options::value<Files::EscapePath>()->default_value(Files::EscapePath(), ""))
("fs-strict", boost::program_options::value<bool>()->implicit_value(true)->default_value(false))
("encoding", boost::program_options::value<Files::EscapeHashString>()->default_value("win1252"))
("resources", boost::program_options::value<Files::EscapeHashString>()->default_value("resources"))
("resources", boost::program_options::value<Files::EscapePath>()->default_value(Files::EscapePath(), "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(), "")
@ -112,7 +112,7 @@ std::pair<Files::PathContainer, std::vector<std::string> > CS::Editor::readConfi
mDocumentManager.setEncoding(ToUTF8::calculateEncoding(mEncodingName));
mFileDialog.setEncoding (QString::fromUtf8(mEncodingName.c_str()));
mDocumentManager.setResourceDir (mResources = variables["resources"].as<Files::EscapeHashString>().toStdString());
mDocumentManager.setResourceDir (mResources = variables["resources"].as<Files::EscapePath>().mPath);
if (variables["script-blacklist-use"].as<bool>())
mDocumentManager.setBlacklistedScripts (
@ -125,14 +125,9 @@ std::pair<Files::PathContainer, std::vector<std::string> > CS::Editor::readConfi
dataDirs = Files::PathContainer(Files::EscapePath::toPathContainer(variables["data"].as<Files::EscapePathContainer>()));
}
std::string local = variables["data-local"].as<Files::EscapeHashString>().toStdString();
Files::PathContainer::value_type local(variables["data-local"].as<Files::EscapePath>().mPath);
if (!local.empty())
{
if (local.front() == '\"')
local = local.substr(1, local.length() - 2);
dataLocal.push_back(Files::PathContainer::value_type(local));
}
dataLocal.push_back(local);
mCfgMgr.processPaths (dataDirs);
mCfgMgr.processPaths (dataLocal, true);

View File

@ -63,13 +63,13 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
("data", bpo::value<Files::EscapePathContainer>()->default_value(Files::EscapePathContainer(), "data")
->multitoken()->composing(), "set data directories (later directories have higher priority)")
("data-local", bpo::value<Files::EscapeHashString>()->default_value(""),
("data-local", bpo::value<Files::EscapePath>()->default_value(Files::EscapePath(), ""),
"set local data directory (highest priority)")
("fallback-archive", bpo::value<Files::EscapeStringVector>()->default_value(Files::EscapeStringVector(), "fallback-archive")
->multitoken()->composing(), "set fallback BSA archives (later archives have higher priority)")
("resources", bpo::value<Files::EscapeHashString>()->default_value("resources"),
("resources", bpo::value<Files::EscapePath>()->default_value(Files::EscapePath(), "resources"),
"set resources directory")
("start", bpo::value<Files::EscapeHashString>()->default_value(""),
@ -106,7 +106,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
("script-blacklist-use", bpo::value<bool>()->implicit_value(true)
->default_value(true), "enable script blacklisting")
("load-savegame", bpo::value<Files::EscapeHashString>()->default_value(""),
("load-savegame", bpo::value<Files::EscapePath>()->default_value(Files::EscapePath(), ""),
"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<bool>()->implicit_value(true)
@ -159,7 +159,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<Files::EscapeHashString>().toStdString());
Version::Version v = Version::getOpenmwVersion(variables["resources"].as<Files::EscapePath>().mPath.string());
std::cout << v.describe() << std::endl;
return false;
}
@ -168,7 +168,7 @@ 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<Files::EscapeHashString>().toStdString());
Version::Version v = Version::getOpenmwVersion(variables["resources"].as<Files::EscapePath>().mPath.string());
std::cout << v.describe() << std::endl;
engine.setGrabMouse(!variables["no-grab"].as<bool>());
@ -183,18 +183,13 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
Files::PathContainer dataDirs(Files::EscapePath::toPathContainer(variables["data"].as<Files::EscapePathContainer>()));
std::string local(variables["data-local"].as<Files::EscapeHashString>().toStdString());
Files::PathContainer::value_type local(variables["data-local"].as<Files::EscapePath>().mPath);
if (!local.empty())
{
if (local.front() == '\"')
local = local.substr(1, local.length() - 2);
dataDirs.push_back(Files::PathContainer::value_type(local));
}
dataDirs.push_back(local);
cfgMgr.processPaths(dataDirs);
engine.setResourceDir(variables["resources"].as<Files::EscapeHashString>().toStdString());
engine.setResourceDir(variables["resources"].as<Files::EscapePath>().mPath);
engine.setDataDirs(dataDirs);
// fallback archives
@ -232,7 +227,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
engine.setWarningsMode (variables["script-warn"].as<int>());
engine.setScriptBlacklist (variables["script-blacklist"].as<Files::EscapeStringVector>().toStdStringVector());
engine.setScriptBlacklistUse (variables["script-blacklist-use"].as<bool>());
engine.setSaveGameFile (variables["load-savegame"].as<Files::EscapeHashString>().toStdString());
engine.setSaveGameFile (variables["load-savegame"].as<Files::EscapePath>().mPath.string());
// other settings
Fallback::Map::init(variables["fallback"].as<FallbackMap>().mMap);

View File

@ -118,12 +118,19 @@ bool Config::GameSettings::readFile(QTextStream &stream, QMultiMap<QString, QStr
QString key = keyRe.cap(1).trimmed();
QString value = keyRe.cap(2).trimmed();
// Don't remove existing data entries
if (key != QLatin1String("data"))
// Don't remove composing entries
if (key != QLatin1String("data")
&& key != QLatin1String("fallback-archive")
&& key != QLatin1String("content")
&& key != QLatin1String("script-blacklist"))
settings.remove(key);
else
if (key == QLatin1String("data")
|| key == QLatin1String("data-local")
|| key == QLatin1String("resources")
|| key == QLatin1String("load-savegame"))
{
// 'data=...' line, so needs processing to deal with ampersands and quotes
// Path line (e.g. 'data=...'), 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 = '&';
@ -175,8 +182,11 @@ 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"))
// path lines (e.g. 'data=...') need quotes and ampersands escaping to match how boost::filesystem::path uses boost::io::quoted
if (i.key() == QLatin1String("data")
|| i.key() == QLatin1String("data-local")
|| i.key() == QLatin1String("resources")
|| i.key() == QLatin1String("load-savegame"))
{
stream << i.key() << "=";
@ -198,20 +208,6 @@ bool Config::GameSettings::writeFile(QTextStream &stream)
continue;
}
// Quote paths with spaces
if (i.key() == QLatin1String("data-local")
|| i.key() == QLatin1String("resources"))
{
if (i.value().contains(QChar(' ')))
{
QString stripped = i.value();
stripped.remove(QChar('\"')); // Remove quotes
stream << i.key() << "=\"" << stripped << "\"\n";
continue;
}
}
stream << i.key() << "=" << i.value() << "\n";
}
@ -406,7 +402,10 @@ bool Config::GameSettings::writeFileWithComments(QFile &file)
{
it.previous();
if (it.key() == QLatin1String("data"))
if (it.key() == QLatin1String("data")
|| it.key() == QLatin1String("data-local")
|| it.key() == QLatin1String("resources")
|| it.key() == QLatin1String("load-savegame"))
{
settingLine = it.key() + "=";
@ -424,15 +423,6 @@ bool Config::GameSettings::writeFileWithComments(QFile &file)
}
settingLine += delim;
}
// Quote paths with spaces
else if ((it.key() == QLatin1String("data-local")
|| it.key() == QLatin1String("resources")) && it.value().contains(QChar(' ')))
{
QString stripped = it.value();
stripped.remove(QChar('\"')); // Remove quotes
settingLine = it.key() + "=\"" + stripped + "\"";
}
else
settingLine = it.key() + "=" + it.value();