A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
As the Windows shell, connect the remembered network drives at sign-in (751)
gelenmedyadb223f1a3e23
diff --git a/crates/rf-app/src/dock/host.rs b/crates/rf-app/src/dock/host.rsindex 5a108768..5cedc8a5 100644--- a/crates/rf-app/src/dock/host.rs+++ b/crates/rf-app/src/dock/host.rs@@ -2061,6 +2061,19 @@ pub fn run(messages: Option<UnboundedReceiver<String>>, cx: &mut App) {// The guard that started this host as the Windows shell waits for word that the desktop is usable (issue 757: the word never// came, so every sign-in ended in the guard's fall-back to Explorer). Queued after the windows' setup job above, so it comes once// they exist. Nothing happens in a dock the file manager started (the guard's variable is not there).+ // Started by the guard as the Windows shell: the mapped network drives Explorer would have connected at sign-in are connected+ // here (issue 751), on a thread of their own (a server that is away takes seconds).+ if std::env::var_os(rf_win::shellhost::ready::VAR).is_some() {+ let _ = std::thread::Builder::new().name("restore network drives".into()).spawn(|| {+ for (letter, answer) in rf_win::network::restore_remembered_drives() {+ if answer == 0 {+ log::info!("shell: network drive {letter}: connected again");+ } else {+ log::warn!("shell: network drive {letter}: not connected again (error {answer})");+ }+ }+ });+ }on_message_loop(cx, || match rf_win::shellhost::ready::signal_if_asked() {Ok(true) => log::info!("shell: the guard was told the desktop is ready"),Ok(false) => {}diff --git a/crates/rf-win/src/network.rs b/crates/rf-win/src/network.rsindex 9e113a46..7af7ff99 100644--- a/crates/rf-win/src/network.rs+++ b/crates/rf-win/src/network.rs@@ -114,6 +114,45 @@ pub fn network_shortcuts() -> Vec<(String, PathBuf)> {out}+/// The network drives the user mapped to come back at every sign-in (`HKCU\Network\<letter>`) that are not connected now, connected+/// again with what Windows remembers for them (no window is shown: a drive whose server is away just stays away). Each letter with+/// the answer (0: connected). Blocks while a server is slow: call off the UI thread.+///+/// WHY (issue 751: with rustyfiles as the Windows shell, a VMware shared folder mapped as Z: was missing and its "network location"+/// led nowhere). Explorer connects them again at every sign-in ("Restoring network connections"); with rustyfiles as the shell,+/// Explorer does not start, so nothing did.+pub fn restore_remembered_drives() -> Vec<(char, u32)> {+ // (in mpr.dll but not in the SDK's import library: looked up at run time)+ type Restore = unsafe extern "system" fn(*mut std::ffi::c_void, *const u16, i32) -> u32;+ let restore: Option<Restore> = unsafe {+ windows::Win32::System::LibraryLoader::LoadLibraryW(windows::core::w!("mpr.dll"))+ .ok()+ .and_then(|m| windows::Win32::System::LibraryLoader::GetProcAddress(m, windows::core::s!("WNetRestoreSingleConnectionW")))+ .map(|f| std::mem::transmute::<unsafe extern "system" fn() -> isize, Restore>(f))+ };+ let Some(restore) = restore else { return Vec::new() };+ let remembered: Vec<char> = windows_registry::CURRENT_USER+ .open("Network")+ .and_then(|k| k.keys().map(|it| it.filter_map(|n| drive_letter_key(&n)).collect()))+ .unwrap_or_default();+ let present = unsafe { windows::Win32::Storage::FileSystem::GetLogicalDrives() };+ remembered+ .into_iter()+ .filter(|l| present & (1 << (*l as u32 - 'A' as u32)) == 0)+ .map(|l| {+ let device = wide(format!("{l}:"));+ (l, unsafe { restore(std::ptr::null_mut(), device.as_ptr(), 0) })+ })+ .collect()+}++/// A key under `HKCU\Network` is a drive letter (`Z`); anything else is not a mapped drive.+fn drive_letter_key(name: &str) -> Option<char> {+ let mut chars = name.chars();+ let c = chars.next()?.to_ascii_uppercase();+ (chars.next().is_none() && c.is_ascii_uppercase()).then_some(c)+}+#[cfg(test)]mod tests {use super::*;@@ -186,3 +225,24 @@ pub fn lan_link() -> Option<(LinkType, u32)> {let bps = row.TransmitLinkSpeed;(bps != u64::MAX && bps >= 1_000_000).then(|| (kind, (bps / 1_000_000).min(u64::from(u32::MAX)) as u32))}++#[cfg(test)]+mod remembered_tests {+ #[test]+ fn only_a_single_letter_key_is_a_mapped_drive() {+ assert_eq!(super::drive_letter_key("Z"), Some('Z'));+ assert_eq!(super::drive_letter_key("z"), Some('Z'));+ assert_eq!(super::drive_letter_key("ZZ"), None);+ assert_eq!(super::drive_letter_key(""), None);+ assert_eq!(super::drive_letter_key("1"), None);+ }++ /// Reads the user's real list and connects nothing that is already there (here: none or all present). Never panics.+ #[test]+ fn restoring_with_nothing_missing_does_nothing() {+ let present = unsafe { windows::Win32::Storage::FileSystem::GetLogicalDrives() };+ for (l, _) in super::restore_remembered_drives() {+ assert_eq!(present & (1 << (l as u32 - 'A' as u32)), 0, "{l}: was there already and was asked again");+ }+ }+}