#include "datastore.h" #include "pch.h" DataStore::DataStore(const char* fileName, bool isPathPredefined) noexcept { if (isPathPredefined) { path = std::string(fileName) + fileExt; } else { path = PLUGIN_PATH((char*)"/CheatMenu/data/") + std::string(fileName) + fileExt; } if (std::filesystem::exists(path)) { toml::parse_result result = toml::parse_file(path); if (result) { pTable = std::make_unique(std::move(result)); return; } } if (pTable == nullptr) { pTable = std::make_unique(); if (fileName == FILE_NAME) { Log::Print("Creating {}{}", fileName, fileExt); } else { Log::Print("Error parsing {}{}", fileName, fileExt); } } } bool DataStore::Contains(const char* ele) noexcept { if (pTable) { return pTable->contains(ele); } return false; } DataStore::Table& DataStore::Items() noexcept { return pTable->as_table()->ref(); } void DataStore::RemoveTable(const char* key) noexcept { if (pTable) { pTable->erase(key); } } void DataStore::RemoveKey(const char* key, const char* entry) noexcept { if (pTable) { (*pTable).at_path(key).as_table()->erase(entry); } } void DataStore::Save() noexcept { if (pTable) { std::ofstream file(path); if (file.good()) { file << *pTable << std::endl; file.close(); } } }