-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New game version update (1.586441.SNOW_DLC_14 (Patch 32.2))
* INI config class * Option for disabling in-game shifting, so that it won't interfere with the mod
- Loading branch information
Showing
13 changed files
with
345 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "config/ini_config.hpp" | ||
|
||
#include "utils/logging.h" | ||
|
||
#include <boost/property_tree/ini_parser.hpp> | ||
|
||
namespace smgm { | ||
IniConfig::IniConfig() : m_path("smgm.ini") {} | ||
|
||
IniConfig::IniConfig(const std::filesystem::path &path) : m_path(path) { | ||
ReadFrom(path); | ||
} | ||
|
||
void IniConfig::SetConfigPath(const std::filesystem::path &path) { | ||
m_path = path; | ||
} | ||
|
||
bool IniConfig::Read() { return ReadFrom(m_path); } | ||
|
||
bool IniConfig::Write() { return WriteTo(m_path); } | ||
|
||
bool IniConfig::ReadFrom(const std::filesystem::path &path) { | ||
try { | ||
read_ini(path.u8string(), m_config); | ||
} catch (const std::exception &e) { | ||
LOG_DEBUG(fmt::format("Failed to read config file: {}", e.what())); | ||
|
||
return false; | ||
} | ||
|
||
WriteDefaultValues(); | ||
|
||
return true; | ||
} | ||
|
||
bool IniConfig::WriteTo(const std::filesystem::path &path) { | ||
try { | ||
write_ini(path.u8string(), m_config); | ||
} catch (const std::exception &e) { | ||
LOG_DEBUG(fmt::format("Failed to write config file: {}", e.what())); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void IniConfig::WriteDefaultValues() { | ||
SetIfNotExists("SMGM.DisableGameShifting", true); | ||
} | ||
|
||
} // namespace smgm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#pragma once | ||
|
||
#include <filesystem> | ||
|
||
#include <boost/property_tree/ptree.hpp> | ||
|
||
namespace smgm { | ||
class IniConfig { | ||
public: | ||
IniConfig(); | ||
explicit IniConfig(const std::filesystem::path &path); | ||
|
||
[[nodiscard]] const std::filesystem::path &GetConfigPath() const { | ||
return m_path; | ||
} | ||
|
||
void SetConfigPath(const std::filesystem::path &path); | ||
|
||
bool Read(); | ||
|
||
bool Write(); | ||
|
||
bool ReadFrom(const std::filesystem::path &path); | ||
|
||
bool WriteTo(const std::filesystem::path &path); | ||
|
||
[[nodiscard]] const auto &GetConfig() const { return m_config; } | ||
|
||
[[nodiscard]] auto &GetConfig() { return m_config; } | ||
|
||
template <typename T, typename PathT> | ||
IniConfig &Set(const PathT &key, const T &value) { | ||
GetConfig().put(key, value); | ||
|
||
return *this; | ||
} | ||
|
||
template <typename T, typename PathT> | ||
IniConfig &SetIfNotExists(const PathT &key, const T &value) { | ||
auto &config = GetConfig(); | ||
|
||
if (config.find(key) == config.not_found()) { | ||
config.add(key, value); | ||
} | ||
|
||
return *this; | ||
} | ||
|
||
template <typename T, typename PathT> | ||
boost::optional<T> GetOptional(const PathT &key) { | ||
return GetConfig().get_optional<T>(key); | ||
} | ||
|
||
template <typename T, typename PathT> T Get(const PathT &key) { | ||
return GetConfig().get<T>(key); | ||
} | ||
|
||
protected: | ||
void WriteDefaultValues(); | ||
|
||
std::filesystem::path m_path; | ||
boost::property_tree::ptree m_config; | ||
}; | ||
} // namespace smgm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.