mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-29 22:45:36 +00:00
Join path components using path::operator/ instead of string::operator+
This commit is contained in:
parent
0f9bb71534
commit
0961720835
6 changed files with 48 additions and 25 deletions
|
@ -12,7 +12,9 @@
|
|||
|
||||
#include <boost/program_options/options_description.hpp>
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
|
||||
#include <components/files/conversion.hpp>
|
||||
#include <components/files/qtconfigpath.hpp>
|
||||
#include <components/files/qtconversion.hpp>
|
||||
#include <components/misc/utf8qtextstream.hpp>
|
||||
|
||||
|
@ -286,11 +288,9 @@ bool Launcher::MainDialog::setupLauncherSettings()
|
|||
|
||||
mLauncherSettings.setMultiValueEnabled(true);
|
||||
|
||||
const auto userPath = Files::pathToQString(mCfgMgr.getUserConfigPath());
|
||||
|
||||
QStringList paths;
|
||||
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)
|
||||
{
|
||||
|
@ -322,10 +322,6 @@ bool Launcher::MainDialog::setupGameSettings()
|
|||
{
|
||||
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;
|
||||
|
||||
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
|
||||
// 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;
|
||||
|
||||
// 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
|
||||
if (!*result && !loadFile(globalPath + QString("openmw.cfg"), &Config::GameSettings::readFile, true))
|
||||
if (!*result && !loadFile(Files::getGlobalConfigPathQString(mCfgMgr), &Config::GameSettings::readFile, true))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
if (!loadFile(userPath + QString("openmw.cfg"), &Config::GameSettings::readFile))
|
||||
if (!loadFile(Files::getUserConfigPathQString(mCfgMgr), &Config::GameSettings::readFile))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
@ -495,9 +491,9 @@ bool Launcher::MainDialog::writeSettings()
|
|||
|
||||
// Game settings
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QFile file(userPath / "openmw.cfg");
|
||||
QFile file(userPath / Files::openmwCfgFile);
|
||||
#else
|
||||
QFile file(Files::pathToQString(userPath / "openmw.cfg"));
|
||||
QFile file(Files::getUserConfigPathQString(mCfgMgr));
|
||||
#endif
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
|
||||
#include <components/files/qtconfigpath.hpp>
|
||||
#include <components/files/qtconversion.hpp>
|
||||
#include <components/misc/utf8qtextstream.hpp>
|
||||
#include <components/process/processinvoker.hpp>
|
||||
|
@ -137,8 +138,6 @@ void Wizard::MainWizard::addLogText(const QString& text)
|
|||
|
||||
void Wizard::MainWizard::setupGameSettings()
|
||||
{
|
||||
QString userPath(Files::pathToQString(mCfgMgr.getUserConfigPath()));
|
||||
QString globalPath(Files::pathToQString(mCfgMgr.getGlobalPath()));
|
||||
QString message(
|
||||
tr("<html><head/><body><p><b>Could not open %1 for reading</b></p> \
|
||||
<p>Please make sure you have the right permissions \
|
||||
|
@ -146,7 +145,7 @@ void Wizard::MainWizard::setupGameSettings()
|
|||
|
||||
// Load the user config file first, separately
|
||||
// So we can write it properly, uncontaminated
|
||||
QString path(userPath + QLatin1String("openmw.cfg"));
|
||||
QString path(Files::getUserConfigPathQString(mCfgMgr));
|
||||
QFile file(path);
|
||||
|
||||
qDebug() << "Loading config file:" << path.toUtf8().constData();
|
||||
|
@ -174,9 +173,9 @@ void Wizard::MainWizard::setupGameSettings()
|
|||
|
||||
// Now the rest
|
||||
QStringList paths;
|
||||
paths.append(userPath + QLatin1String("openmw.cfg"));
|
||||
paths.append(Files::getUserConfigPathQString(mCfgMgr));
|
||||
paths.append(QLatin1String("openmw.cfg"));
|
||||
paths.append(globalPath + QLatin1String("openmw.cfg"));
|
||||
paths.append(Files::getGlobalConfigPathQString(mCfgMgr));
|
||||
|
||||
for (const QString& path2 : paths)
|
||||
{
|
||||
|
@ -258,8 +257,7 @@ void Wizard::MainWizard::runSettingsImporter()
|
|||
|
||||
QString path(field(QLatin1String("installation.path")).toString());
|
||||
|
||||
QString userPath(Files::pathToQString(mCfgMgr.getUserConfigPath()));
|
||||
QFile file(userPath + QLatin1String("openmw.cfg"));
|
||||
QFile file(Files::getUserConfigPathQString(mCfgMgr));
|
||||
|
||||
// Construct the arguments to run the importer
|
||||
QStringList arguments;
|
||||
|
@ -304,7 +302,7 @@ void Wizard::MainWizard::runSettingsImporter()
|
|||
}
|
||||
|
||||
arguments.append(QLatin1String("--cfg"));
|
||||
arguments.append(userPath + QLatin1String("openmw.cfg"));
|
||||
arguments.append(Files::getUserConfigPathQString(mCfgMgr));
|
||||
|
||||
if (!mImporterInvoker->startProcess(QLatin1String("openmw-iniimporter"), arguments, false))
|
||||
return qApp->quit();
|
||||
|
@ -440,7 +438,7 @@ void Wizard::MainWizard::writeSettings()
|
|||
}
|
||||
|
||||
// Game settings
|
||||
QFile file(userPath + QLatin1String("openmw.cfg"));
|
||||
QFile file(Files::getUserConfigPathQString(mCfgMgr));
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate))
|
||||
{
|
||||
|
@ -466,7 +464,8 @@ void Wizard::MainWizard::writeSettings()
|
|||
file.close();
|
||||
|
||||
// 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))
|
||||
{
|
||||
|
|
|
@ -383,6 +383,7 @@ if (USE_QT)
|
|||
|
||||
add_component_qt_dir (files
|
||||
qtconversion
|
||||
qtconfigpath
|
||||
)
|
||||
|
||||
QT5_WRAP_UI(ESM_UI_HDR ${ESM_UI})
|
||||
|
|
|
@ -18,8 +18,6 @@ namespace Files
|
|||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
static const char* const openmwCfgFile = "openmw.cfg";
|
||||
|
||||
#if defined(_WIN32) || defined(__WINDOWS__)
|
||||
static const char* const applicationName = "OpenMW";
|
||||
#else
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <map>
|
||||
#include <optional>
|
||||
#include <stack>
|
||||
#include <string_view>
|
||||
|
||||
#include <components/files/collections.hpp>
|
||||
#include <components/files/fixedpath.hpp>
|
||||
|
@ -19,6 +20,7 @@ namespace boost::program_options
|
|||
*/
|
||||
namespace Files
|
||||
{
|
||||
inline constexpr std::string_view openmwCfgFile = "openmw.cfg";
|
||||
|
||||
/**
|
||||
* \struct ConfigurationManager
|
||||
|
|
27
components/files/qtconfigpath.hpp
Normal file
27
components/files/qtconfigpath.hpp
Normal file
|
@ -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…
Reference in a new issue