MassBuilderSaveTool/src/Configuration/Configuration.cpp

183 lines
4.1 KiB
C++

// MassBuilderSaveTool
// Copyright (C) 2021-2024 Guillaume Jacquemin
//
// This program 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 3 of the License, or
// (at your option) any later version.
//
// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/Pair.h>
#include <Corrade/Utility/Path.h>
#include "Configuration.h"
namespace mbst {
Configuration::Configuration() {
Containers::String exe_path = Utility::Path::split(*Utility::Path::executableLocation()).first();
_conf = Utility::Configuration{Utility::Path::join(exe_path, "MassBuilderSaveTool.ini")};
if(_conf.hasValue("swap_interval")) {
_swapInterval = _conf.value<int>("swap_interval");
}
else {
_conf.setValue("swap_interval", 1);
}
if(_conf.hasValue("frame_limit")) {
std::string frame_limit = _conf.value("frame_limit");
if(frame_limit == "half_vsync") {
_swapInterval = 2;
}
_conf.removeValue("frame_limit");
}
if(_conf.hasValue("fps_cap")) {
_fpsCap = _conf.value<float>("fps_cap");
}
else {
_conf.setValue("fps_cap", 60.0f);
}
if(_conf.hasValue("cheat_mode")) {
_cheatMode = _conf.value<bool>("cheat_mode");
}
else {
_conf.setValue("cheat_mode", _cheatMode);
}
if(_conf.hasValue("advanced_mode")) {
_advancedMode = _conf.value<bool>("advanced_mode");
}
else {
_conf.setValue("advanced_mode", _advancedMode);
}
if(_conf.hasValue("startup_update_check")) {
_checkUpdatesOnStartup = _conf.value<bool>("startup_update_check");
}
else {
_conf.setValue("startup_update_check", _checkUpdatesOnStartup);
}
if(_conf.hasValue("skip_disclaimer")) {
_skipDisclaimer = _conf.value<bool>("skip_disclaimer");
}
else {
_conf.setValue("skip_disclaimer", _skipDisclaimer);
}
}
Configuration::~Configuration() {
save();
}
void
Configuration::save() {
_conf.save();
}
int
Configuration::swapInterval() const {
return _swapInterval;
}
void
Configuration::setSwapInterval(int interval) {
_swapInterval = interval;
_conf.setValue("swap_interval", _swapInterval);
_conf.save();
}
float
Configuration::fpsCap() const {
return _fpsCap;
}
void
Configuration::setFpsCap(float cap) {
_fpsCap = cap;
_conf.setValue("fps_cap", _fpsCap);
_conf.save();
}
bool
Configuration::cheatMode() const {
return _cheatMode;
}
void
Configuration::setCheatMode(bool enabled) {
_cheatMode = enabled;
_conf.setValue("cheat_mode", _cheatMode);
_conf.save();
}
bool
Configuration::advancedMode() const {
return _advancedMode;
}
void
Configuration::setAdvancedMode(bool enabled) {
_advancedMode = enabled;
_conf.setValue("advanced_mode", _advancedMode);
_conf.save();
}
bool
Configuration::checkUpdatesOnStartup() const {
return _checkUpdatesOnStartup;
}
void
Configuration::setCheckUpdatesOnStartup(bool mode) {
_checkUpdatesOnStartup = mode;
_conf.setValue("startup_update_check", _checkUpdatesOnStartup);
_conf.save();
}
bool
Configuration::skipDisclaimer() const {
return _skipDisclaimer;
}
void
Configuration::setSkipDisclaimer(bool mode) {
_skipDisclaimer = mode;
_conf.setValue("skip_disclaimer", _skipDisclaimer);
_conf.save();
}
bool
Configuration::isRunningInWine() const {
return _isRunningInWine;
}
void
Configuration::setRunningInWine(bool wine) {
_isRunningInWine = wine;
}
Configuration&
Configuration::instance() {
static Configuration conf{};
return conf;
}
Configuration&
conf() {
return Configuration::instance();
}
}