20 #define MAX_KEY_LENGTH 255 21 #define MAX_VALUE_NAME 16383 24 #define strncasecmp _strnicmp 25 #define strcasecmp _stricmp 40 return strcasecmp(a.c_str(), b.c_str()) == 0;
43 inline bool operator==(
const device_id& a,
const device_id& b)
45 return equal(a.pid, b.pid) &&
46 equal(a.guid, b.guid) &&
51 class windows_metadata_helper :
public metadata_helper
56 static const std::regex regex(
"pid_([0-9a-f]+)&mi_([0-9]+)#[0-9a-f]&([0-9a-f]+)&[\\s\\S]*\\{([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\\}", std::regex_constants::icase);
58 std::match_results<std::string::const_iterator> match;
60 if (std::regex_search(
id, match,
regex) && match.size() > 4)
71 static void foreach_device_path(
const std::vector<device_id>&
devices,
72 std::function<
void(
const device_id&,
75 std::map<std::string, std::vector<device_id>> guid_to_devices;
76 for (
auto&&
d : devices)
78 guid_to_devices[
d.guid].push_back(
d);
81 for (
auto&&
kvp : guid_to_devices)
83 auto guid =
kvp.first;
86 ss <<
"SYSTEM\\CurrentControlSet\\Control\\DeviceClasses\\{" << guid <<
"}";
88 std::wstring prefix(
s.begin(),
s.end());
91 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, prefix.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &
key) == ERROR_SUCCESS)
94 std::shared_ptr<void> raii(key, RegCloseKey);
96 TCHAR achClass[MAX_PATH] = TEXT(
"");
97 DWORD cchClassName = MAX_PATH;
103 DWORD cbMaxValueData;
104 DWORD cbSecurityDescriptor;
105 FILETIME ftLastWriteTime;
107 DWORD retCode = RegQueryInfoKey(
118 &cbSecurityDescriptor,
121 for (
auto i = 0ul;
i < cSubKeys;
i++)
123 TCHAR achKey[MAX_KEY_LENGTH];
124 DWORD cbName = MAX_KEY_LENGTH;
125 retCode = RegEnumKeyEx(key,
i,
132 if (retCode == ERROR_SUCCESS)
134 std::wstring suffix = achKey;
136 auto a =
std::string(suffix.begin(), suffix.end());
137 if (parse_device_id(a, &rdid))
139 for (
auto&& did :
kvp.second)
143 std::wstringstream ss;
144 ss << prefix <<
"\\" << suffix <<
"\\#GLOBAL\\Device Parameters";
145 auto path = ss.str();
162 if (
equal(pid,
"0b0d") ||
equal(pid,
"0b3d") ||
equal(pid,
"0b64") ||
equal(pid,
"0b68"))
return 3;
164 else if (
equal(pid,
"0b5b"))
return 3;
170 bool is_running_as_admin()
173 PSID admin_group =
NULL;
175 SID_IDENTIFIER_AUTHORITY ntauthority = SECURITY_NT_AUTHORITY;
176 if (!AllocateAndInitializeSid(
179 SECURITY_BUILTIN_DOMAIN_RID,
180 DOMAIN_ALIAS_RID_ADMINS,
187 std::shared_ptr<void> raii(admin_group, FreeSid);
189 if (!CheckTokenMembership(
NULL, admin_group, &result))
198 bool elevate_to_admin()
200 if (!is_running_as_admin())
202 wchar_t szPath[MAX_PATH];
203 if (GetModuleFileName(
NULL, szPath, ARRAYSIZE(szPath)))
205 SHELLEXECUTEINFO sei = {
sizeof(sei) };
207 sei.lpVerb = L
"runas";
208 sei.fMask = SEE_MASK_NOCLOSEPROCESS;
211 sei.nShow = SW_NORMAL;
212 auto cmd_line = get_command_line_param();
213 std::wstring wcmd(cmd_line.begin(), cmd_line.end());
214 sei.lpParameters = wcmd.c_str();
216 if (ShellExecuteEx(&sei) != ERROR_SUCCESS)
223 WaitForSingleObject(sei.hProcess, INFINITE);
225 GetExitCodeProcess(sei.hProcess, &exitCode);
226 CloseHandle(sei.hProcess);
228 throw std::runtime_error(
"Failed to set metadata registry keys!");
249 if (parse_device_id(
id, &did))
250 foreach_device_path({ did }, [&
res, did](
const device_id&, std::wstring
path) {
253 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
path.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &
key) == ERROR_SUCCESS)
256 std::shared_ptr<void> raii(key, RegCloseKey);
259 DWORD
len =
sizeof(DWORD);
261 for (
int i = 0;
i < number_of_mediapins(did.pid, did.mi);
i++)
263 std::wstringstream ss; ss << L
"MetadataBufferSizeInKB" <<
i;
264 std::wstring metadatakey = ss.str();
266 DWORD MetadataBufferSizeInKB = 0;
272 (LPBYTE)(&MetadataBufferSizeInKB),
273 &
len) != ERROR_SUCCESS)
276 found = found && MetadataBufferSizeInKB;
279 if (found) res =
true;
286 void enable_metadata()
override 288 if (elevate_to_admin())
290 std::vector<device_id> dids;
294 for (
uint32_t i = 0; i < list.size(); i++)
303 if (can_support_metadata(product))
311 if (parse_device_id(port, &did)) dids.push_back(did);
320 bool failure =
false;
321 foreach_device_path(dids, [&failure](
const device_id& did, std::wstring
path) {
323 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, path.c_str(), 0, KEY_WRITE | KEY_WOW64_64KEY, &
key) == ERROR_SUCCESS)
326 std::shared_ptr<void> raii(key, RegCloseKey);
329 DWORD len =
sizeof(DWORD);
331 for (
int i = 0; i < number_of_mediapins(did.pid, did.mi); i++)
333 std::wstringstream ss; ss << L
"MetadataBufferSizeInKB" <<
i;
334 std::wstring metadatakey = ss.str();
336 DWORD MetadataBufferSizeInKB = 5;
337 if (RegSetValueEx(key, metadatakey.c_str(), 0, REG_DWORD,
338 (
const BYTE*)&MetadataBufferSizeInKB,
sizeof(DWORD)) != ERROR_SUCCESS)
346 if (failure)
throw std::runtime_error(
"Unable to write to metadata registry key!");
355 static windows_metadata_helper instance;
GLboolean GLboolean GLboolean b
std::vector< sensor > query_sensors() const
bool operator==(const plane &lhs, const plane &rhs)
GLsizei const GLchar *const * path
device_list query_devices() const
void log(rs2_log_severity severity, const char *message)
GLsizei const GLchar *const * string
GLboolean GLboolean GLboolean GLboolean a
const char * get_info(rs2_camera_info info) const
bool supports(rs2_camera_info info) const