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
Parse Windows 10 Settings catalogue entries and multi-word queries
jokwa1351dc2432e5a0b
diff --git a/crates/rf-app/src/settings_rows.rs b/crates/rf-app/src/settings_rows.rsindex 908f15a6..d68b4ec6 100644--- a/crates/rf-app/src/settings_rows.rs+++ b/crates/rf-app/src/settings_rows.rs@@ -71,7 +71,21 @@ fn rank(f: &Folded, q: &str) -> Option<i32> {};best = best.max(s);}- best+ if best.is_some() {+ return best;+ }+ let tokens: Vec<&str> = q.split_whitespace().collect();+ if tokens.len() >= 2 {+ let has_word = |hay: &str, tok: &str| hay.split(|c: char| !c.is_alphanumeric()).any(|w| w.starts_with(tok));+ if tokens.iter().all(|t| has_word(&f.name, t)) {+ let page = f.entry.place.is_empty() && !f.entry.launch.is_classic();+ return Some(260 + if page { PAGE_FIRST } else { 0 });+ }+ if tokens.iter().all(|t| has_word(&f.name, t) || f.words.iter().any(|w| has_word(w, t))) {+ return Some(220);+ }+ }+ None}fn rows_of(all: &[Folded], q: &str, lift: &dyn Fn(&Target) -> i32) -> Vec<Item> {@@ -236,4 +250,15 @@ mod tests {let rows = rows_of(&sample(), &fold("ses"), &|t| if matches!(t, Target::Setting { name, .. } if name == "Ses düzeyi karıştırıcısı") { 500 } else { 0 });assert_eq!(rows[0].title, "Ses düzeyi karıştırıcısı");}++ #[test]+ fn multi_word_queries_match_non_adjacent_title_and_keyword_words() {+ let all = vec![+ entry("Add or remove programs", "Apps & features", "uninstall", Launch::Page("SettingsPageAppsSizes".into())),+ entry("Bluetooth and other devices settings", "", "bluetooth;pairing", Launch::Page("SettingsPageDevices".into())),+ ];+ assert_eq!(rows_of(&all, &fold("add remove"), &|_| 0)[0].title, "Add or remove programs");+ assert_eq!(rows_of(&all, &fold("bluetooth"), &|_| 0)[0].title, "Bluetooth and other devices settings");+ assert_eq!(rows_of(&all, &fold("bluetooth pairing"), &|_| 0)[0].title, "Bluetooth and other devices settings");+ }}diff --git a/crates/rf-win/src/settingscat.rs b/crates/rf-win/src/settingscat.rsindex 6dece7b9..0e010938 100644--- a/crates/rf-win/src/settingscat.rs+++ b/crates/rf-win/src/settingscat.rs@@ -145,8 +145,19 @@ pub fn parse(xml: &str) -> Vec<Raw> {raw.depth = nodes.len();raw.page = nodes.first().filter(|(kind, _)| *kind == "Page").map(|(_, text)| unescape(text));}+ let raw_page_id = tag(block, "PageID").filter(|d| !d.is_empty()).map(unescape);raw.deep_link = tag(block, "DeepLink").filter(|d| !d.is_empty()).map(unescape);- raw.page_id = tag(block, "PageID").filter(|d| !d.is_empty()).map(|p| p.to_ascii_uppercase());+ raw.page_id = raw_page_id.as_ref().map(|p| p.to_ascii_uppercase());+ // Windows 10 AllSystemSettings XML uses `<PageID>` / `<GroupID>` directly without `<SettingPaths><Path>`.+ if raw.page.is_none()+ && raw.deep_link.is_none()+ && let Some(pid) = raw_page_id+ && !pid.starts_with('{')+ && !pid.eq_ignore_ascii_case(DEFENDER_PAGE)+ {+ raw.page = Some(pid);+ raw.depth = if tag(block, "GroupID").filter(|g| !g.is_empty()).is_some() { 2 } else { 1 };+ }out.push(raw);}out@@ -221,9 +232,11 @@ fn clean(s: &str) -> String {s.replace(['\t', '\n', '\r'], " ")}+const CACHE_VERSION: &str = "2";+/// The file's text: a first line with the key the file is valid for, then one entry a line.pub fn to_text(key: &str, entries: &[Entry]) -> String {- let mut s = format!("rustyfiles-settings-catalogue\t1\t{}\n", clean(key));+ let mut s = format!("rustyfiles-settings-catalogue\t{CACHE_VERSION}\t{}\n", clean(key));for e in entries {s.push_str(&format!("{}\t{}\t{}\t{}\n", clean(&e.name), clean(&e.place), clean(&e.keywords), clean(&e.launch.encode())));}@@ -234,7 +247,7 @@ pub fn to_text(key: &str, entries: &[Entry]) -> String {pub fn from_text(key: &str, text: &str) -> Option<Vec<Entry>> {let mut lines = text.lines();let head: Vec<&str> = lines.next()?.split('\t').collect();- if head.len() != 3 || head[0] != "rustyfiles-settings-catalogue" || head[1] != "1" || head[2] != clean(key) {+ if head.len() != 3 || head[0] != "rustyfiles-settings-catalogue" || head[1] != CACHE_VERSION || head[2] != clean(key) {return None;}let mut out = Vec::new();@@ -294,6 +307,24 @@ fn resolve(reference: &str) -> Option<String> {(!s.is_empty() && !s.starts_with('@')).then_some(s)}+struct ComGuard(bool);++impl ComGuard {+ fn init() -> Self {+ use windows::Win32::System::Com::{COINIT_MULTITHREADED, CoInitializeEx};+ let hr = unsafe { CoInitializeEx(None, COINIT_MULTITHREADED) };+ ComGuard(hr.is_ok())+ }+}++impl Drop for ComGuard {+ fn drop(&mut self) {+ if self.0 {+ unsafe { windows::Win32::System::Com::CoUninitialize() };+ }+ }+}+/// Reads the catalogue: from the small file in `cache_dir` when it is valid, else from Windows' files (seconds), writing the small/// file for the next time. Blocks: never on the UI thread.pub fn load(cache_dir: &Path) -> Vec<Entry> {@@ -306,6 +337,8 @@ pub fn load(cache_dir: &Path) -> Vec<Entry> {if let Some(entries) = std::fs::read_to_string(&cache).ok().and_then(|t| from_text(&key, &t)) {return entries;}+ // SHLoadIndirectString needs COM initialized on this worker thread for @{windows?ms-resource://...} strings on Win10.+ let _com = ComGuard::init();let began = std::time::Instant::now();let mut raws = Vec::new();for f in &files {@@ -546,6 +579,33 @@ mod tests {// a tab or a line break in a name cannot break the filelet odd = vec![Entry { name: "a\tb\nc".into(), place: String::new(), keywords: String::new(), launch: Launch::Page("P".into()) }];assert_eq!(from_text("k", &to_text("k", &odd)).unwrap()[0].name, "a b c");+ // version 1 caches are ignored so older Win10 caches rebuild+ assert_eq!(from_text("k", "rustyfiles-settings-catalogue\t1\tk\n"), None);+ }++ #[test]+ fn windows_10_page_id_entries_without_path_resolve_to_settings_pages() {+ let xml = r#"<PCSettings>+ <SearchableContent>+ <Filename>Bluetooth.xml</Filename>+ <SettingIdentity><PageID>SettingsPageDevices</PageID></SettingIdentity>+ <SettingInformation><Description>Bluetooth and other devices settings</Description></SettingInformation>+ </SearchableContent>+ <SearchableContent>+ <Filename>AddRemove.xml</Filename>+ <SettingIdentity><PageID>SettingsPageAppsSizes</PageID><GroupID>AppsGroup</GroupID></SettingIdentity>+ <SettingInformation><Description>Add or remove programs</Description></SettingInformation>+ </SearchableContent>+</PCSettings>"#;+ let raws = parse(xml);+ assert_eq!(raws.len(), 2);+ assert_eq!((raws[0].page.as_deref(), raws[0].depth), (Some("SettingsPageDevices"), 1));+ assert_eq!((raws[1].page.as_deref(), raws[1].depth), (Some("SettingsPageAppsSizes"), 2));+ let entries = build(&raws, &table);+ assert_eq!(entries.len(), 2);+ assert_eq!(entries[0].launch, Launch::Page("SettingsPageDevices".into()));+ assert_eq!(entries[1].place, "");+ assert_eq!(entries[1].launch, Launch::Page("SettingsPageAppsSizes".into()));}#[test]