From 08b8c7e648befce0218654ecd6ceb5ab91f1dc3b Mon Sep 17 00:00:00 2001 From: Alexander Arques Date: Fri, 13 Nov 2026 20:57:12 +0100 Subject: [PATCH 1/2] Allow opt-in scans of non-Windows drive roots Support dedicated game volumes while preserving the default root restriction and pruning Windows-managed directories from both filesystem walks. --- src/backend.rs | 3 ++- src/config.rs | 3 +++ src/directstorage.rs | 4 +++ src/folder.rs | 58 +++++++++++++++++++++++++++++++++----------- src/gui.rs | 7 ++++++ src/ui/app.js | 2 ++ src/ui/index.html | 7 ++++++ 7 files changed, 69 insertions(+), 15 deletions(-) diff --git a/src/backend.rs b/src/backend.rs index cf8970a..3f4f60e 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -233,7 +233,8 @@ impl Backend { } fn target_is_valid(&self, path: &Path) -> bool { - match validate_target_path(path) { + let allow = config().read().unwrap().current().allow_drive_roots; + match validate_target_path(path, allow) { Ok(()) => true, Err(message) => { self.gui.error("Folder not supported", &message); diff --git a/src/config.rs b/src/config.rs index 883388c..bbf322e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -88,6 +88,8 @@ pub struct Config { pub hdd_single_thread: bool, #[serde(default = "default_protect_direct_storage")] pub protect_direct_storage: bool, + #[serde(default)] + pub allow_drive_roots: bool, #[serde(default = "default_compression_priority")] pub compression_priority: CompressionPriority, pub excludes: Vec, @@ -102,6 +104,7 @@ impl Default for Config { max_threads: default_max_threads(), hdd_single_thread: default_hdd_single_thread(), protect_direct_storage: default_protect_direct_storage(), + allow_drive_roots: false, compression_priority: default_compression_priority(), excludes: vec![ "*:\\Windows*", diff --git a/src/directstorage.rs b/src/directstorage.rs index 7908b01..8de4177 100644 --- a/src/directstorage.rs +++ b/src/directstorage.rs @@ -3,6 +3,8 @@ use std::path::{Path, PathBuf}; use walkdir::WalkDir; +use crate::folder::{is_protected_root_dir, volume_root_path}; + const DIRECT_STORAGE_DLLS: &[&str] = &["dstorage.dll", "dstoragecore.dll"]; // These are library/container directories, not individual games. When a @@ -220,9 +222,11 @@ pub fn discover_direct_storage_roots(scan_root: &Path) -> Vec { let mut dlls = Vec::new(); let mut exe_dirs = HashSet::new(); + let volume_root = volume_root_path(scan_root); for entry in WalkDir::new(scan_root) .follow_links(false) .into_iter() + .filter_entry(|entry| !is_protected_root_dir(entry, volume_root.as_deref())) .filter_map(Result::ok) .filter(|entry| entry.file_type().is_file()) { diff --git a/src/folder.rs b/src/folder.rs index 745d32c..cd7f14b 100644 --- a/src/folder.rs +++ b/src/folder.rs @@ -252,7 +252,7 @@ fn wide_null(path: &Path) -> Vec { .collect() } -fn volume_root_path(path: &Path) -> Option { +pub(crate) fn volume_root_path(path: &Path) -> Option { match path.components().next()? { Component::Prefix(prefix) => match prefix.kind() { Prefix::Disk(letter) | Prefix::VerbatimDisk(letter) => { @@ -265,10 +265,12 @@ fn volume_root_path(path: &Path) -> Option { } fn normalized_path(path: &Path) -> String { - path.to_string_lossy() - .replace('/', "\\") - .trim_end_matches('\\') - .to_ascii_lowercase() + let path = path.to_string_lossy().replace('/', "\\"); + let path = match path.strip_prefix(r"\\?\") { + Some(rest) if rest.as_bytes().get(1) == Some(&b':') => rest, + _ => &path, + }; + path.trim_end_matches('\\').to_ascii_lowercase() } fn path_is_same_or_child(path: &Path, parent: &Path) -> bool { @@ -340,7 +342,26 @@ fn cluster_size_for_path(path: &Path) -> u64 { } } -pub fn validate_target_path(path: &Path) -> Result<(), String> { +/// Windows-managed top-level directories (recycle bin, System Volume Information, +/// Recovery, other `$*`) are never walked, even when the user selects a whole drive. +pub(crate) fn is_protected_root_dir(entry: &walkdir::DirEntry, root: Option<&Path>) -> bool { + let Some(root) = root else { return false }; + let Some(parent) = entry.path().parent() else { + return false; + }; + if entry.file_type().is_file() || normalized_path(parent) != normalized_path(root) { + return false; + } + is_protected_root_name(&entry.file_name().to_string_lossy()) +} + +fn is_protected_root_name(name: &str) -> bool { + name.eq_ignore_ascii_case("system volume information") + || name.eq_ignore_ascii_case("recovery") + || name.starts_with('$') +} + +pub fn validate_target_path(path: &Path, allow_drive_roots: bool) -> Result<(), String> { if !path.exists() { return Err("The selected folder no longer exists.".to_string()); } @@ -353,8 +374,16 @@ pub fn validate_target_path(path: &Path) -> Result<(), String> { .to_string() })?; + let system_root = std::env::var_os("SystemRoot").map(PathBuf::from); if normalized_path(path) == normalized_path(&root) { - return Err("Select a folder rather than an entire drive root.".to_string()); + if !allow_drive_roots { + return Err("Select a folder or enable Allow scanning entire drives in Settings.".to_string()); + } + let windows_volume = system_root.as_deref().and_then(volume_root_path) + .ok_or_else(|| "Unable to identify the active Windows volume.".to_string())?; + if normalized_path(&root) == normalized_path(&windows_volume) { + return Err("The active Windows volume root is protected from compression.".to_string()); + } } let filesystem = volume_filesystem(path) @@ -370,8 +399,8 @@ pub fn validate_target_path(path: &Path) -> Result<(), String> { )); } - if let Some(system_root) = std::env::var_os("SystemRoot") { - if path_is_same_or_child(path, &PathBuf::from(system_root)) { + if let Some(system_root) = system_root { + if path_is_same_or_child(path, &system_root) { return Err("The active Windows directory is protected from compression.".to_string()); } } @@ -383,10 +412,7 @@ pub fn validate_target_path(path: &Path) -> Result<(), String> { .map(|value| value.trim_start_matches('\\')) { let first = relative.split('\\').next().unwrap_or_default(); - if first.eq_ignore_ascii_case("system volume information") - || first.eq_ignore_ascii_case("recovery") - || first.starts_with('$') - { + if is_protected_root_name(first) { return Err("The selected folder is a protected Windows-managed path.".to_string()); } } @@ -872,9 +898,13 @@ impl Background for FolderScan { let mut last_status = Instant::now(); + let scan_root = volume_root_path(&path); let walker = WalkDir::new(&path) .into_iter() - .filter_entry(|e| e.file_type().is_file() || !excludes.is_match(e.path())) + .filter_entry(|e| { + e.file_type().is_file() + || (!excludes.is_match(e.path()) && !is_protected_root_dir(e, scan_root.as_deref())) + }) .filter_map(|e| e.map_err(|e| eprintln!("Error: {:?}", e)).ok()) .filter(|e| e.file_type().is_file()) .filter_map(|e| e.metadata().map(|md| (e, md)).ok()) diff --git a/src/gui.rs b/src/gui.rs index c129d3d..783772c 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -26,6 +26,7 @@ pub enum GuiRequest { max_threads: usize, hdd_single_thread: bool, protect_direct_storage: bool, + allow_drive_roots: bool, compression_priority: String, excludes: String, }, @@ -76,6 +77,7 @@ pub enum GuiResponse { max_threads: usize, hdd_single_thread: bool, protect_direct_storage: bool, + allow_drive_roots: bool, compression_priority: String, excludes: String, }, @@ -149,6 +151,7 @@ impl GuiWrapper { max_threads: s.max_threads, hdd_single_thread: s.hdd_single_thread, protect_direct_storage: s.protect_direct_storage, + allow_drive_roots: s.allow_drive_roots, compression_priority: s.compression_priority.to_string(), excludes: s.excludes.join("\n"), }); @@ -262,6 +265,7 @@ pub fn spawn_gui() { max_threads, hdd_single_thread, protect_direct_storage, + allow_drive_roots, compression_priority, excludes, }) => { @@ -272,6 +276,7 @@ pub fn spawn_gui() { max_threads, hdd_single_thread, protect_direct_storage, + allow_drive_roots, compression_priority: compression_priority.parse().unwrap_or_default(), excludes: excludes.split('\n').map(str::to_owned).collect(), }; @@ -292,6 +297,7 @@ pub fn spawn_gui() { max_threads: s.max_threads, hdd_single_thread: s.hdd_single_thread, protect_direct_storage: s.protect_direct_storage, + allow_drive_roots: s.allow_drive_roots, compression_priority: s.compression_priority.to_string(), excludes: s.excludes.join("\n"), }, @@ -320,6 +326,7 @@ pub fn spawn_gui() { max_threads: s.max_threads, hdd_single_thread: s.hdd_single_thread, protect_direct_storage: s.protect_direct_storage, + allow_drive_roots: s.allow_drive_roots, compression_priority: s.compression_priority.to_string(), excludes: s.excludes.join("\n"), }, diff --git a/src/ui/app.js b/src/ui/app.js index 3e242d1..7dc72ef 100644 --- a/src/ui/app.js +++ b/src/ui/app.js @@ -222,6 +222,7 @@ var Response = (function() { Gui.set_compression_priority(msg.compression_priority); Gui.set_hdd_single_thread(msg.hdd_single_thread); Gui.set_protect_direct_storage(msg.protect_direct_storage); + $("#Allow_Drive_Roots").prop("checked", msg.allow_drive_roots); Gui.set_excludes(msg.excludes); break; @@ -337,6 +338,7 @@ var Gui = (function() { compression_priority: $("#Compression_Priority").val(), hdd_single_thread: $("#HDD_Single_Thread").prop("checked"), protect_direct_storage: $("#Protect_DirectStorage").prop("checked"), + allow_drive_roots: $("#Allow_Drive_Roots").prop("checked"), excludes: $("#Excludes").val() }); }); diff --git a/src/ui/index.html b/src/ui/index.html index a0aed23..f87211d 100644 --- a/src/ui/index.html +++ b/src/ui/index.html @@ -164,6 +164,13 @@

Compression

Skip detected DirectStorage game roots so WOF compression does not interfere with their fast I/O path. + From 9df999b55b434a476163471a2352a03957bc18b2 Mon Sep 17 00:00:00 2001 From: Alexander Arques Date: Fri, 13 Nov 2026 21:06:11 +0100 Subject: [PATCH 2/2] Use a GUI setter for the drive root setting --- src/ui/app.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ui/app.js b/src/ui/app.js index 7dc72ef..7b249d5 100644 --- a/src/ui/app.js +++ b/src/ui/app.js @@ -222,7 +222,7 @@ var Response = (function() { Gui.set_compression_priority(msg.compression_priority); Gui.set_hdd_single_thread(msg.hdd_single_thread); Gui.set_protect_direct_storage(msg.protect_direct_storage); - $("#Allow_Drive_Roots").prop("checked", msg.allow_drive_roots); + Gui.set_allow_drive_roots(msg.allow_drive_roots); Gui.set_excludes(msg.excludes); break; @@ -467,6 +467,10 @@ var Gui = (function() { $("#HDD_Single_Thread").prop("checked", enabled); }, + set_allow_drive_roots: function(enabled) { + $("#Allow_Drive_Roots").prop("checked", enabled); + }, + set_protect_direct_storage: function(enabled) { $("#Protect_DirectStorage").prop("checked", enabled); },