1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 20:29:57 +00:00
openmw/components/config/gamesettings.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
3 KiB
C++
Raw Normal View History

#ifndef GAMESETTINGS_HPP
#define GAMESETTINGS_HPP
#include <QFile>
2020-06-24 10:51:26 +00:00
#include <QMultiMap>
2013-02-25 21:00:51 +00:00
#include <QString>
#include <QStringList>
#include <QTextStream>
#include <filesystem>
namespace Files
{
typedef std::vector<std::filesystem::path> PathContainer;
struct ConfigurationManager;
}
namespace Config
{
2013-10-25 16:17:26 +00:00
class GameSettings
{
2013-10-25 16:17:26 +00:00
public:
explicit GameSettings(const Files::ConfigurationManager& cfg);
2013-10-25 16:17:26 +00:00
inline QString value(const QString& key, const QString& defaultValue = QString())
{
return mSettings.value(key).isEmpty() ? defaultValue : mSettings.value(key);
}
2013-10-25 16:17:26 +00:00
inline void setValue(const QString& key, const QString& value)
{
2020-06-24 10:51:26 +00:00
mSettings.remove(key);
2013-10-25 16:17:26 +00:00
mSettings.insert(key, value);
2020-06-24 10:51:26 +00:00
mUserSettings.remove(key);
mUserSettings.insert(key, value);
2013-10-25 16:17:26 +00:00
}
2013-10-25 16:17:26 +00:00
inline void setMultiValue(const QString& key, const QString& value)
{
QStringList values = mSettings.values(key);
if (!values.contains(value))
2020-06-24 10:51:26 +00:00
mSettings.insert(key, value);
values = mUserSettings.values(key);
if (!values.contains(value))
2020-06-24 10:51:26 +00:00
mUserSettings.insert(key, value);
2013-10-25 16:17:26 +00:00
}
2013-10-25 16:17:26 +00:00
inline void remove(const QString& key)
{
mSettings.remove(key);
mUserSettings.remove(key);
2013-10-25 16:17:26 +00:00
}
QStringList getDataDirs() const;
std::filesystem::path getGlobalDataDir() const;
inline void removeDataDir(const QString& dir)
{
if (!dir.isEmpty())
mDataDirs.removeAll(dir);
}
inline void addDataDir(const QString& dir)
{
if (!dir.isEmpty())
mDataDirs.append(dir);
2022-09-22 18:26:05 +00:00
}
2021-01-01 15:54:45 +00:00
inline QString getDataLocal() const { return mDataLocal; }
bool hasMaster();
QStringList values(const QString& key, const QStringList& defaultValues = QStringList()) const;
bool readFile(QTextStream& stream, bool ignoreContent = false);
bool readFile(QTextStream& stream, QMultiMap<QString, QString>& settings, bool ignoreContent = false);
bool readUserFile(QTextStream& stream, bool ignoreContent = false);
2013-10-25 16:17:26 +00:00
bool writeFile(QTextStream& stream);
bool writeFileWithComments(QFile& file);
QStringList getArchiveList() const;
void setContentList(const QStringList& dirNames, const QStringList& archiveNames, const QStringList& fileNames);
QStringList getContentList() const;
void clear();
2013-10-25 16:17:26 +00:00
private:
const Files::ConfigurationManager& mCfgMgr;
2013-10-25 16:17:26 +00:00
void validatePaths();
2020-06-24 10:51:26 +00:00
QMultiMap<QString, QString> mSettings;
QMultiMap<QString, QString> mUserSettings;
2013-10-25 16:17:26 +00:00
QStringList mDataDirs;
QString mDataLocal;
static const char sArchiveKey[];
static const char sContentKey[];
static const char sDirectoryKey[];
2020-10-22 22:03:14 +00:00
static bool isOrderedLine(const QString& line);
2013-10-25 16:17:26 +00:00
};
}
#endif // GAMESETTINGS_HPP