wininskit 0.1.2

Thin checked wrappers over the Win32 an installer needs: elevation, ACLs, services, the Restart Manager, the registry and shortcuts.
use std::{path::Path, ptr};

use windows_sys::Win32::Storage::FileSystem::{MOVEFILE_DELAY_UNTIL_REBOOT, MoveFileExW};

use crate::{
    error::{Error, Result},
    wide::wide_path,
};

/// Asks Windows to delete `path` at the next restart.
///
/// The uninstaller lives inside the folder it is removing, so it cannot delete
/// its own file while it is running. Everything else goes immediately and this
/// leaves the last two entries - the executable and the folder that now only
/// holds it - to the restart.
///
/// The folder is only removed if it is empty by then, which is the behaviour
/// wanted: anything a person put in there afterwards keeps it alive.
pub fn delete_after_restart(path: &Path) -> Result<()> {
    let wide = wide_path(path);
    // A null destination with this flag means delete rather than move.
    if unsafe { MoveFileExW(wide.as_ptr(), ptr::null(), MOVEFILE_DELAY_UNTIL_REBOOT) } == 0 {
        return Err(Error::last("MoveFileExW"));
    }
    Ok(())
}