-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.hpp
47 lines (42 loc) · 1.04 KB
/
utils.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <filesystem>
#include <string>
#include <fstream>
#include "skStr.h"
#include "json.hpp"
using json = nlohmann::json;
std::string ReadFromJson(std::string path, std::string section)
{
if (!std::filesystem::exists(path))
return skCrypt("File Not Found").decrypt();
std::ifstream file(path);
json data = json::parse(file);
return data[section];
}
bool CheckIfJsonKeyExists(std::string path, std::string section)
{
if (!std::filesystem::exists(path))
return skCrypt("File Not Found").decrypt();
std::ifstream file(path);
json data = json::parse(file);
return data.contains(section);
}
bool WriteToJson(std::string path, std::string name, std::string value, bool userpass, std::string name2, std::string value2)
{
json file;
if (!userpass)
{
file[name] = value;
}
else
{
file[name] = value;
file[name2] = value2;
}
std::ofstream jsonfile(path, std::ios::out);
jsonfile << file;
jsonfile.close();
if (!std::filesystem::exists(path))
return false;
return true;
}