diff options
| author | a1xd <[email protected]> | 2020-07-22 19:34:13 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-07-22 19:34:13 -0400 |
| commit | 78156f34166c110fcad47aef166684b8e25ac4fa (patch) | |
| tree | b6121a5e1725639800c266c865f9067b3cd31a17 /common-install/utility-install.hpp | |
| parent | Add .gitignore and .gitattributes. (diff) | |
| download | rawaccel-0.1-test.tar.xz rawaccel-0.1-test.zip | |
Add project files.v0.1-test
Diffstat (limited to 'common-install/utility-install.hpp')
| -rw-r--r-- | common-install/utility-install.hpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/common-install/utility-install.hpp b/common-install/utility-install.hpp new file mode 100644 index 0000000..e1823e4 --- /dev/null +++ b/common-install/utility-install.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include <filesystem> +#include <Windows.h> + +#include "external/WinReg.hpp" + +namespace fs = std::filesystem; +namespace wr = winreg; + +inline const std::wstring DRIVER_NAME = L"rawaccel"; +inline const std::wstring DRIVER_FILE_NAME = DRIVER_NAME + L".sys"; + +fs::path get_sys_path() { + std::wstring path; + path.resize(MAX_PATH); + + UINT chars_copied = GetSystemDirectoryW(path.data(), MAX_PATH); + if (chars_copied == 0) throw std::runtime_error("GetSystemDirectory failed"); + + path.resize(chars_copied); + return path; +} + +fs::path get_target_path() { + return get_sys_path() / L"drivers" / DRIVER_FILE_NAME; +} + +fs::path make_temp_path(const fs::path& p) { + auto tmp_path = p; + tmp_path.concat(".tmp"); + return tmp_path; +} + +template<typename Func> +void modify_upper_filters(Func fn) { + const std::wstring FILTERS_NAME = L"UpperFilters"; + wr::RegKey key( + HKEY_LOCAL_MACHINE, + L"SYSTEM\\CurrentControlSet\\Control\\Class\\{4d36e96f-e325-11ce-bfc1-08002be10318}" + ); + + std::vector<std::wstring> filters = key.GetMultiStringValue(FILTERS_NAME); + fn(filters); + key.SetMultiStringValue(FILTERS_NAME, filters); +} |