summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authora1xd <[email protected]>2021-02-26 21:50:35 -0500
committera1xd <[email protected]>2021-09-23 22:36:19 -0400
commit41d73f257a58905f273fce3195cb4c0f3cd5c165 (patch)
tree33ed86b2257878a4102dc15b86e25875e13b172f /common
parentbump version, target win10 (diff)
downloadrawaccel-41d73f257a58905f273fce3195cb4c0f3cd5c165.tar.xz
rawaccel-41d73f257a58905f273fce3195cb4c0f3cd5c165.zip
improve installer
use standard syntax for service binpath throw if copy_file fails
Diffstat (limited to 'common')
-rw-r--r--common/utility-install.hpp23
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;
}