windows: a setup program, and an uninstall entry in Settings > Apps
ProxySuite-<version>-windows-x64-setup.exe (NSIS, English and Russian): it unpacks the release into its temporary folder and runs the release's own proxy-suite-service.exe install from there, as install.cmd does from the zip (unpacked straight into Program Files, an upgrade would find its files in use). It refuses 32-bit Windows and anything before 10 1903, and offers Windows' OpenSSH Client, unchecked, for the SSH tunnel. install now writes the entry in Settings > Apps (uninstall.cmd; quietly, the service's uninstall), and uninstall removes it, with WinDivert's driver service when it is the suite's own. The release workflow publishes the setup beside the zip. The app's icon and GPUI's manifest share one resource (llvm-rc for both); the build scripts' clones retry, and are kept for the next build. Tested under Wine: tools/wine-setup-test.sh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ae31e499ca
commit
ae58bd1f12
14 files changed
+421
-33
No files matched your search
@@ -1,7 +1,8 @@
|
||||
//! The Windows build carries the app's icon as its resource 1, where GPUI loads its windows'
|
||||
//! icon from (and Explorer, the Start Menu and Settings > Apps show it). The resource compiler
|
||||
//! is LLVM's (`llvm-rc`, in the dev shell; `RC` names another); without one the app builds
|
||||
//! with Windows' default icon, and says so.
|
||||
//! is LLVM's (`llvm-rc`, in the dev shell), or `rc.exe` on Windows; `PS_GUI_RC` names another.
|
||||
//! (Not `RC`: the dev shell sets that to MinGW's windres, which takes other arguments.) Without
|
||||
//! one the app builds with Windows' default icon, and says so; tools/package.sh refuses that.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
@@ -9,7 +10,7 @@ use std::process::Command;
|
||||
fn main() {
|
||||
let icon = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("assets/proxy-suite.ico");
|
||||
println!("cargo:rerun-if-changed={}", icon.display());
|
||||
println!("cargo:rerun-if-env-changed=RC");
|
||||
println!("cargo:rerun-if-env-changed=PS_GUI_RC");
|
||||
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
|
||||
return;
|
||||
}
|
||||
@@ -18,7 +19,7 @@ fn main() {
|
||||
let res = out.join("app.res");
|
||||
// The resource script's strings are C strings: backslashes doubled.
|
||||
std::fs::write(&rc, format!("1 ICON \"{}\"\n", icon.display().to_string().replace('\\', "\\\\"))).unwrap();
|
||||
let compiler = std::env::var("RC").unwrap_or_else(|_| if cfg!(windows) { "rc.exe".into() } else { "llvm-rc".into() });
|
||||
let compiler = std::env::var("PS_GUI_RC").unwrap_or_else(|_| if cfg!(windows) { "rc.exe".into() } else { "llvm-rc".into() });
|
||||
let mut command = Command::new(&compiler);
|
||||
command.arg("/nologo");
|
||||
if compiler.contains("llvm-rc") {
|
||||
|
||||
@@ -144,6 +144,9 @@ pub fn install() -> Result<()> {
|
||||
Ok(false) => {}
|
||||
Err(e) => println!("warning: the app's Start Menu entry and start at sign-in: {e:#}"),
|
||||
}
|
||||
if let Err(e) = apps::add(&to) {
|
||||
println!("warning: the entry in Settings → Apps: {e:#}");
|
||||
}
|
||||
println!("Open a new terminal and try: proxy-ctl status");
|
||||
Ok(())
|
||||
}
|
||||
@@ -163,8 +166,10 @@ pub fn uninstall() -> Result<()> {
|
||||
} else {
|
||||
println!("{DISPLAY} was not installed.");
|
||||
}
|
||||
remove_windivert(&manager);
|
||||
let dir = install_dir();
|
||||
desktop::remove();
|
||||
apps::remove();
|
||||
let _ = path::remove(&dir);
|
||||
if dir.exists() {
|
||||
// This program may be one of the files: they go a moment after it exits. Raw, as cmd
|
||||
@@ -185,6 +190,100 @@ pub fn uninstall() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The WinDivert driver zapret loaded from this suite's components, if it is still registered
|
||||
/// (WinDivert removes its own service as it loads, but one stopped hard can stay): stopped and
|
||||
/// deleted, as Flowseal's service.bat removes it. One from elsewhere is left alone.
|
||||
fn remove_windivert(manager: &ServiceManager) {
|
||||
let ours = crate::paths::Paths::platform_default().root.to_string_lossy().to_lowercase();
|
||||
for name in ["WinDivert", "WinDivert14"] {
|
||||
let Ok(service) = manager.open_service(name, ServiceAccess::QUERY_CONFIG | ServiceAccess::QUERY_STATUS | ServiceAccess::STOP | ServiceAccess::DELETE) else {
|
||||
continue;
|
||||
};
|
||||
let Ok(config) = service.query_config() else { continue };
|
||||
if config.executable_path.to_string_lossy().to_lowercase().contains(&ours) {
|
||||
let _ = service.stop();
|
||||
if service.delete().is_ok() {
|
||||
println!("WinDivert's driver ({name}) is removed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The entry in Settings → Apps (and Control Panel's Programs and Features): its Uninstall runs
|
||||
/// uninstall.cmd, which asks for administrator rights; `QuietUninstallString` (winget, scripts
|
||||
/// that run elevated) the service's own `uninstall`.
|
||||
mod apps {
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use windows_sys::Win32::Foundation::ERROR_SUCCESS;
|
||||
use windows_sys::Win32::System::Registry::{
|
||||
HKEY, HKEY_LOCAL_MACHINE, KEY_WRITE, REG_DWORD, REG_OPTION_NON_VOLATILE, REG_SZ, RegCloseKey, RegCreateKeyExW, RegDeleteTreeW,
|
||||
RegSetValueExW,
|
||||
};
|
||||
|
||||
const KEY: &str = r"Software\Microsoft\Windows\CurrentVersion\Uninstall\ProxySuite";
|
||||
|
||||
fn wide(s: &str) -> Vec<u16> {
|
||||
s.encode_utf16().chain(Some(0)).collect()
|
||||
}
|
||||
|
||||
fn size_kib(dir: &Path) -> u64 {
|
||||
fn walk(dir: &Path) -> u64 {
|
||||
std::fs::read_dir(dir).into_iter().flatten().flatten().map(|e| match e.file_type() {
|
||||
Ok(t) if t.is_dir() => walk(&e.path()),
|
||||
Ok(t) if t.is_file() => e.metadata().map_or(0, |m| m.len()),
|
||||
_ => 0,
|
||||
}).sum()
|
||||
}
|
||||
walk(dir) / 1024
|
||||
}
|
||||
|
||||
pub fn add(dir: &Path) -> Result<()> {
|
||||
let system = std::env::var("SystemRoot").unwrap_or_else(|_| r"C:\Windows".into());
|
||||
let d = dir.display();
|
||||
let text = [
|
||||
("DisplayName", super::DISPLAY.to_owned()),
|
||||
("DisplayVersion", env!("CARGO_PKG_VERSION").to_owned()),
|
||||
("Publisher", "Proxy Suite".to_owned()),
|
||||
("URLInfoAbout", "https://git.faumaray.com/faumaray/proxy-suite-flake".to_owned()),
|
||||
("InstallLocation", d.to_string()),
|
||||
("DisplayIcon", format!("{d}\\proxy-suite.exe")),
|
||||
// cmd's /c takes the whole line in one more pair of quotes.
|
||||
("UninstallString", format!("\"{system}\\System32\\cmd.exe\" /c \"\"{d}\\uninstall.cmd\"\"")),
|
||||
("QuietUninstallString", format!("\"{d}\\proxy-suite-service.exe\" uninstall")),
|
||||
];
|
||||
let numbers = [("NoModify", 1u32), ("NoRepair", 1), ("EstimatedSize", size_kib(dir).min(u32::MAX as u64) as u32)];
|
||||
// SAFETY: NUL-terminated names and data, lengths as given; the key is closed below.
|
||||
unsafe {
|
||||
let mut key: HKEY = std::ptr::null_mut();
|
||||
if RegCreateKeyExW(HKEY_LOCAL_MACHINE, wide(KEY).as_ptr(), 0, std::ptr::null(), REG_OPTION_NON_VOLATILE, KEY_WRITE, std::ptr::null(), &mut key, std::ptr::null_mut()) != ERROR_SUCCESS {
|
||||
bail!("cannot create the uninstall key");
|
||||
}
|
||||
let mut failed = false;
|
||||
for (name, value) in &text {
|
||||
let data = wide(value);
|
||||
failed |= RegSetValueExW(key, wide(name).as_ptr(), 0, REG_SZ, data.as_ptr().cast(), (data.len() * 2) as u32) != ERROR_SUCCESS;
|
||||
}
|
||||
for (name, value) in &numbers {
|
||||
failed |= RegSetValueExW(key, wide(name).as_ptr(), 0, REG_DWORD, (value as *const u32).cast(), 4) != ERROR_SUCCESS;
|
||||
}
|
||||
RegCloseKey(key);
|
||||
if failed {
|
||||
bail!("cannot write the uninstall key");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove() {
|
||||
// SAFETY: a NUL-terminated name.
|
||||
unsafe {
|
||||
RegDeleteTreeW(HKEY_LOCAL_MACHINE, wide(KEY).as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The desktop app: a Start Menu entry for everyone, and started at each sign-in into the tray;
|
||||
/// closed before its files are replaced or removed.
|
||||
mod desktop {
|
||||
|
||||
Reference in new issue
Block a user