-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetting.cpp
More file actions
146 lines (117 loc) · 3.67 KB
/
Setting.cpp
File metadata and controls
146 lines (117 loc) · 3.67 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
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
#include "Setting.h"
namespace kukdh1 {
Setting::Setting() {
DWORD dwLength;
pDefaultLanguage = {
{ L"PAZ Unpacker" },
{ L"PAZ Unpacker - %s" },
{ L"Idle" },
{ L"Busy" },
{ L"Select paz folder" },
{ L"Select folder to save file(s)" },
{ L"pad00000.meta doesn't exists" },
{ L"Alert" },
{ L"Error" },
{ L"Version: %d\r\nPAZ file no.: %d\r\nSize: %s" },
{ L"Name: %S\r\nSize: %s\r\nPaz file: %s\r\nPath: %S" },
{ L"Name: %S\r\nSize: %s" },
{ L"(1/4) Processing %d/%d..." },
{ L"(2/4) Sorting..." },
{ L"(3/4) Calculate capacities..." },
{ L"(4/4) Adding data to tree..." },
{ L"(%d/%d) Extracting..." },
{ L"" },
{ L"Fail to create directory" },
{ L"Open" },
{ L"Extract" },
{ L"(%d/%d) Adding data to tree..." }
};
// Get current directory
dwLength = GetCurrentDirectory(0, NULL);
filepath.resize(dwLength);
GetCurrentDirectory(dwLength, (wchar_t *)filepath.c_str());
// Delete null-terminator
filepath.pop_back();
// Make path of xml file
if (filepath.back() != L'\\')
filepath.append(L"\\");
filepath.append(DEFAULT_SETTING_FILENAME);
// Open file
setting.load_file(filepath.c_str());
// Check existance of setting node
std::wstring tag(LANGUAGE_TAG);
if (!setting.child(ROOT_NODE_NAME)) {
setting.append_child(ROOT_NODE_NAME);
}
if (!setting.child(LANG_NODE_NAME)) {
pugi::xml_node node = setting.append_child(LANG_NODE_NAME);
for (uint32_t i = ID_LANG_BEGIN; i < ID_LANG_END; i++) {
std::wstring tag_name = tag;
tag_name.append(std::to_wstring(i));
pugi::xml_node string = node.append_child(tag_name.c_str());
if (string) {
string.text().set(pDefaultLanguage.at(i).c_str());
}
}
}
else {
pugi::xml_node node = setting.child(LANG_NODE_NAME);
for (uint32_t i = ID_LANG_BEGIN; i < ID_LANG_END; i++) {
std::wstring tag_name = tag;
tag_name.append(std::to_wstring(i));
pugi::xml_node string = node.child(tag_name.c_str());
if (string) {
pDefaultLanguage.at(i) = string.child_value();
}
else {
string = node.append_child(tag_name.c_str());
if (string) {
string.text().set(pDefaultLanguage.at(i).c_str());
}
}
}
}
}
Setting::~Setting() {
Save();
}
void Setting::Save() {
setting.save_file(filepath.c_str(), L" ", pugi::format_default, pugi::encoding_utf8);
}
bool Setting::setData(std::wstring name, std::wstring value) {
pugi::xml_node node = setting.child(ROOT_NODE_NAME).child(name.c_str());
if (!node) {
// Create node
node = setting.child(ROOT_NODE_NAME).append_child(name.c_str());
if (!node) {
return false;
}
}
node.text().set(value.c_str());
return true;
}
bool Setting::setData(std::wstring name, int value) {
return setData(name, std::to_wstring(value));
}
void Setting::getData(std::wstring name, std::wstring &value, std::wstring defaultValue) {
pugi::xml_node node = setting.child(ROOT_NODE_NAME).child(name.c_str());
if (node) {
value = node.child_value();
}
else {
setData(name, defaultValue);
value = defaultValue;
}
}
void Setting::getData(std::wstring name, int &value, int defaultValue) {
std::wstring temp;
getData(name, temp, std::to_wstring(defaultValue));
value = _wtoi(temp.c_str());
}
std::wstring Setting::getString(LANG_ID id) {
if (id >= ID_LANG_END) {
return std::wstring();
}
return pDefaultLanguage.at(id);
}
}