2020-12-02 16:19:16 -05:00
|
|
|
#include "pch.h"
|
|
|
|
#include "Json.h"
|
|
|
|
|
2020-12-21 15:24:07 -05:00
|
|
|
CJson::CJson(const char* name)
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
2021-06-17 09:00:32 -04:00
|
|
|
if (name == "")
|
|
|
|
return;
|
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
m_FilePath = PLUGIN_PATH((char*)"/CheatMenu/json/") + std::string(name) + ".json";
|
2021-02-24 16:54:45 -05:00
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
if (fs::exists(m_FilePath))
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
2020-12-21 15:24:07 -05:00
|
|
|
try
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
std::ifstream file(m_FilePath);
|
|
|
|
file >> m_Data;
|
2020-12-21 15:24:07 -05:00
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
flog << "Error trying to read " << m_FilePath << std::endl;
|
|
|
|
m_Data = "{}"_json;
|
2020-12-02 16:19:16 -05:00
|
|
|
}
|
2020-12-21 15:24:07 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
m_Data = "{}"_json;
|
2021-02-27 15:40:51 -05:00
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
if (m_FilePath.find("config"))
|
2021-02-27 15:40:51 -05:00
|
|
|
flog << "Creating config.json file" << std::endl;
|
|
|
|
else
|
2021-06-18 12:49:11 -04:00
|
|
|
flog << "Failed to locate file " << m_FilePath << std::endl;
|
2020-12-02 16:19:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-20 14:23:32 -05:00
|
|
|
void CJson::WriteToDisk()
|
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
std::ofstream file(m_FilePath);
|
|
|
|
file << m_Data.dump(4, ' ', false, nlohmann::json::error_handler_t::replace) << std::endl;
|
2020-12-20 14:23:32 -05:00
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CJson::LoadData(std::vector<std::string>& vec, std::string& selected) // Test
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
for (auto element : m_Data.items())
|
2020-12-02 16:19:16 -05:00
|
|
|
vec.push_back(element.key());
|
2021-06-18 12:49:11 -04:00
|
|
|
}
|