mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
Make path settings have path type
This commit is contained in:
parent
f57851587d
commit
538314b03a
@ -89,10 +89,10 @@ std::pair<Files::PathContainer, std::vector<std::string> > CS::Editor::readConfi
|
|||||||
|
|
||||||
desc.add_options()
|
desc.add_options()
|
||||||
("data", boost::program_options::value<Files::EscapePathContainer>()->default_value(Files::EscapePathContainer(), "data")->multitoken()->composing())
|
("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))
|
("fs-strict", boost::program_options::value<bool>()->implicit_value(true)->default_value(false))
|
||||||
("encoding", boost::program_options::value<Files::EscapeHashString>()->default_value("win1252"))
|
("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>()->
|
("fallback-archive", boost::program_options::value<Files::EscapeStringVector>()->
|
||||||
default_value(Files::EscapeStringVector(), "fallback-archive")->multitoken())
|
default_value(Files::EscapeStringVector(), "fallback-archive")->multitoken())
|
||||||
("fallback", boost::program_options::value<FallbackMap>()->default_value(FallbackMap(), "")
|
("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));
|
mDocumentManager.setEncoding(ToUTF8::calculateEncoding(mEncodingName));
|
||||||
mFileDialog.setEncoding (QString::fromUtf8(mEncodingName.c_str()));
|
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>())
|
if (variables["script-blacklist-use"].as<bool>())
|
||||||
mDocumentManager.setBlacklistedScripts (
|
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>()));
|
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.empty())
|
||||||
{
|
dataLocal.push_back(local);
|
||||||
if (local.front() == '\"')
|
|
||||||
local = local.substr(1, local.length() - 2);
|
|
||||||
|
|
||||||
dataLocal.push_back(Files::PathContainer::value_type(local));
|
|
||||||
}
|
|
||||||
|
|
||||||
mCfgMgr.processPaths (dataDirs);
|
mCfgMgr.processPaths (dataDirs);
|
||||||
mCfgMgr.processPaths (dataLocal, true);
|
mCfgMgr.processPaths (dataLocal, true);
|
||||||
|
@ -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")
|
("data", bpo::value<Files::EscapePathContainer>()->default_value(Files::EscapePathContainer(), "data")
|
||||||
->multitoken()->composing(), "set data directories (later directories have higher priority)")
|
->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)")
|
"set local data directory (highest priority)")
|
||||||
|
|
||||||
("fallback-archive", bpo::value<Files::EscapeStringVector>()->default_value(Files::EscapeStringVector(), "fallback-archive")
|
("fallback-archive", bpo::value<Files::EscapeStringVector>()->default_value(Files::EscapeStringVector(), "fallback-archive")
|
||||||
->multitoken()->composing(), "set fallback BSA archives (later archives have higher priority)")
|
->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")
|
"set resources directory")
|
||||||
|
|
||||||
("start", bpo::value<Files::EscapeHashString>()->default_value(""),
|
("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)
|
("script-blacklist-use", bpo::value<bool>()->implicit_value(true)
|
||||||
->default_value(true), "enable script blacklisting")
|
->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)")
|
"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)
|
("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);
|
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;
|
std::cout << v.describe() << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
|||||||
cfgMgr.readConfiguration(variables, desc);
|
cfgMgr.readConfiguration(variables, desc);
|
||||||
cfgMgr.mergeComposingVariables(variables, composingVariables, 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;
|
std::cout << v.describe() << std::endl;
|
||||||
|
|
||||||
engine.setGrabMouse(!variables["no-grab"].as<bool>());
|
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>()));
|
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.empty())
|
||||||
{
|
dataDirs.push_back(local);
|
||||||
if (local.front() == '\"')
|
|
||||||
local = local.substr(1, local.length() - 2);
|
|
||||||
|
|
||||||
dataDirs.push_back(Files::PathContainer::value_type(local));
|
|
||||||
}
|
|
||||||
|
|
||||||
cfgMgr.processPaths(dataDirs);
|
cfgMgr.processPaths(dataDirs);
|
||||||
|
|
||||||
engine.setResourceDir(variables["resources"].as<Files::EscapeHashString>().toStdString());
|
engine.setResourceDir(variables["resources"].as<Files::EscapePath>().mPath);
|
||||||
engine.setDataDirs(dataDirs);
|
engine.setDataDirs(dataDirs);
|
||||||
|
|
||||||
// fallback archives
|
// 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.setWarningsMode (variables["script-warn"].as<int>());
|
||||||
engine.setScriptBlacklist (variables["script-blacklist"].as<Files::EscapeStringVector>().toStdStringVector());
|
engine.setScriptBlacklist (variables["script-blacklist"].as<Files::EscapeStringVector>().toStdStringVector());
|
||||||
engine.setScriptBlacklistUse (variables["script-blacklist-use"].as<bool>());
|
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
|
// other settings
|
||||||
Fallback::Map::init(variables["fallback"].as<FallbackMap>().mMap);
|
Fallback::Map::init(variables["fallback"].as<FallbackMap>().mMap);
|
||||||
|
@ -118,12 +118,19 @@ bool Config::GameSettings::readFile(QTextStream &stream, QMultiMap<QString, QStr
|
|||||||
QString key = keyRe.cap(1).trimmed();
|
QString key = keyRe.cap(1).trimmed();
|
||||||
QString value = keyRe.cap(2).trimmed();
|
QString value = keyRe.cap(2).trimmed();
|
||||||
|
|
||||||
// Don't remove existing data entries
|
// Don't remove composing entries
|
||||||
if (key != QLatin1String("data"))
|
if (key != QLatin1String("data")
|
||||||
|
&& key != QLatin1String("fallback-archive")
|
||||||
|
&& key != QLatin1String("content")
|
||||||
|
&& key != QLatin1String("script-blacklist"))
|
||||||
settings.remove(key);
|
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
|
// 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 delim = '\"';
|
||||||
QChar escape = '&';
|
QChar escape = '&';
|
||||||
@ -175,8 +182,11 @@ bool Config::GameSettings::writeFile(QTextStream &stream)
|
|||||||
while (i.hasPrevious()) {
|
while (i.hasPrevious()) {
|
||||||
i.previous();
|
i.previous();
|
||||||
|
|
||||||
// 'data=...' lines need quotes and ampersands escaping to match how boost::filesystem::path uses boost::io::quoted
|
// 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"))
|
if (i.key() == QLatin1String("data")
|
||||||
|
|| i.key() == QLatin1String("data-local")
|
||||||
|
|| i.key() == QLatin1String("resources")
|
||||||
|
|| i.key() == QLatin1String("load-savegame"))
|
||||||
{
|
{
|
||||||
stream << i.key() << "=";
|
stream << i.key() << "=";
|
||||||
|
|
||||||
@ -198,20 +208,6 @@ bool Config::GameSettings::writeFile(QTextStream &stream)
|
|||||||
continue;
|
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";
|
stream << i.key() << "=" << i.value() << "\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -406,7 +402,10 @@ bool Config::GameSettings::writeFileWithComments(QFile &file)
|
|||||||
{
|
{
|
||||||
it.previous();
|
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() + "=";
|
settingLine = it.key() + "=";
|
||||||
|
|
||||||
@ -424,15 +423,6 @@ bool Config::GameSettings::writeFileWithComments(QFile &file)
|
|||||||
}
|
}
|
||||||
settingLine += delim;
|
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
|
else
|
||||||
settingLine = it.key() + "=" + it.value();
|
settingLine = it.key() + "=" + it.value();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user