MCPcopy Create free account
hub / github.com/ashaduri/gsmartcontrol / get_smartctl_binary

Function get_smartctl_binary

src/applib/smartctl_executor.cpp:24–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23
24hz::fs::path get_smartctl_binary()
25{
26 auto smartctl_binary = hz::fs_path_from_string(rconfig::get_data<std::string>("system/smartctl_binary"));
27
28 if (BuildEnv::is_kernel_family_windows()) {
29 // Look in smartmontools installation directory.
30 hz::fs::path system_binary;
31 do {
32 const bool use_smt = rconfig::get_data<bool>("system/win32_search_smartctl_in_smartmontools");
33 if (!use_smt)
34 break;
35
36 auto smt_regpath = rconfig::get_data<std::string>("system/win32_smartmontools_regpath");
37 auto smt_regpath_wow = rconfig::get_data<std::string>("system/win32_smartmontools_regpath_wow"); // same as above, but with WOW6432Node
38 auto smt_regkey = rconfig::get_data<std::string>("system/win32_smartmontools_regkey");
39 auto smt_smartctl = rconfig::get_data<std::string>("system/win32_smartmontools_smartctl_binary");
40
41 if ((smt_regpath.empty() && smt_regpath_wow.empty()) || smt_regkey.empty() || smt_smartctl.empty())
42 break;
43
44 std::string smt_inst_dir;
45 #ifdef _WIN32
46 hz::win32_get_registry_value_string(HKEY_LOCAL_MACHINE, smt_regpath, smt_regkey, smt_inst_dir);
47 if (smt_inst_dir.empty()) {
48 hz::win32_get_registry_value_string(HKEY_LOCAL_MACHINE, smt_regpath_wow, smt_regkey, smt_inst_dir);
49 }
50 #endif
51
52 if (smt_inst_dir.empty()) {
53 debug_out_info("app", DBG_FUNC_MSG << "Smartmontools installation not found in \"HKLM\\"
54 << smt_regpath << "\\" << smt_regkey << "\".\n");
55 break;
56 }
57 debug_out_info("app", DBG_FUNC_MSG << "Smartmontools installation found at \"" << smt_inst_dir
58 << "\", using \"" << smt_smartctl << "\".\n");
59
60 auto p = hz::fs_path_from_string(smt_inst_dir) / hz::fs_path_from_string(smt_smartctl);
61
62 if (!hz::fs::exists(p) || !hz::fs::is_regular_file(p))
63 break;
64
65 system_binary = p;
66 } while (false);
67
68 if (!system_binary.empty()) {
69 smartctl_binary = system_binary;
70
71 } else if (smartctl_binary.is_relative()) {
72 // If smartctl path is relative, and it's Windows, and the package seems to contain smartctl, use our own binary.
73 if (auto app_dir = hz::fs_get_application_dir(); !app_dir.empty() && hz::fs::exists(app_dir / smartctl_binary)) {
74 smartctl_binary = app_dir / smartctl_binary;
75 }
76 }
77 }
78
79 return smartctl_binary;
80}
81

Callers 4

execute_smartctlFunction · 0.85
run_update_drivedbMethod · 0.85

Calls 4

fs_path_from_stringFunction · 0.85
fs_get_application_dirFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected