Skip to content

Commit

Permalink
Fixed running "Update smartctl database" on Windows; use argv on all …
Browse files Browse the repository at this point in the history
…platforms so it is more secure.
  • Loading branch information
ashaduri committed Nov 5, 2024
1 parent 7fd43bb commit 99bf00d
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/gui/gsc_main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,21 +955,26 @@ void GscMainWindow::run_update_drivedb()
return;
}

hz::fs::path update_binary_path = hz::fs_path_from_string("update-smart-drivedb");
std::vector<std::string> argv;

if constexpr (BuildEnv::is_kernel_family_windows()) {
update_binary_path += ".ps1";
}
if (smartctl_binary.is_absolute()) {
update_binary_path = smartctl_binary.parent_path() / update_binary_path;
}
std::string update_binary = hz::fs_path_to_string(update_binary_path);
hz::fs::path update_binary_path = hz::fs_path_from_string("update-smart-drivedb.ps1");
if (smartctl_binary.is_absolute()) {
update_binary_path = smartctl_binary.parent_path() / update_binary_path;
}
argv = {"powershell.exe", "-ExecutionPolicy", "Bypass", "-File", hz::fs_path_to_string(update_binary_path)};

if constexpr(!BuildEnv::is_kernel_family_windows()) { // X11
update_binary = "xterm -hold -e " + update_binary;
} else { // X11
// TODO Wayland
hz::fs::path update_binary_path = hz::fs_path_from_string("update-smart-drivedb");
if (smartctl_binary.is_absolute()) {
update_binary_path = smartctl_binary.parent_path() / update_binary_path;
}
argv = {"xterm", "-hold", "-e", hz::fs_path_to_string(update_binary_path)};
}

try {
Glib::spawn_command_line_async(update_binary);
Glib::spawn_async(Glib::get_current_dir(), argv, Glib::SPAWN_SEARCH_PATH);
}
catch(Glib::Error& e) {
gui_show_error_dialog(_("Error Updating Drive Database"), e.what(), this);
Expand Down

0 comments on commit 99bf00d

Please sign in to comment.