Merge branch 'join_path' into 'master'

Join path components using path::operator/ instead of string::operator+

See merge request OpenMW/openmw!2652
7220-lua-add-a-general-purpose-lexical-parser
psi29a 2 years ago
commit 22c62a8c38

@ -12,7 +12,9 @@
#include <boost/program_options/options_description.hpp> #include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
#include <components/files/conversion.hpp> #include <components/files/conversion.hpp>
#include <components/files/qtconfigpath.hpp>
#include <components/files/qtconversion.hpp> #include <components/files/qtconversion.hpp>
#include <components/misc/utf8qtextstream.hpp> #include <components/misc/utf8qtextstream.hpp>
@ -286,11 +288,9 @@ bool Launcher::MainDialog::setupLauncherSettings()
mLauncherSettings.setMultiValueEnabled(true); mLauncherSettings.setMultiValueEnabled(true);
const auto userPath = Files::pathToQString(mCfgMgr.getUserConfigPath());
QStringList paths; QStringList paths;
paths.append(QString(Config::LauncherSettings::sLauncherConfigFileName)); paths.append(QString(Config::LauncherSettings::sLauncherConfigFileName));
paths.append(userPath + QString(Config::LauncherSettings::sLauncherConfigFileName)); paths.append(Files::pathToQString(mCfgMgr.getUserConfigPath() / Config::LauncherSettings::sLauncherConfigFileName));
for (const QString& path : paths) for (const QString& path : paths)
{ {
@ -322,10 +322,6 @@ bool Launcher::MainDialog::setupGameSettings()
{ {
mGameSettings.clear(); mGameSettings.clear();
const auto localPath = Files::pathToQString(mCfgMgr.getLocalPath());
const auto userPath = Files::pathToQString(mCfgMgr.getUserConfigPath());
const auto globalPath = Files::pathToQString(mCfgMgr.getGlobalPath());
QFile file; QFile file;
auto loadFile = [&](const QString& path, bool (Config::GameSettings::*reader)(QTextStream&, bool), auto loadFile = [&](const QString& path, bool (Config::GameSettings::*reader)(QTextStream&, bool),
@ -355,19 +351,19 @@ bool Launcher::MainDialog::setupGameSettings()
// Load the user config file first, separately // Load the user config file first, separately
// So we can write it properly, uncontaminated // So we can write it properly, uncontaminated
if (!loadFile(userPath + QLatin1String("openmw.cfg"), &Config::GameSettings::readUserFile)) if (!loadFile(Files::getUserConfigPathQString(mCfgMgr), &Config::GameSettings::readUserFile))
return false; return false;
// Now the rest - priority: user > local > global // Now the rest - priority: user > local > global
if (auto result = loadFile(localPath + QString("openmw.cfg"), &Config::GameSettings::readFile, true)) if (auto result = loadFile(Files::getLocalConfigPathQString(mCfgMgr), &Config::GameSettings::readFile, true))
{ {
// Load global if local wasn't found // Load global if local wasn't found
if (!*result && !loadFile(globalPath + QString("openmw.cfg"), &Config::GameSettings::readFile, true)) if (!*result && !loadFile(Files::getGlobalConfigPathQString(mCfgMgr), &Config::GameSettings::readFile, true))
return false; return false;
} }
else else
return false; return false;
if (!loadFile(userPath + QString("openmw.cfg"), &Config::GameSettings::readFile)) if (!loadFile(Files::getUserConfigPathQString(mCfgMgr), &Config::GameSettings::readFile))
return false; return false;
return true; return true;
@ -495,9 +491,9 @@ bool Launcher::MainDialog::writeSettings()
// Game settings // Game settings
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QFile file(userPath / "openmw.cfg"); QFile file(userPath / Files::openmwCfgFile);
#else #else
QFile file(Files::pathToQString(userPath / "openmw.cfg")); QFile file(Files::getUserConfigPathQString(mCfgMgr));
#endif #endif
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) if (!file.open(QIODevice::ReadWrite | QIODevice::Text))

@ -6,6 +6,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QProcess> #include <QProcess>
#include <components/files/qtconfigpath.hpp>
#include <components/files/qtconversion.hpp> #include <components/files/qtconversion.hpp>
#include <components/misc/utf8qtextstream.hpp> #include <components/misc/utf8qtextstream.hpp>
#include <components/process/processinvoker.hpp> #include <components/process/processinvoker.hpp>
@ -137,8 +138,6 @@ void Wizard::MainWizard::addLogText(const QString& text)
void Wizard::MainWizard::setupGameSettings() void Wizard::MainWizard::setupGameSettings()
{ {
QString userPath(Files::pathToQString(mCfgMgr.getUserConfigPath()));
QString globalPath(Files::pathToQString(mCfgMgr.getGlobalPath()));
QString message( QString message(
tr("<html><head/><body><p><b>Could not open %1 for reading</b></p> \ tr("<html><head/><body><p><b>Could not open %1 for reading</b></p> \
<p>Please make sure you have the right permissions \ <p>Please make sure you have the right permissions \
@ -146,7 +145,7 @@ void Wizard::MainWizard::setupGameSettings()
// Load the user config file first, separately // Load the user config file first, separately
// So we can write it properly, uncontaminated // So we can write it properly, uncontaminated
QString path(userPath + QLatin1String("openmw.cfg")); QString path(Files::getUserConfigPathQString(mCfgMgr));
QFile file(path); QFile file(path);
qDebug() << "Loading config file:" << path.toUtf8().constData(); qDebug() << "Loading config file:" << path.toUtf8().constData();
@ -174,9 +173,9 @@ void Wizard::MainWizard::setupGameSettings()
// Now the rest // Now the rest
QStringList paths; QStringList paths;
paths.append(userPath + QLatin1String("openmw.cfg")); paths.append(Files::getUserConfigPathQString(mCfgMgr));
paths.append(QLatin1String("openmw.cfg")); paths.append(QLatin1String("openmw.cfg"));
paths.append(globalPath + QLatin1String("openmw.cfg")); paths.append(Files::getGlobalConfigPathQString(mCfgMgr));
for (const QString& path2 : paths) for (const QString& path2 : paths)
{ {
@ -258,8 +257,7 @@ void Wizard::MainWizard::runSettingsImporter()
QString path(field(QLatin1String("installation.path")).toString()); QString path(field(QLatin1String("installation.path")).toString());
QString userPath(Files::pathToQString(mCfgMgr.getUserConfigPath())); QFile file(Files::getUserConfigPathQString(mCfgMgr));
QFile file(userPath + QLatin1String("openmw.cfg"));
// Construct the arguments to run the importer // Construct the arguments to run the importer
QStringList arguments; QStringList arguments;
@ -304,7 +302,7 @@ void Wizard::MainWizard::runSettingsImporter()
} }
arguments.append(QLatin1String("--cfg")); arguments.append(QLatin1String("--cfg"));
arguments.append(userPath + QLatin1String("openmw.cfg")); arguments.append(Files::getUserConfigPathQString(mCfgMgr));
if (!mImporterInvoker->startProcess(QLatin1String("openmw-iniimporter"), arguments, false)) if (!mImporterInvoker->startProcess(QLatin1String("openmw-iniimporter"), arguments, false))
return qApp->quit(); return qApp->quit();
@ -440,7 +438,7 @@ void Wizard::MainWizard::writeSettings()
} }
// Game settings // Game settings
QFile file(userPath + QLatin1String("openmw.cfg")); QFile file(Files::getUserConfigPathQString(mCfgMgr));
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate))
{ {
@ -466,7 +464,8 @@ void Wizard::MainWizard::writeSettings()
file.close(); file.close();
// Launcher settings // Launcher settings
file.setFileName(userPath + QLatin1String(Config::LauncherSettings::sLauncherConfigFileName)); file.setFileName(
Files::pathToQString(mCfgMgr.getUserConfigPath() / Config::LauncherSettings::sLauncherConfigFileName));
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate))
{ {

@ -383,6 +383,7 @@ if (USE_QT)
add_component_qt_dir (files add_component_qt_dir (files
qtconversion qtconversion
qtconfigpath
) )
QT5_WRAP_UI(ESM_UI_HDR ${ESM_UI}) QT5_WRAP_UI(ESM_UI_HDR ${ESM_UI})

@ -18,8 +18,6 @@ namespace Files
namespace bpo = boost::program_options; namespace bpo = boost::program_options;
static const char* const openmwCfgFile = "openmw.cfg";
#if defined(_WIN32) || defined(__WINDOWS__) #if defined(_WIN32) || defined(__WINDOWS__)
static const char* const applicationName = "OpenMW"; static const char* const applicationName = "OpenMW";
#else #else

@ -4,6 +4,7 @@
#include <map> #include <map>
#include <optional> #include <optional>
#include <stack> #include <stack>
#include <string_view>
#include <components/files/collections.hpp> #include <components/files/collections.hpp>
#include <components/files/fixedpath.hpp> #include <components/files/fixedpath.hpp>
@ -19,6 +20,7 @@ namespace boost::program_options
*/ */
namespace Files namespace Files
{ {
inline constexpr std::string_view openmwCfgFile = "openmw.cfg";
/** /**
* \struct ConfigurationManager * \struct ConfigurationManager

@ -0,0 +1,27 @@
#ifndef OPENMW_COMPONENTS_FILES_QTCONFIGPATH_H
#define OPENMW_COMPONENTS_FILES_QTCONFIGPATH_H
#include "configurationmanager.hpp"
#include "qtconversion.hpp"
#include <QString>
namespace Files
{
inline QString getLocalConfigPathQString(const Files::ConfigurationManager& cfgMgr)
{
return Files::pathToQString(cfgMgr.getLocalPath() / openmwCfgFile);
}
inline QString getUserConfigPathQString(const Files::ConfigurationManager& cfgMgr)
{
return Files::pathToQString(cfgMgr.getUserConfigPath() / openmwCfgFile);
}
inline QString getGlobalConfigPathQString(const Files::ConfigurationManager& cfgMgr)
{
return Files::pathToQString(cfgMgr.getGlobalPath() / openmwCfgFile);
}
}
#endif // OPENMW_COMPONENTS_FILES_QTCONFIGPATH_H
Loading…
Cancel
Save