Skip to content

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.

Network drives: the name Explorer's Rename gives, read and written

gelenmedya1ed8391da785
diff --git a/crates/rf-app/src/properties_view.rs b/crates/rf-app/src/properties_view.rs
index 6a119302..bc0c8eea 100644
--- a/crates/rf-app/src/properties_view.rs
+++ b/crates/rf-app/src/properties_view.rs
@@ -803,6 +803,9 @@ impl PropsView {
_ => None,
};
let label = self.label_now(cx);
+ // a mapped network drive's share: its name is changed as Explorer's Rename does, not on the server (issue 729)
+ let network_share =
+ self.drive.as_ref().filter(|d| d.kind == rf_win::drives::DriveKind::Network).and_then(|d| rf_win::drives::share_of(d.letter));
let cancel = self.cancel.clone();
self.busy = true;
self.error = None;
@@ -861,7 +864,12 @@ impl PropsView {
if let Some((was, now)) = &desc {
rf_win::props::set_editable(&paths[0], was, now).map_err(|e| named(&paths[0], &format!("{e:#}")))?;
}
- if let Some(l) = &label {
+ if let Some(l) = &label
+ && let Some(share) = &network_share
+ {
+ rf_win::drives::set_mapped_label(share, l).map_err(|e| named(&paths[0], &e))?;
+ rf_win::shell::notify_updated(&paths[0]);
+ } else if let Some(l) = &label {
// (a fixed drive needs an administrator: Windows says "access denied", we never elevate)
rf_win::volume::set_label(&paths[0], l).map_err(|e| match e.kind() {
std::io::ErrorKind::PermissionDenied => t!("Bu sürücünün etiketini değiştirmek yönetici izni ister").to_string(),
diff --git a/crates/rf-win/src/drives.rs b/crates/rf-win/src/drives.rs
index 34c13291..a0ee6d78 100644
--- a/crates/rf-win/src/drives.rs
+++ b/crates/rf-win/src/drives.rs
@@ -143,7 +143,8 @@ fn list_drives_except(skip: u32) -> Vec<Drive> {
if drives.iter().any(|d| d.kind == DriveKind::Network) {
let mapped = mapped_drives();
for d in drives.iter_mut().filter(|d| d.kind == DriveKind::Network) {
- if let Some(name) = mapped.iter().find(|(l, _)| *l == d.letter).and_then(|(_, share)| share_label(share)) {
+ // (the name the user gave it in Explorer or here comes first: issue 729)
+ if let Some(name) = mapped.iter().find(|(l, _)| *l == d.letter).and_then(|(_, share)| mapped_label(share).or_else(|| share_label(share))) {
d.label = name;
}
}
@@ -159,6 +160,35 @@ pub fn share_label(share: &str) -> Option<String> {
(!server.is_empty()).then(|| format!(r"{name} (\\{server})"))
}
+/// Where Explorer keeps the name a user gave a mapped share: `MountPoints2\##nas#media`, value `_LabelFromReg`. The share's own
+/// volume label belongs to the server and cannot be changed from here (SetVolumeLabel answers "not supported", issue 729); this
+/// name is the one Explorer's Rename of a network drive writes, per user.
+fn mount_point_key(share: &str) -> String {
+ format!(r"Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\{}", share.replace('\\', "#"))
+}
+
+/// The name the user gave a mapped share (`\\nas\media`), when there is one.
+pub fn mapped_label(share: &str) -> Option<String> {
+ windows_registry::CURRENT_USER.open(mount_point_key(share)).ok()?.get_string("_LabelFromReg").ok().filter(|l| !l.trim().is_empty())
+}
+
+/// Names a mapped share as Explorer's Rename does; an empty name, or its default one, gives it back the default (`media (\\nas)`).
+pub fn set_mapped_label(share: &str, label: &str) -> std::io::Result<()> {
+ let key = windows_registry::CURRENT_USER.create(mount_point_key(share)).map_err(std::io::Error::other)?;
+ let label = label.trim();
+ if label.is_empty() || share_label(share).as_deref() == Some(label) {
+ let _ = key.remove_value("_LabelFromReg");
+ } else {
+ key.set_string("_LabelFromReg", label).map_err(std::io::Error::other)?;
+ }
+ Ok(())
+}
+
+/// The share a mapped drive letter is connected to (`Z` → `\\nas\media`).
+pub fn share_of(letter: char) -> Option<String> {
+ mapped_drives().into_iter().find(|(l, _)| l.eq_ignore_ascii_case(&letter)).map(|(_, s)| s)
+}
+
/// How long the list waits for a network drive's name and size (`list_drives_except`).
const NETWORK_WAIT: std::time::Duration = std::time::Duration::from_millis(400);
@@ -373,6 +403,7 @@ mod network_tests {
assert_eq!(super::share_label(r"\\srv\data\projects").as_deref(), Some(r"projects (\\srv)"));
assert_eq!(super::share_label(r"C:\x"), None);
assert_eq!(super::share_label(r"\\srv"), None);
+ assert_eq!(super::mount_point_key(r"\\nas\media"), r"Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##nas#media");
}
use std::path::Path;