mkxp-freebird/src/config.cpp

110 lines
2.8 KiB
C++
Raw Normal View History

2013-09-01 14:27:21 +00:00
/*
** config.cpp
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 2 of the License, or
** (at your option) any later version.
**
** mkxp is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <QSettings>
#include <QFileInfo>
#include <QString>
#include <QStringList>
#include <QFile>
#include <QRegExp>
Config::Config()
: debugMode(false),
winResizable(false),
fullscreen(false),
fixedAspectRatio(true),
2013-09-23 09:00:50 +00:00
smoothScaling(false),
2013-09-01 14:27:21 +00:00
vsync(false),
defScreenW(640),
defScreenH(480),
2013-10-17 00:18:16 +00:00
fixedFramerate(0),
2013-09-01 14:27:21 +00:00
solidFonts(false),
gameFolder(".")
{}
void Config::read()
{
QSettings confFile("mkxp.conf", QSettings::IniFormat);
#define READ_VAL(key, Type) key = confFile.value(#key, key).to##Type()
READ_VAL(debugMode, Bool);
READ_VAL(winResizable, Bool);
READ_VAL(fullscreen, Bool);
2013-09-23 08:39:16 +00:00
READ_VAL(fixedAspectRatio, Bool);
2013-09-23 09:00:50 +00:00
READ_VAL(smoothScaling, Bool);
2013-09-01 14:27:21 +00:00
READ_VAL(vsync, Bool);
READ_VAL(defScreenW, Int);
READ_VAL(defScreenH, Int);
2013-10-17 00:18:16 +00:00
READ_VAL(fixedFramerate, Int);
2013-09-01 14:27:21 +00:00
READ_VAL(solidFonts, Bool);
READ_VAL(gameFolder, ByteArray);
READ_VAL(customScript, ByteArray);
QStringList _rtps = confFile.value("RTPs").toStringList();
Q_FOREACH(const QString &s, _rtps)
rtps << s.toUtf8();
confFile.beginGroup("Binding");
QStringList bindingKeys = confFile.childKeys();
Q_FOREACH (const QString &key, bindingKeys)
{
QVariant value = confFile.value(key);
/* Convert QString to QByteArray */
if (value.type() == QVariant::String)
value = value.toString().toUtf8();
2013-10-11 08:32:56 +00:00
bindingConf.insert(key.toLatin1(), value);
}
confFile.endGroup();
2013-09-01 14:27:21 +00:00
}
void Config::readGameINI()
{
if (!customScript.isEmpty())
{
game.title = basename(customScript.constData());
return;
}
QSettings gameINI(gameFolder + "/Game.ini", QSettings::IniFormat);
QFileInfo finfo(gameFolder.constData());
game.title = gameINI.value("Game/Title", finfo.baseName()).toByteArray();
/* Gotta read the "Scripts" entry manually because Qt can't handle '\' */
QFile gameINIFile(gameFolder + "/Game.ini");
if (gameINIFile.open(QFile::ReadOnly))
{
QString gameINIContents = gameINIFile.readAll();
QRegExp scriptsRE(".*Scripts=(.*)\r\nTitle=.*");
if (scriptsRE.exactMatch(gameINIContents))
{
game.scripts = scriptsRE.cap(1).toUtf8();
game.scripts.replace('\\', '/');
}
}
}