mirror of https://github.com/ospab/ostp.git
Fix: Overhaul Windows UAC elevation to preserve CWD and CLI arguments, preventing instant crash on relaunch; apply UseBasicParsing to fix background downloader hangs.
This commit is contained in:
parent
d0146d027d
commit
1ab313b616
|
|
@ -45,12 +45,29 @@ fn is_admin() -> bool {
|
|||
#[cfg(target_os = "windows")]
|
||||
fn relaunch_as_admin() -> Result<()> {
|
||||
let current_exe = std::env::current_exe()?;
|
||||
let exe_str = current_exe.to_string_lossy();
|
||||
let exe_str = current_exe.to_string_lossy().replace('\'', "''");
|
||||
|
||||
let current_dir = std::env::current_dir()?;
|
||||
let dir_str = current_dir.to_string_lossy().replace('\'', "''");
|
||||
|
||||
let mut arg_parts = Vec::new();
|
||||
for arg in std::env::args().skip(1) {
|
||||
arg_parts.push(format!("'{}'", arg.replace('\'', "''")));
|
||||
}
|
||||
|
||||
let arg_list_str = if !arg_parts.is_empty() {
|
||||
format!("-ArgumentList {}", arg_parts.join(","))
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
let ps_script = format!(
|
||||
"Start-Process -FilePath '{}' {} -WorkingDirectory '{}' -Verb RunAs",
|
||||
exe_str, arg_list_str, dir_str
|
||||
);
|
||||
|
||||
let _ = std::process::Command::new("powershell")
|
||||
.args([
|
||||
"-Command",
|
||||
&format!("Start-Process -FilePath '{}' -Verb RunAs", exe_str),
|
||||
])
|
||||
.args(["-Command", &ps_script])
|
||||
.spawn()?;
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ pub fn download_wintun_dll(debug: bool) -> Result<()> {
|
|||
let dll_dest = dll_path.to_string_lossy().replace('\\', "/");
|
||||
|
||||
let ps_script = format!(
|
||||
"Invoke-WebRequest -Uri 'https://www.wintun.net/builds/wintun-0.14.1.zip' -OutFile '{}' -ErrorAction Stop; \
|
||||
"Invoke-WebRequest -Uri 'https://www.wintun.net/builds/wintun-0.14.1.zip' -OutFile '{}' -UseBasicParsing -ErrorAction Stop; \
|
||||
Expand-Archive -Path '{}' -DestinationPath '{}' -Force; \
|
||||
Get-ChildItem -Path '{}' -Filter 'wintun.dll' -Recurse | Copy-Item -Destination '{}' -Force; \
|
||||
Remove-Item '{}', '{}' -Recurse -Force",
|
||||
|
|
@ -66,7 +66,7 @@ pub fn download_tun2socks(debug: bool) -> Result<()> {
|
|||
let url = "https://github.com/xjasonlyu/tun2socks/releases/download/v2.5.2/tun2socks-windows-amd64.zip";
|
||||
|
||||
let ps_script = format!(
|
||||
"Invoke-WebRequest -Uri '{}' -OutFile '{}' -ErrorAction Stop; \
|
||||
"Invoke-WebRequest -Uri '{}' -OutFile '{}' -UseBasicParsing -ErrorAction Stop; \
|
||||
Expand-Archive -Path '{}' -DestinationPath '{}' -Force; \
|
||||
Get-ChildItem -Path '{}' -Filter '*.exe' -Recurse | Copy-Item -Destination '{}' -Force; \
|
||||
Remove-Item '{}', '{}' -Recurse -Force",
|
||||
|
|
|
|||
Loading…
Reference in New Issue