2013-01-25 04:19:06 +00:00
|
|
|
#ifndef GAMESETTINGS_HPP
|
|
|
|
#define GAMESETTINGS_HPP
|
|
|
|
|
2015-06-14 04:51:01 +00:00
|
|
|
#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>
|
2013-01-25 04:19:06 +00:00
|
|
|
|
2022-06-11 17:23:44 +00:00
|
|
|
#include <filesystem>
|
|
|
|
|
2013-10-27 19:03:12 +00:00
|
|
|
namespace Files
|
|
|
|
{
|
2022-06-08 21:25:50 +00:00
|
|
|
typedef std::vector<std::filesystem::path> PathContainer;
|
2013-10-27 19:03:12 +00:00
|
|
|
struct ConfigurationManager;
|
|
|
|
}
|
2013-01-26 17:19:04 +00:00
|
|
|
|
2013-12-24 23:50:25 +00:00
|
|
|
namespace Config
|
2013-01-25 04:19:06 +00:00
|
|
|
{
|
2013-10-25 16:17:26 +00:00
|
|
|
class GameSettings
|
2013-01-26 17:19:04 +00:00
|
|
|
{
|
2013-10-25 16:17:26 +00:00
|
|
|
public:
|
2023-03-21 20:27:25 +00:00
|
|
|
explicit GameSettings(const Files::ConfigurationManager& cfg);
|
2013-01-26 17:19:04 +00:00
|
|
|
|
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-01-26 17:19:04 +00:00
|
|
|
|
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);
|
2013-12-16 19:40:58 +00:00
|
|
|
mUserSettings.insert(key, value);
|
2013-10-25 16:17:26 +00:00
|
|
|
}
|
2013-02-18 22:10:50 +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);
|
2013-12-16 19:40:58 +00:00
|
|
|
|
|
|
|
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-02-18 22:10:50 +00:00
|
|
|
|
2013-10-25 16:17:26 +00:00
|
|
|
inline void remove(const QString& key)
|
|
|
|
{
|
|
|
|
mSettings.remove(key);
|
2013-12-16 19:40:58 +00:00
|
|
|
mUserSettings.remove(key);
|
2013-10-25 16:17:26 +00:00
|
|
|
}
|
2013-01-26 17:19:04 +00:00
|
|
|
|
2020-04-26 13:31:39 +00:00
|
|
|
QStringList getDataDirs() const;
|
2022-06-19 11:28:33 +00:00
|
|
|
std::filesystem::path getGlobalDataDir() const;
|
2014-02-25 14:33:30 +00:00
|
|
|
|
|
|
|
inline void removeDataDir(const QString& dir)
|
|
|
|
{
|
|
|
|
if (!dir.isEmpty())
|
|
|
|
mDataDirs.removeAll(dir);
|
2013-11-02 14:31:23 +00:00
|
|
|
}
|
|
|
|
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; }
|
2013-10-27 19:03:12 +00:00
|
|
|
|
2013-11-02 14:31:23 +00:00
|
|
|
bool hasMaster();
|
2013-01-26 17:19:04 +00:00
|
|
|
|
2015-01-10 05:46:47 +00:00
|
|
|
QStringList values(const QString& key, const QStringList& defaultValues = QStringList()) const;
|
2013-12-16 19:40:58 +00:00
|
|
|
|
2022-06-30 18:57:51 +00:00
|
|
|
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-12-16 19:40:58 +00:00
|
|
|
|
2013-10-25 16:17:26 +00:00
|
|
|
bool writeFile(QTextStream& stream);
|
2015-06-14 04:51:01 +00:00
|
|
|
bool writeFileWithComments(QFile& file);
|
2013-01-26 17:19:04 +00:00
|
|
|
|
2020-04-26 13:31:39 +00:00
|
|
|
QStringList getArchiveList() const;
|
|
|
|
void setContentList(const QStringList& dirNames, const QStringList& archiveNames, const QStringList& fileNames);
|
2015-01-10 05:46:47 +00:00
|
|
|
QStringList getContentList() const;
|
|
|
|
|
2015-11-27 19:52:29 +00:00
|
|
|
void clear();
|
|
|
|
|
2013-10-25 16:17:26 +00:00
|
|
|
private:
|
2023-03-21 20:27:25 +00:00
|
|
|
const Files::ConfigurationManager& mCfgMgr;
|
2013-01-26 17:19:04 +00:00
|
|
|
|
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-01-25 04:19:06 +00:00
|
|
|
|
2013-10-25 16:17:26 +00:00
|
|
|
QStringList mDataDirs;
|
|
|
|
QString mDataLocal;
|
2015-01-10 05:46:47 +00:00
|
|
|
|
2020-04-26 13:31:39 +00:00
|
|
|
static const char sArchiveKey[];
|
2015-01-10 05:46:47 +00:00
|
|
|
static const char sContentKey[];
|
2020-04-26 13:31:39 +00:00
|
|
|
static const char sDirectoryKey[];
|
2015-06-14 04:51:01 +00:00
|
|
|
|
2020-10-22 22:03:14 +00:00
|
|
|
static bool isOrderedLine(const QString& line);
|
2013-10-25 16:17:26 +00:00
|
|
|
};
|
|
|
|
}
|
2013-01-25 04:19:06 +00:00
|
|
|
#endif // GAMESETTINGS_HPP
|