4
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

78 lines
1.9 KiB

#pragma once
#include "Achievements.h"
#include <SimpleIni.h>
inline const SKSE::LoadInterface* GetLoadInterface(const SKSE::LoadInterface* loadInterface = nullptr)
{
const static SKSE::LoadInterface* singleton;
if (loadInterface) {
singleton = loadInterface;
}
return singleton;
}
inline Achievements::AchievementHolder* SteamInstance(Achievements::AchievementHolder* steamInterface = nullptr)
{
static Achievements::AchievementHolder* singleton = nullptr;
if (steamInterface) {
singleton = steamInterface;
}
return singleton;
}
inline bool AchievementsEnabled(bool bEnabled = NULL)
{
static bool value;
if (bEnabled != NULL) {
value = bEnabled;
}
return value;
}
inline void LoadINI(std::map<std::string, bool>* settings, const char* iniPath)
{
for (auto it = settings->begin(); it != settings->end(); it++) {
logger::info("[DEFAULT] {} = {}", it->first, it->second);
}
if (!std::filesystem::exists(iniPath)) {
logger::warn("{} does not exist, using default values.", iniPath);
return;
}
try {
CSimpleIniA ini;
ini.SetUnicode(false);
ini.SetMultiKey(false);
ini.LoadFile(iniPath);
std::list<CSimpleIniA::Entry> keysList;
ini.GetAllKeys("", keysList);
bool bUpdateINI = false;
for (auto it = settings->begin(); it != settings->end(); it++) {
bool bExists = false;
for (const auto& k : keysList) {
if (it->first == k.pItem) {
settings->insert_or_assign(k.pItem, ini.GetBoolValue("", k.pItem, settings->at(k.pItem)));
logger::info("[INI] {} = {}", k.pItem, settings->at(k.pItem));
bExists = true;
break;
}
}
if (!bExists) {
ini.SetBoolValue("", it->first.c_str(), it->second);
bUpdateINI = true;
}
}
if (bUpdateINI) {
logger::info("New settings detected, adding to ArtifactTracker.ini");
ini.SaveFile(iniPath);
}
} catch (const std::exception& e) {
logger::error(e.what());
}
}