//! 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 = 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 = "Jarvis를 설치하거나 제거하는 중입니다. 끝난 뒤 다시 실행해 주세요.".encode_utf16().chain(Some(0)).collect(); let title: Vec = "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() {}