forked from maikel233/xhook_wowclassic_TBC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigs.cpp
196 lines (158 loc) · 5.79 KB
/
Configs.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include "Settings/Settings.h"
#include "Configs.h"
int Settings::UI::Windows::Config::sizeX = 185;
int Settings::UI::Windows::Config::sizeY = 250;
int Settings::UI::Windows::Config::posX = 185;
int Settings::UI::Windows::Config::posY = 250;
bool Settings::UI::Windows::Config::open = false;
bool Settings::UI::Windows::Config::reload = false;
namespace ImGui
{
static auto vector_getter = [](void* vec, int idx, const char** out_text)
{
auto& vector = *static_cast<std::vector<std::string>*>(vec);
if (idx < 0 || idx >= static_cast<int>(vector.size())) { return false; }
*out_text = vector.at(idx).c_str();
return true;
};
inline bool Combo(const char* label, int* currIndex, std::vector<std::string>& values) {
if (values.empty()) { return false; }
return Combo(label, currIndex, vector_getter,
static_cast<void*>(&values), values.size());
}
inline bool
ListBox(const char* label, int* currIndex, std::vector<std::string>& values, int height_in_items = -1) {
if (values.empty()) { return false; }
return ListBox(label, currIndex, vector_getter,
static_cast<void*>(&values), values.size(), height_in_items);
}
}
std::string folder, file;
CHAR path[MAX_PATH];
char buf[128] = "";
class ConfigFile
{
public:
ConfigFile(const char* path, const char* name)
{
this->path = path;
this->name = name;
}
public:
std::string path, name;
};
std::vector<ConfigFile> getAllConfInFolder(std::string path);
std::vector<std::string> getAllConf();
//static std::vector<std::string> configItems = getAllConf();
//static int configItemCurrent = -1;
std::vector<ConfigFile> getAllConfInFolder(std::string path)
{
std::vector<ConfigFile> configs;
std::string search_path = path + "*.ini";
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(search_path.c_str(), &fd);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
std::string fPath = path + fd.cFileName;
std::string tmp_f_name(fd.cFileName);
size_t pos = tmp_f_name.find(".");
std::string fName = (std::string::npos == pos) ? tmp_f_name : tmp_f_name.substr(0, pos);
ConfigFile newConf(fPath.c_str(), fName.c_str());
configs.push_back(newConf);
}
} while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
return configs;
}
std::vector<std::string> getAllConf()
{
folder = std::string(path) + "C:\\XHOOK\\wow\\Configs\\";
std::vector<ConfigFile> confFiles = getAllConfInFolder(folder);
std::vector<std::string> confs;
for (auto config = confFiles.begin(); config != confFiles.end(); config++)
confs.push_back(config->name);
std::sort(confs.begin(), confs.end());
return confs;
}
bool Configs::showWindow = false;
#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
void Configs::RenderWindow() {
if (Settings::UI::Windows::Config::reload) {
ImGui::SetNextWindowPos(ImVec2(Settings::UI::Windows::Config::posX, Settings::UI::Windows::Config::posY),
ImGuiSetCond_Always);
ImGui::SetNextWindowSize(ImVec2(Settings::UI::Windows::Config::sizeX, Settings::UI::Windows::Config::sizeY),
ImGuiSetCond_Always);
Settings::UI::Windows::Config::reload = false;
Configs::showWindow = Settings::UI::Windows::Config::open;
}
else {
ImGui::SetNextWindowPos(ImVec2(Settings::UI::Windows::Config::posX, Settings::UI::Windows::Config::posY),
ImGuiSetCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(Settings::UI::Windows::Config::sizeX, Settings::UI::Windows::Config::sizeY),
ImGuiSetCond_FirstUseEver);
}
if (!Configs::showWindow) {
Settings::UI::Windows::Config::open = false;
return;
}
if (ImGui::Begin(XorStr("Configs"), &Configs::showWindow,
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar)) {
Settings::UI::Windows::Config::open = true;
ImVec2 temp = ImGui::GetWindowSize();
Settings::UI::Windows::Config::sizeX = (int)temp.x;
Settings::UI::Windows::Config::sizeY = (int)temp.y;
temp = ImGui::GetWindowPos();
Settings::UI::Windows::Config::posX = (int)temp.x;
Settings::UI::Windows::Config::posY = (int)temp.y;
static std::vector<std::string> configItems = getAllConf();
static int configItemCurrent = -1;
if (ImGui::Button("Refresh"))
{
configItems = getAllConf();
}
ImGui::SameLine();
if (ImGui::Button(XorStr("Save"))) {
if (configItems.size() > 0 &&
(configItemCurrent >= 0 && configItemCurrent < (int)configItems.size())) {
folder = std::string(path) + "C:\\XHOOK\\wow\\Configs\\";
file = std::string(folder) + configItems[configItemCurrent] + ".ini";
// remove(file.c_str());
Settings::LoadDefaultsOrSave(file);
}
}
ImGui::SameLine();
if (ImGui::Button(XorStr("Remove"))) {
if (configItems.size() > 0 &&
(configItemCurrent >= 0 && configItemCurrent < (int)configItems.size())) {
folder = std::string(path) + "C:\\xhook\\wow\\Configs\\";
file = std::string(folder) + configItems[configItemCurrent] + ".ini";
remove(file.c_str());
configItems = getAllConf();
configItemCurrent = -1;
}
}
static char buf[128] = "";
ImGui::PushItemWidth(138);
ImGui::InputText("", buf, IM_ARRAYSIZE(buf));
ImGui::PopItemWidth();
ImGui::SameLine();
if (ImGui::Button(XorStr("Add")) && strlen(buf) > 0) {
folder = std::string(path) + "C:\\xhook\\wow\\Configs\\";
file = std::string(folder) + std::string(buf) + ".ini";
Settings::LoadDefaultsOrSave(file);
}
ImGui::PushItemWidth(178);
if (ImGui::ListBox("", &configItemCurrent, configItems, 10)) {
folder = std::string(path) + "C:\\xhook\\wow\\Configs\\";
file = std::string(folder) + configItems[configItemCurrent] + ".ini";
Settings::LoadConfig(file);
}
ImGui::PopItemWidth();
ImGui::End();
}
}