Skip to content

Commit

Permalink
Default config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferrster committed Nov 3, 2024
1 parent ef9cc8a commit 07f1b33
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/dll/config/ini_config.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "config/ini_config.hpp"

#include "utils/input_reader.h"
#include "utils/logging.h"

#include <boost/property_tree/ini_parser.hpp>

extern smgm::InputReader *g_InputReader;

namespace smgm {
IniConfig::IniConfig() : m_path("smgm.ini") {}

Expand Down Expand Up @@ -45,6 +48,21 @@ bool IniConfig::WriteTo(const std::filesystem::path &path) {
return true;
}

bool IniConfig::WriteDefaultConfig() {
if (std::filesystem::exists(m_path)) {
return false;
}

LOG_DEBUG(
fmt::format("No config file found at path {}. Generating default one...",
m_path.u8string()));

g_InputReader->WriteDefaultConfig(*this);
WriteDefaultValues();

return Write();
}

void IniConfig::WriteDefaultValues() {
SetIfNotExists("SMGM.DisableGameShifting", true);
}
Expand Down
2 changes: 2 additions & 0 deletions src/dll/config/ini_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class IniConfig {
return GetConfig().get<T>(key);
}

bool WriteDefaultConfig();

protected:
void WriteDefaultValues();

Expand Down
4 changes: 3 additions & 1 deletion src/dll/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ void Init(HINSTANCE hinst, DWORD dwReason, LPVOID reserved) {

LOG_DEBUG("SnowRunner Manual Gearbox v0.1.14");

g_IniConfig.Read();
if (!g_IniConfig.WriteDefaultConfig()) {
g_IniConfig.Read();
}

#ifdef SMGM_USE_DETOURS
DetourRestoreAfterWith();
Expand Down
1 change: 0 additions & 1 deletion src/dll/utils/input_reader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ void InputReader::WriteDefaultConfig(IniConfig &config) {
defaultKey);
});
});
config.Write();
}

} // namespace smgm
4 changes: 2 additions & 2 deletions src/dll/utils/input_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class InputReader {
private:
void ProcessKeys();

void WriteDefaultConfig(IniConfig &config);

public:
InputReader();
~InputReader();
Expand All @@ -61,5 +59,7 @@ class InputReader {
void WaitForThread();

bool ReadInputConfig(const IniConfig &config);

void WriteDefaultConfig(IniConfig &config);
};
} // namespace smgm

0 comments on commit 07f1b33

Please sign in to comment.