1 /*
2 * This file is part of EasyRPG Player.
3 *
4 * EasyRPG Player is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * EasyRPG Player is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifdef _WIN32
19 # include <windows.h>
20 #endif
21
22 #if defined(_WIN32) && !defined(_ARM_)
23
24 // Headers
25 #include <string>
26 #include "registry.h"
27 #include "utils.h"
28
29 /**
30 * Adds Manifest depending on architecture.
31 */
32 #ifdef _MSC_VER
33 #if defined _M_IX86
34 #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
35 #elif defined _M_X64
36 #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
37 #else
38 #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
39 #endif
40 #endif
41
ReadStrValue(HKEY hkey,StringView key,StringView val,REGVIEW view)42 std::string Registry::ReadStrValue(HKEY hkey, StringView key, StringView val, REGVIEW view) {
43 char value[1024];
44 DWORD size = 1024;
45 DWORD type = REG_SZ;
46 HKEY key_handle;
47 REGSAM desired_access = KEY_QUERY_VALUE;
48
49 switch (view) {
50 case KEY32:
51 desired_access |= KEY_WOW64_32KEY;
52 break;
53 case KEY64:
54 desired_access |= KEY_WOW64_64KEY;
55 break;
56 case NATIVE:
57 default:
58 break;
59 }
60
61 std::wstring wkey = Utils::ToWideString(ToString(key));
62
63 if (RegOpenKeyEx(hkey, wkey.c_str(), NULL, desired_access, &key_handle)) {
64 return "";
65 }
66
67 std::wstring wval = Utils::ToWideString(ToString(val));
68
69 if (RegQueryValueEx(key_handle, wval.c_str(), NULL, &type, (LPBYTE)&value, &size)) {
70 return "";
71 }
72 RegCloseKey(key_handle);
73
74 std::string string_value = "";
75 for (unsigned int i = 0; i < size; i++) {
76 if (value[i] != '\0' ) {
77 string_value += value[i];
78 }
79 }
80 return string_value;
81 }
82
ReadBinValue(HKEY hkey,StringView key,StringView val,unsigned char * bin,REGVIEW view)83 int Registry::ReadBinValue(HKEY hkey, StringView key, StringView val, unsigned char* bin, REGVIEW view) {
84 DWORD size = 1024;
85 DWORD type = REG_BINARY;
86 HKEY key_handle;
87 REGSAM desired_access = KEY_QUERY_VALUE;
88
89 switch (view) {
90 case KEY32:
91 desired_access |= KEY_WOW64_32KEY;
92 break;
93 case KEY64:
94 desired_access |= KEY_WOW64_64KEY;
95 break;
96 case NATIVE:
97 default:
98 break;
99 }
100
101 std::wstring wkey = Utils::ToWideString(ToString(key));
102
103 if (RegOpenKeyEx(hkey, wkey.c_str(), NULL, desired_access, &key_handle)) {
104 return 0;
105 }
106
107 std::wstring wval = Utils::ToWideString(ToString(val));
108
109 if (RegQueryValueEx(key_handle, wval.c_str(), NULL, &type, bin, &size)) {
110 return 0;
111 }
112 RegCloseKey(key_handle);
113
114 return size;
115 }
116
117 #endif
118