working on windows service install/uninstall

This commit is contained in:
rustdesk
2023-06-05 20:27:48 +08:00
parent f1cc42769c
commit b07ac438f5
17 changed files with 280 additions and 688 deletions

View File

@@ -14,3 +14,4 @@ embed-resource = "2.1"
brotli = "3.3"
dirs = "5.0"
md5 = "0.7"
winapi = { version = "0.3", features = ["winbase"] }

View File

@@ -1 +1 @@
rustdesk_icon ICON "../../res/icon.ico"
rustdesk_icon ICON "../../res/tray-icon.ico"

View File

@@ -38,7 +38,7 @@ impl BinaryData {
let cursor = Cursor::new(self.raw);
let mut decoder = brotli::Decompressor::new(cursor, BUF_SIZE);
let mut buf = Vec::new();
decoder.read_to_end(&mut buf).unwrap();
decoder.read_to_end(&mut buf).ok();
buf
}
@@ -51,7 +51,7 @@ impl BinaryData {
}
if p.exists() {
// check md5
let f = fs::read(p.clone()).unwrap();
let f = fs::read(p.clone()).unwrap_or_default();
let digest = format!("{:x}", md5::compute(&f));
let md5_record = String::from_utf8_lossy(self.md5_code);
if digest == md5_record {
@@ -127,11 +127,13 @@ impl BinaryReader {
let exe_path = prefix.join(&self.exe);
if exe_path.exists() {
let f = File::open(exe_path).unwrap();
let meta = f.metadata().unwrap();
let mut permissions = meta.permissions();
permissions.set_mode(0o755);
f.set_permissions(permissions).unwrap();
if let Ok(f) = File::open(exe_path) {
if let Ok(meta) = f.metadata() {
let mut permissions = meta.permissions();
permissions.set_mode(0o755);
f.set_permissions(permissions).ok();
}
}
}
}
}

View File

@@ -1,6 +1,7 @@
#![windows_subsystem = "windows"]
use std::{
os::windows::process::CommandExt,
path::PathBuf,
process::{Command, Stdio},
};
@@ -40,17 +41,18 @@ fn setup(reader: BinaryReader, dir: Option<PathBuf>, clear: bool) -> Option<Path
fn execute(path: PathBuf, args: Vec<String>) {
println!("executing {}", path.display());
// setup env
let exe = std::env::current_exe().unwrap();
let exe_name = exe.file_name().unwrap();
let exe = std::env::current_exe().unwrap_or_default();
let exe_name = exe.file_name().unwrap_or_default();
// run executable
Command::new(path)
.args(args)
.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW)
.env(APPNAME_RUNTIME_ENV_KEY, exe_name)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.expect(&format!("failed to execute {:?}", exe_name));
.ok();
}
fn main() {
@@ -84,7 +86,7 @@ fn main() {
}
mod windows {
use std::{fs, path::PathBuf, process::Command};
use std::{fs, os::windows::process::CommandExt, path::PathBuf, process::Command};
// Used for privacy mode(magnifier impl).
pub const RUNTIME_BROKER_EXE: &'static str = "C:\\Windows\\System32\\RuntimeBroker.exe";
@@ -105,6 +107,7 @@ mod windows {
}
let _allow_err = Command::new("taskkill")
.args(&["/F", "/IM", "RuntimeBroker_rustdesk.exe"])
.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW)
.output();
let _allow_err = std::fs::copy(src, &format!("{}\\{}", dir.to_string_lossy(), tgt));
}