From c0257bff525b57935f77fdad9bff2fa49122af01 Mon Sep 17 00:00:00 2001 From: fufesou Date: Tue, 7 Mar 2023 22:38:01 +0800 Subject: [PATCH] win, install cert Signed-off-by: fufesou --- src/core_main.rs | 4 ++++ src/lang/de.rs | 2 ++ src/lang/fa.rs | 2 ++ src/lang/ru.rs | 2 ++ src/platform/windows.rs | 25 ++++++++++++++++++++++--- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/core_main.rs b/src/core_main.rs index 60a7d9c9c..76b630f88 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -143,6 +143,10 @@ pub fn core_main() -> Option> { #[cfg(feature = "with_rc")] hbb_common::allow_err!(crate::rc::extract_resources(&args[1])); return None; + } else if args[0] == "--install-cert" { + #[cfg(windows)] + hbb_common::allow_err!(crate::platform::windows::install_cert(&args[1])); + return None; } else if args[0] == "--portable-service" { crate::platform::elevate_or_run_as_system( click_setup, diff --git a/src/lang/de.rs b/src/lang/de.rs index 78d6d6c15..26fb727c5 100644 --- a/src/lang/de.rs +++ b/src/lang/de.rs @@ -461,5 +461,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Resolution", "Auflösung"), ("No transfers in progress", "Keine Übertragungen im Gange"), ("Set one-time password length", "Länge des Einmalpassworts festlegen"), + ("Install driver cert(test cert)", ""), + ("Virtual display requirement", "") ].iter().cloned().collect(); } diff --git a/src/lang/fa.rs b/src/lang/fa.rs index 9c24ca6c3..a45768701 100644 --- a/src/lang/fa.rs +++ b/src/lang/fa.rs @@ -461,5 +461,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Resolution", "وضوح"), ("No transfers in progress", "هیچ انتقالی در حال انجام نیست"), ("Set one-time password length", "طول رمز یکبار مصرف را تعیین کنید"), + ("Install driver cert(test cert)", ""), + ("Virtual display requirement", "") ].iter().cloned().collect(); } diff --git a/src/lang/ru.rs b/src/lang/ru.rs index adc5872a3..145700c0d 100644 --- a/src/lang/ru.rs +++ b/src/lang/ru.rs @@ -461,5 +461,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Resolution", "Разрешение"), ("No transfers in progress", "Передача не осуществляется"), ("Set one-time password length", "Установить длину одноразового пароля"), + ("Install driver cert(test cert)", ""), + ("Virtual display requirement", "") ].iter().cloned().collect(); } diff --git a/src/platform/windows.rs b/src/platform/windows.rs index dbf30311c..696a18ab9 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -1108,6 +1108,12 @@ if exist \"{tmp_path}\\{app_name} Tray.lnk\" del /f /q \"{tmp_path}\\{app_name} ); let src_exe = std::env::current_exe()?.to_str().unwrap_or("").to_string(); + let install_cert = if options.contains("driverCert") { + format!("\"{}\" --install-cert \"RustDeskIddDriver.cer\"", src_exe) + } else { + "".to_owned() + }; + let cmds = format!( " {uninstall_str} @@ -1139,6 +1145,7 @@ sc create {app_name} binpath= \"\\\"{exe}\\\" --import-config \\\"{config_path}\ sc start {app_name} sc stop {app_name} sc delete {app_name} +{install_cert} {after_install} {sleep} ", @@ -1159,6 +1166,7 @@ sc delete {app_name} shortcuts=shortcuts, config_path=Config::file().to_str().unwrap_or(""), lic=register_licence(), + install_cert=install_cert, after_install=get_after_install(&exe), sleep=if debug { "timeout 300" @@ -1174,9 +1182,6 @@ sc delete {app_name} ); run_cmds(cmds, debug, "install")?; std::thread::sleep(std::time::Duration::from_millis(2000)); - if options.contains("driverCert") { - allow_err!(cert::install_cert(std::path::Path::new(&path).join("RustDeskIddDriver.cer"))); - } if !silent { std::process::Command::new(&exe).spawn()?; std::process::Command::new(&exe).arg("--tray").spawn()?; @@ -1907,6 +1912,20 @@ pub fn user_accessible_folder() -> ResultType { Ok(dir) } +#[inline] +pub fn install_cert(cert_file: &str) -> ResultType<()> { + let exe_file = std::env::current_exe()?; + if let Some(cur_dir) = exe_file.parent() { + allow_err!(cert::install_cert(cur_dir.join(cert_file))); + } else { + bail!( + "Invalid exe parent for {}", + exe_file.to_string_lossy().as_ref() + ); + } + Ok(()) +} + mod cert { use hbb_common::{allow_err, bail, log, ResultType}; use std::{path::Path, str::from_utf8};