fix(app): installer removes only its own files and stops on failed steps
- installer.sh lists every packaged file for the uninstaller, and folders are removed only when empty, so a chosen folder keeps other files. - A virtual monitor driver removal that fails stops the uninstall with everything kept (silent exit code 4); the elevated half exits 2 when there is no driver of ours to remove, which the uninstaller accepts. - WebView2 is installed before any file is copied; when it is still missing the installer asks to retry, or silently stops with code 3 without installing or starting anything. - The installer holds Global\JarvisBotSetup while it runs; jarvis.exe started meanwhile shows a message and exits before any window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -302,7 +302,9 @@ the browser runs headless with a note.
|
||||
devices, whatever their class (a device whose driver was declined has none).
|
||||
The settings: one monitor, one mode (1280x720 at 30 Hz), no custom EDID. When another program's
|
||||
copy of the same driver is installed (its `VDDPATH` is not ours) the app refuses to install or
|
||||
remove and never touches its monitors. Uninstall removes the device, then the driver package (one
|
||||
remove and never touches its monitors; the elevated half asked to remove a driver that is not
|
||||
ours (another program's, or none) does nothing and exits with code 2, which the app and the
|
||||
uninstaller take as nothing to remove. Uninstall removes the device, then the driver package (one
|
||||
not in the driver store counts as gone), and only then the registry key, which makes it ours, and
|
||||
the settings folder; when a device or the package stays, it fails with the reason and keeps the
|
||||
registry key, so a retry is still allowed.
|
||||
@@ -576,14 +578,23 @@ come with the first-run wizard into the data folder, which the installer never t
|
||||
asks the SignPath question once; a failure says it can be installed later from the features
|
||||
screen). Shortcuts are for every user of the PC.
|
||||
- The WebView2 runtime is installed with Microsoft's bootstrapper (inside the installer) only when
|
||||
the PC has none.
|
||||
- Before installing or removing, the installer waits for `jarvis.exe` to close: it asks with a
|
||||
retry, or silently waits up to 60 s (an update closes the app itself), then gives up.
|
||||
the PC has none, before any file is copied. When it is still missing afterwards the installer
|
||||
asks to retry or cancel; silently it stops with exit code 3, nothing installed and nothing
|
||||
started.
|
||||
- While it installs, updates or removes, the installer holds the named mutex
|
||||
`Global\JarvisBotSetup` (`setup_lock.rs`); `jarvis.exe` started meanwhile says so in a message
|
||||
box and exits (code 3) before any window or service. Before copying or removing, the installer
|
||||
also waits for `jarvis.exe` to close: it asks with a retry, or silently waits up to 60 s (an
|
||||
update closes the app itself), then gives up.
|
||||
- `/S` installs silently with the default components; `/S /RUN` starts the app again afterwards
|
||||
(the app's updates). The uninstall entry has the version, size and a quiet uninstall string.
|
||||
- Uninstall: the driver goes too when this app installed it (the elevated half refuses another
|
||||
program's copy), then only what the installer put there (a folder the person chose may hold
|
||||
other things), the shortcuts and the registry keys. The data folder stays.
|
||||
- Uninstall: the driver goes first when this app installed it (`--display-driver uninstall`:
|
||||
0 removed, 2 nothing of ours to remove; the elevated half refuses another program's copy). Any
|
||||
other result stops the uninstall with everything kept, so it can be run again (silently exit
|
||||
code 4). Then only what the installer put there goes: `installer.sh` lists every file of
|
||||
`python-src/` and `display-driver/` for the uninstaller (`uninstall-list.nsh`) and folders are
|
||||
removed only when empty, so a folder the person chose keeps its other things. Then the
|
||||
shortcuts and the registry keys. The data folder stays.
|
||||
|
||||
## Tests
|
||||
|
||||
@@ -656,5 +667,10 @@ entries, non-ASCII paths, the person's lists first, staying on until the game en
|
||||
detection off) and its settings. A removal forgets the driver only when no device is left and the package
|
||||
is gone or was not in the store; a failed install forgets it only under the same rule (and never
|
||||
when it was ours before), reporting both reasons otherwise; a leftover offers removal; driver tasks refused while the services start, and a start (and a
|
||||
second task) refused while one runs, also after it failed. On Linux the same window test runs on an X display (one window at the given place and
|
||||
second task) refused while one runs, also after it failed; removing a driver that is not ours says
|
||||
there is nothing to remove. The installer (by hand on a Windows VM): installing into a folder that
|
||||
holds other files and uninstalling keeps them; a driver removal that fails stops the uninstall with
|
||||
the files and entry kept, and nothing to remove lets it finish; with no WebView2 and its installer
|
||||
failing nothing is installed or started; with the lock held the app shows its message and exits
|
||||
after OK, and starts normally once released. On Linux the same window test runs on an X display (one window at the given place and
|
||||
size, the bot's tab in it).
|
||||
|
||||
@@ -29,6 +29,7 @@ pub mod secrets;
|
||||
pub mod services;
|
||||
pub mod settings;
|
||||
pub mod settings_edit;
|
||||
pub mod setup_lock;
|
||||
pub mod speakers;
|
||||
pub mod strata;
|
||||
pub mod system;
|
||||
|
||||
41
app/src/setup_lock.rs
Normal file
41
app/src/setup_lock.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
//! The installer's lock (admin.spec.md, "Installer"): while Jarvis is installed, updated or
|
||||
//! removed, the installer holds the named mutex `Global\JarvisBotSetup`, and the app does not
|
||||
//! start meanwhile (it would hold files being replaced, or start services on a driver being
|
||||
//! removed).
|
||||
|
||||
pub const MUTEX: &str = "Global\\JarvisBotSetup";
|
||||
|
||||
/// Whether an installer holds the lock (also when this user may not open it: it exists).
|
||||
#[cfg(windows)]
|
||||
pub fn held() -> bool {
|
||||
use windows_sys::Win32::Foundation::{CloseHandle, GetLastError, ERROR_ACCESS_DENIED};
|
||||
use windows_sys::Win32::System::Threading::{OpenMutexW, SYNCHRONIZATION_SYNCHRONIZE};
|
||||
let name: Vec<u16> = MUTEX.encode_utf16().chain(Some(0)).collect();
|
||||
// SAFETY: opening a named object by a NUL-terminated name; the handle is closed at once.
|
||||
unsafe {
|
||||
let h = OpenMutexW(SYNCHRONIZATION_SYNCHRONIZE, 0, name.as_ptr());
|
||||
if !h.is_null() {
|
||||
CloseHandle(h);
|
||||
return true;
|
||||
}
|
||||
GetLastError() == ERROR_ACCESS_DENIED
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub fn held() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Say so in a message box (the app has no window yet).
|
||||
#[cfg(windows)]
|
||||
pub fn tell() {
|
||||
use windows_sys::Win32::UI::WindowsAndMessaging::{MessageBoxW, MB_ICONINFORMATION, MB_OK};
|
||||
let text: Vec<u16> = "Jarvis를 설치하거나 제거하는 중입니다. 끝난 뒤 다시 실행해 주세요.".encode_utf16().chain(Some(0)).collect();
|
||||
let title: Vec<u16> = "Jarvis".encode_utf16().chain(Some(0)).collect();
|
||||
// SAFETY: NUL-terminated strings; no owner window.
|
||||
unsafe { MessageBoxW(std::ptr::null_mut(), text.as_ptr(), title.as_ptr(), MB_OK | MB_ICONINFORMATION) };
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub fn tell() {}
|
||||
@@ -124,12 +124,22 @@ pub async fn run_elevated(_action: &str) -> Result<(), String> {
|
||||
Err("가상 모니터는 Windows에서만 씁니다".into())
|
||||
}
|
||||
|
||||
/// The elevated half's exit code when removing finds no driver of this app's (none, or another
|
||||
/// program's copy): the uninstaller goes on. 0 is done, 1 failed (the uninstaller stops).
|
||||
pub const NOTHING_TO_REMOVE: i32 = 2;
|
||||
|
||||
/// `jarvis.exe --display-driver install|uninstall --result FILE`: the elevated half of
|
||||
/// `run_elevated`; the outcome (empty, or why it failed) goes to FILE. `None` without the option.
|
||||
pub fn elevated_main(args: &[String]) -> Option<i32> {
|
||||
let i = args.iter().position(|a| a == "--display-driver")?;
|
||||
let action = args.get(i + 1).map(String::as_str).unwrap_or("");
|
||||
let result = args.iter().position(|a| a == "--result").and_then(|j| args.get(j + 1)).map(PathBuf::from);
|
||||
if action == "uninstall" && !owns_driver() {
|
||||
if let Some(f) = &result {
|
||||
let _ = std::fs::write(f, "");
|
||||
}
|
||||
return Some(NOTHING_TO_REMOVE);
|
||||
}
|
||||
let outcome = match (action, driver_dir()) {
|
||||
(_, None) => Err("앱 폴더를 찾지 못했습니다".to_owned()),
|
||||
("install", Some(d)) => install(&d),
|
||||
@@ -142,6 +152,14 @@ pub fn elevated_main(args: &[String]) -> Option<i32> {
|
||||
Some(if outcome.is_ok() { 0 } else { 1 })
|
||||
}
|
||||
|
||||
/// Whether this app's driver (or something it left) is on the PC.
|
||||
fn owns_driver() -> bool {
|
||||
#[cfg(windows)]
|
||||
return win::ours();
|
||||
#[cfg(not(windows))]
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn install(_driver: &Path) -> Result<(), String> {
|
||||
Err("가상 모니터는 Windows에서만 씁니다".into())
|
||||
@@ -249,7 +267,7 @@ mod win {
|
||||
(r == ERROR_SUCCESS).then(|| text(&buf))
|
||||
}
|
||||
|
||||
fn ours() -> bool {
|
||||
pub(super) fn ours() -> bool {
|
||||
match (vdd_path(), config_dir()) {
|
||||
(Some(p), Some(c)) => p.trim_end_matches('\\').eq_ignore_ascii_case(c.to_string_lossy().trim_end_matches('\\')),
|
||||
_ => false,
|
||||
@@ -558,6 +576,7 @@ mod win {
|
||||
let _ = std::fs::remove_file(&result);
|
||||
match code {
|
||||
0 => Ok(()),
|
||||
c if c as i32 == super::NOTHING_TO_REMOVE && action == "uninstall" => Ok(()),
|
||||
_ if !why.is_empty() => Err(why),
|
||||
c => Err(format!("드라이버 작업이 실패했습니다 (종료 코드 {c})")),
|
||||
}
|
||||
@@ -653,4 +672,17 @@ mod tests {
|
||||
fn only_the_display_driver_option_runs_the_elevated_half() {
|
||||
assert_eq!(elevated_main(&["jarvis".into(), "--location".into(), "x".into()]), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_a_driver_this_app_does_not_own_says_there_is_nothing_to_remove() {
|
||||
// The uninstaller goes on with code 2, and stops on a failure (code 1).
|
||||
let result = std::env::temp_dir().join(format!("jarvis-vdd-test-{}.txt", std::process::id()));
|
||||
let args: Vec<String> = ["jarvis", "--display-driver", "uninstall", "--result", result.to_str().unwrap()]
|
||||
.map(String::from).into();
|
||||
assert_eq!(elevated_main(&args), Some(NOTHING_TO_REMOVE));
|
||||
assert_eq!(std::fs::read_to_string(&result).unwrap(), "");
|
||||
let _ = std::fs::remove_file(&result);
|
||||
let bad: Vec<String> = ["jarvis", "--display-driver", "nope"].map(String::from).into();
|
||||
assert_eq!(elevated_main(&bad), Some(1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user