forked from sur-ser/Age_of_Empires_II_Definitive-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.cpp
75 lines (61 loc) · 1.89 KB
/
Config.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "Config.h"
#include <Windows.h>
#include <iostream>
#include <fstream>
#include "Shlobj.h"
#include "Shlobj_core.h"
Config* Config::instance = NULL;
std::filesystem::path Config::GetConfigPath()
{
TCHAR szPath[MAX_PATH];
SHGetFolderPath(nullptr, CSIDL_APPDATA, nullptr, 0, szPath);
std::filesystem::path path = std::filesystem::path(szPath);
path.append("AoE2DE_imgui");
return path;
}
Config::Config()
{
std::filesystem::path path = GetConfigPath();
//create directory if it doesn't exist
CreateDirectoryA(GetConfigPath().string().c_str(), NULL);
//create config.ini if doesn't exist
std::ofstream configFile;
path.append("config.ini");
configFile.open(path.c_str(), std::fstream::app);
}
std::filesystem::path Config::GetConfigFilePath()
{
std::filesystem::path path = GetConfigPath();
path.append("config.ini");
return path;
}
float Config::ReadFloat(std::string feature, std::string settingsName)
{
char buffer[256];
int read = GetPrivateProfileString(feature.c_str(), settingsName.c_str(), NULL, buffer, 256, GetConfigFilePath().string().c_str());
if (!read)
{
printf("Failed to read config: %s->%s\n", feature.c_str(), settingsName.c_str());
}
return std::stof(buffer);
}
int Config::ReadInt(std::string feature, std::string settingsName)
{
char buffer[256];
int read = GetPrivateProfileString(feature.c_str(), settingsName.c_str(), NULL, buffer, 256, GetConfigFilePath().string().c_str());
if (!read)
{
printf("Failed to read config: %s->%s\n", feature.c_str(), settingsName.c_str());
}
return std::stoi(buffer);
}
std::string Config::ReadString(std::string feature, std::string settingsName)
{
char buffer[256];
int read = GetPrivateProfileString(feature.c_str(), settingsName.c_str(), NULL, buffer, 256, GetConfigFilePath().string().c_str());
if (!read)
{
printf("Failed to read config: %s->%s\n", feature.c_str(), settingsName.c_str());
}
return std::string(buffer);
}