diff options
| author | a1xd <[email protected]> | 2021-09-24 02:04:43 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-24 02:04:43 -0400 |
| commit | 2896b8a09ce42e965705c58593b8738adc454f7f (patch) | |
| tree | 71e4d0cff60b5a1ad11427d78e1f8c7b775e5690 /common/utility-install.hpp | |
| parent | Merge pull request #107 from a1xd/1.5.0-fix (diff) | |
| parent | make note clearer (diff) | |
| download | rawaccel-1.6.0.tar.xz rawaccel-1.6.0.zip | |
v1.6
Diffstat (limited to 'common/utility-install.hpp')
| -rw-r--r-- | common/utility-install.hpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/common/utility-install.hpp b/common/utility-install.hpp index e1823e4..55ae9d6 100644 --- a/common/utility-install.hpp +++ b/common/utility-install.hpp @@ -10,25 +10,24 @@ namespace wr = winreg; inline const std::wstring DRIVER_NAME = L"rawaccel"; inline const std::wstring DRIVER_FILE_NAME = DRIVER_NAME + L".sys"; +inline const std::wstring DRIVER_ENV_PATH = L"%systemroot%\\system32\\drivers\\" + DRIVER_FILE_NAME; -fs::path get_sys_path() { - std::wstring path; - path.resize(MAX_PATH); +inline const auto sys_error = [](auto what, DWORD code = GetLastError()) { + return std::system_error(code, std::system_category(), what); +}; - UINT chars_copied = GetSystemDirectoryW(path.data(), MAX_PATH); - if (chars_copied == 0) throw std::runtime_error("GetSystemDirectory failed"); +inline std::wstring expand(const std::wstring& env_path) { + std::wstring path(MAX_PATH, L'\0'); - path.resize(chars_copied); + auto len = ExpandEnvironmentStringsW(env_path.c_str(), &path[0], MAX_PATH); + if (len == 0) throw sys_error("ExpandEnvironmentStrings failed"); + path.resize(len - 1); 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) { +inline fs::path make_temp_path(const fs::path& p) { auto tmp_path = p; - tmp_path.concat(".tmp"); + tmp_path.concat(L".tmp"); return tmp_path; } |