-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.hpp
More file actions
85 lines (76 loc) · 2.66 KB
/
Config.hpp
File metadata and controls
85 lines (76 loc) · 2.66 KB
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
76
77
78
79
80
81
82
83
84
85
#pragma once
#include <string>
#include <fstream>
#include <iostream>
#include <mutex>
#include "Utils/Keybind.hpp"
#include "Utils/ErrorHandler.hpp"
namespace Config {
std::string path;
std::mutex config_lock;
void Rewrite(
const int horizontal_min,
const int horizontal_max,
const int vertical_min,
const int vertical_max,
const bool only_forward,
const bool only_moving,
const bool enabled
) {
std::lock_guard<std::mutex> lock(config_lock);
std::ifstream icfg(path);
std::string keybind;
if (icfg.is_open()) {
for (std::string param, value; std::getline(icfg, param, '=') && std::getline(icfg, value); ) {
if (param == "keybind")
keybind = value;
}
icfg.close();
}
else {
MessageBoxA(Utils::ErrorHandler::window, "Îøèáêà ÷òåíèÿ ôàéëà!", "Velocity", MB_ICONERROR);
}
std::ofstream ocfg(path, std::ios::trunc);
if (ocfg.is_open()) {
ocfg << "horizontal_min=" << horizontal_min << std::endl;
ocfg << "horizontal_max=" << horizontal_max << std::endl;
ocfg << "vertical_min=" << vertical_min << std::endl;
ocfg << "vertical_max=" << vertical_max << std::endl;
ocfg << "only_forward=" << (only_forward ? "true" : "false") << std::endl;
ocfg << "only_moving=" << (only_moving ? "true" : "false") << std::endl;
ocfg << "enabled=" << (enabled ? "true" : "false") << std::endl;
ocfg << "keybind=" << keybind;
}
else {
MessageBoxA(Utils::ErrorHandler::window, "Îøèáêà çàïèñè ôàéëà!", "Velocity", MB_ICONERROR);
}
}
void Read(
int& horizontal_min,
int& horizontal_max,
int& vertical_min,
int& vertical_max,
int& keycode,
bool& only_forward,
bool& only_moving,
bool& enabled
) {
std::lock_guard<std::mutex> lock(config_lock);
std::ifstream cfg(path);
if (cfg.is_open()) {
for (std::string param, value; std::getline(cfg, param, '=') && std::getline(cfg, value); ) {
if (param == "horizontal_min") horizontal_min = atoi(value.c_str());
else if (param == "horizontal_max") horizontal_max = atoi(value.c_str());
else if (param == "vertical_min") vertical_min = atoi(value.c_str());
else if (param == "vertical_max") vertical_max = atoi(value.c_str());
else if (param == "only_forward") only_forward = (value == "true" ? true : false);
else if (param == "only_moving") only_moving = (value == "true" ? true : false);
else if (param == "enabled") enabled = (value == "true" ? true : false);
else if (param == "keybind") keycode = Keybind::GetVirtualKeyCodeByKeyName(value);
}
}
else {
MessageBoxA(Utils::ErrorHandler::window, "Îøèáêà ÷òåíèÿ ôàéëà!", "Velocity", MB_ICONERROR);
}
}
}