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
//! "Set as default file manager" (Files' Advanced setting), per-user (HKCU only, no admin):
//! folders and Win+E open in rustyfiles. Same keys as Files' SetFilesAsDefault.reg. Archives
//! are offered as an app registration (see `register_app`): the user picks rustyfiles for them
//! in Windows' Default apps.
//!
//! The app must hand non-folder arguments (e.g. `::{CLSID}` shell namespaces like Control Panel)
//! back to explorer.exe — see `rf-app` main.
use windows_registry::{CURRENT_USER, Key};
pub const CLASSES: &str = r"Software\Classes";
const WIN_E_CLSID: &str = r"CLSID\{52205fd8-5dfb-447d-801a-d0b52f2e83e1}";
/// zip (CompressedFolder) and 7z, rar, tar, gz… (ArchiveFolder): their `open` verbs. Earlier
/// versions pointed these at rustyfiles; no more: "Open with" then merged Windows' own handler
/// ("File Explorer") with ours into one entry with Explorer's name. Ours are removed.
const ARCHIVE_VERBS: [&str; 2] = [r"CompressedFolder\shell\open", r"ArchiveFolder\shell\open"];
fn set_command(base: &Key, sub: &str, command: &str) -> anyhow::Result<()> {
let k = base.create(sub)?;
k.set_string("", command)?;
k.set_string("DelegateExecute", "")?;
Ok(())
}
/// Registers `exe` under `classes_root` (normally `CLASSES`; tests pass a scratch key).
pub fn enable(exe: &str, classes_root: &str) -> anyhow::Result<()> {
let base = CURRENT_USER.create(classes_root)?;
let cmd = format!("\"{exe}\" \"%1\"");
set_command(&base, r"Folder\shell\open\command", &cmd)?;
set_command(&base, r"Folder\shell\explore\command", &cmd)?;
set_command(&base, &format!(r"{WIN_E_CLSID}\shell\opennewwindow\command"), &format!("\"{exe}\""))?;
remove_archive_verbs(classes_root);
register_app(exe, classes_root)
}
/// Archive types rustyfiles browses, offered in Windows' Default apps and "Open with". Which
/// app opens them is the user's choice (Windows keeps it signed; no program may set it).
pub const ARCHIVE_EXTS: [&str; 9] = [".zip", ".7z", ".rar", ".tar", ".tgz", ".txz", ".tzst", ".tbz2", ".tbz"];
const PROGID: &str = "rustyfiles.Archive";
/// Name under RegisteredApplications (`ms-settings:defaultapps?registeredAppUser=rustyfiles`).
pub const APP_NAME: &str = "rustyfiles";
/// `Software` for `Software\Classes` (tests use a scratch root).
fn software_root(classes_root: &str) -> &str {
classes_root.strip_suffix(r"\Classes").unwrap_or(classes_root)
}
/// Registers rustyfiles as an app that opens archives (Default Programs capabilities): it
/// can then be picked in Settings → Default apps or "Open with → Always". Changes no default.
pub fn register_app(exe: &str, classes_root: &str) -> anyhow::Result<()> {
let base = CURRENT_USER.create(classes_root)?;
let p = base.create(PROGID)?;
p.set_string("", "Sıkıştırılmış arşiv")?;
// the zip folder icon, not ours: archives must still look like archives
base.create(format!(r"{PROGID}\DefaultIcon"))?.set_expand_string("", r"%SystemRoot%\system32\zipfldr.dll")?;
// a plain command: `DelegateExecute` (needed above to beat HKLM's) would make Windows list
// this handler as File Explorer
let _ = base.remove_tree(format!(r"{PROGID}\shell"));
base.create(format!(r"{PROGID}\shell\open\command"))?.set_string("", format!("\"{exe}\" \"%1\""))?;
// the name and icon "Open with" / Default apps show for this handler
let app = base.create(format!(r"{PROGID}\Application"))?;
app.set_string("ApplicationName", "rustyfiles")?;
app.set_string("ApplicationIcon", format!("\"{exe}\",0"))?;
app.set_string("ApplicationCompany", "rustyfiles")?;
for e in ARCHIVE_EXTS {
base.create(format!(r"{e}\OpenWithProgids"))?.set_string(PROGID, "")?;
}
let root = software_root(classes_root);
let caps_path = format!(r"{root}\rustyfiles\Capabilities");
let caps = CURRENT_USER.create(&caps_path)?;
caps.set_string("ApplicationName", "rustyfiles")?;
caps.set_string("ApplicationDescription", "Hızlı dosya yöneticisi")?;
let fa = caps.create("FileAssociations")?;
for e in ARCHIVE_EXTS {
fa.set_string(e, PROGID)?;
}
CURRENT_USER.create(format!(r"{root}\RegisteredApplications"))?.set_string(APP_NAME, &caps_path)?;
Ok(())
}
fn unregister_app(classes_root: &str) {
let Ok(base) = CURRENT_USER.create(classes_root) else { return };
let _ = base.remove_tree(PROGID);
for e in ARCHIVE_EXTS {
if let Ok(k) = base.open(format!(r"{e}\OpenWithProgids")) {
let _ = k.remove_value(PROGID);
}
}
let root = software_root(classes_root);
let _ = CURRENT_USER.remove_tree(format!(r"{root}\rustyfiles"));
if let Ok(k) = CURRENT_USER.open(format!(r"{root}\RegisteredApplications")) {
let _ = k.remove_value(APP_NAME);
}
}
/// True when the archive app registration points at `exe`.
fn app_registered(exe: &str, classes_root: &str) -> bool {
verb_command(classes_root, &format!(r"{PROGID}\shell\open")).is_some_and(|c| c == format!("\"{exe}\" \"%1\""))
&& CURRENT_USER.open(format!(r"{}\RegisteredApplications", software_root(classes_root))).and_then(|k| k.get_string(APP_NAME)).is_ok()
// registrations before the name fix had DelegateExecute and no Application key
&& CURRENT_USER.open(format!(r"{classes_root}\{PROGID}\Application")).and_then(|k| k.get_string("ApplicationName")).is_ok()
&& CURRENT_USER.open(format!(r"{classes_root}\{PROGID}\shell\open\command")).and_then(|k| k.get_string("DelegateExecute")).is_err()
}
fn verb_command(classes_root: &str, verb: &str) -> Option<String> {
CURRENT_USER.open(format!(r"{classes_root}\{verb}\command")).and_then(|k| k.get_string("")).ok()
}
fn ours(classes_root: &str, verb: &str) -> bool {
verb_command(classes_root, verb).is_some_and(|v| v.to_lowercase().contains("rustyfiles"))
}
/// Our old archive verb overrides go (another app's own ones stay).
fn remove_archive_verbs(classes_root: &str) -> bool {
let Ok(base) = CURRENT_USER.create(classes_root) else { return false };
let mut removed = false;
for v in ARCHIVE_VERBS {
if ours(classes_root, v) {
removed |= base.remove_tree(v).is_ok();
}
}
removed
}
/// Brings an older registration up to date: the archive app registration added, the old archive
/// verb overrides removed. True when it changed something.
pub fn add_archives(exe: &str, classes_root: &str) -> bool {
if !is_enabled(classes_root) {
return false;
}
let removed = remove_archive_verbs(classes_root);
let added = !app_registered(exe, classes_root) && register_app(exe, classes_root).is_ok();
removed || added
}
/// Another program's folder handler (Discord, 2026-11-29: File Pilot's `Directory\shell\open`, left pointing at an exe that was
/// gone, made Windows answer every folder with "Application not found", and it also beat our `Folder\shell\open`, which is the less
/// specific key). `Directory` is what a folder on disk is; its verb wins over `Folder`'s.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OtherHandler {
/// The command it runs (`"E:\apps\fpilot\FPilot.exe" "%1"`).
pub command: String,
/// Its program, when the command names one.
pub program: Option<std::path::PathBuf>,
/// Whether that program is still on the disk.
pub program_exists: bool,
}
/// The program a command line starts: the quoted first part, or up to the first space.
fn program_of(command: &str) -> Option<std::path::PathBuf> {
let c = command.trim();
let p = match c.strip_prefix('"') {
Some(rest) => rest.split('"').next()?,
None => c.split(' ').next()?,
};
(!p.is_empty()).then(|| p.into())
}
/// The verb `Directory\shell` opens with for this user (its default value, else `open`) and that verb's command, when the user's own
/// classes have one that is not ours.
pub fn other_folder_handler(classes_root: &str) -> Option<OtherHandler> {
let verb = CURRENT_USER
.open(format!(r"{classes_root}\Directory\shell"))
.and_then(|k| k.get_string(""))
.ok()
.filter(|v| !v.trim().is_empty())
.unwrap_or_else(|| "open".into());
let command = verb_command(classes_root, &format!(r"Directory\shell\{verb}"))?;
if command.to_lowercase().contains("rustyfiles") {
return None;
}
let program = program_of(&command);
let program_exists = program.as_ref().is_some_and(|p| p.exists());
Some(OtherHandler { command, program, program_exists })
}
/// Where the other handler's values are kept while ours stand in their place (see [`take_over_folders`]).
fn backup_key(classes_root: &str) -> String {
format!(r"{}\rustyfiles\FolderHandlerBackup", software_root(classes_root))
}
/// Puts our command in the place of another program's folder handler (`Directory\shell`), keeping its values to be put back by
/// [`disable`]. This is what the "use rustyfiles anyway" choice does.
pub fn take_over_folders(exe: &str, classes_root: &str) -> anyhow::Result<()> {
let base = CURRENT_USER.create(classes_root)?;
let shell = base.create(r"Directory\shell")?;
let backup = CURRENT_USER.create(backup_key(classes_root))?;
// (only the first time: a second take-over must not back up our own values)
if backup.get_string("Saved").is_err() {
backup.set_string("ShellDefault", shell.get_string("").unwrap_or_default())?;
backup.set_string("OpenCommand", verb_command(classes_root, r"Directory\shell\open").unwrap_or_default())?;
backup.set_string("Saved", "1")?;
}
shell.set_string("", "open")?;
set_command(&base, r"Directory\shell\open\command", &format!("\"{exe}\" \"%1\""))?;
Ok(())
}
/// Puts back what [`take_over_folders`] replaced (nothing when it never ran).
fn give_back_folders(classes_root: &str) {
let Ok(backup) = CURRENT_USER.open(backup_key(classes_root)) else { return };
if backup.get_string("Saved").is_err() {
return;
}
let (default, open) = (backup.get_string("ShellDefault").unwrap_or_default(), backup.get_string("OpenCommand").unwrap_or_default());
if let Ok(base) = CURRENT_USER.create(classes_root) {
if open.is_empty() {
let _ = base.remove_tree(r"Directory\shell\open");
} else if let Ok(k) = base.create(r"Directory\shell\open\command") {
let _ = k.set_string("", &open);
let _ = k.remove_value("DelegateExecute");
}
if let Ok(shell) = base.create(r"Directory\shell") {
let _ = if default.is_empty() { shell.remove_value("") } else { shell.set_string("", &default) };
}
}
let _ = CURRENT_USER.remove_tree(backup_key(classes_root));
}
/// Removes our overrides (the system defaults under HKLM take over again), and gives another program's folder handler back when we
/// had taken its place.
pub fn disable(classes_root: &str) -> anyhow::Result<()> {
let base = CURRENT_USER.create(classes_root)?;
for sub in [r"Folder\shell\open", r"Folder\shell\explore", WIN_E_CLSID] {
// missing keys are fine
let _ = base.remove_tree(sub);
}
give_back_folders(classes_root);
remove_archive_verbs(classes_root);
unregister_app(classes_root);
Ok(())
}
pub fn is_enabled(classes_root: &str) -> bool {
CURRENT_USER
.open(format!(r"{classes_root}\Folder\shell\open\command"))
.and_then(|k| k.get_string(""))
.map(|v| v.to_lowercase().contains("rustyfiles"))
.unwrap_or(false)
}
/// The exe our `Folder\shell\open` command points at (None when not enabled).
pub fn registered_exe(classes_root: &str) -> Option<std::path::PathBuf> {
let v = CURRENT_USER.open(format!(r"{classes_root}\Folder\shell\open\command")).and_then(|k| k.get_string("")).ok()?;
let v = v.trim();
let exe = match v.strip_prefix('"') {
Some(rest) => rest.split('"').next()?,
None => v.split(' ').next()?,
};
exe.to_lowercase().contains("rustyfiles").then(|| exe.into())
}
/// While we are the default, a registered exe that no longer exists (moved, rebuilt elsewhere,
/// its folder cleaned) would leave Windows unable to open any folder: point it at `current`.
/// Returns true when it re-registered.
///
/// Also a registration that lost its `open` verb while its `explore` verb is still ours (issue 97: on a reporter's PC `Folder\shell\open`
/// was an empty key, so "Show in folder" from a browser went to Explorer, or to nothing, while every other folder opened here): it is
/// written again whole.
pub fn heal(current: &str, classes_root: &str) -> bool {
if !std::path::Path::new(current).exists() {
return false;
}
match registered_exe(classes_root) {
Some(old) if !old.exists() => enable(current, classes_root).is_ok(),
Some(_) => false,
None if verb_command(classes_root, r"Folder\shell\explore").is_some_and(|c| c.to_lowercase().contains("rustyfiles")) => {
enable(current, classes_root).is_ok()
}
None => false,
}
}
/// True when the argument should be handed back to Explorer (shell namespaces, non-folders).
pub fn should_forward_to_explorer(arg: &str) -> bool {
let a = arg.trim().trim_matches('"');
!a.is_empty() && (a.starts_with("::") || a.starts_with("shell:") || !std::path::Path::new(a).is_dir())
}
/// Explorer opens folders through the same `Folder\shell\open` verb we take over, so an
/// argument we hand to it can come straight back (a server root like `\\nas`, a folder that
/// looked like a file). Forwards are remembered for a few seconds to break such a loop.
fn forward_log() -> std::path::PathBuf {
std::env::temp_dir().join("rustyfiles-forward.txt")
}
fn now_ms() -> u128 {
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0, |d| d.as_millis())
}
/// True when `arg` was handed to Explorer within the last few seconds.
pub fn forwarded_recently(arg: &str) -> bool {
forwarded_within(&forward_log(), arg, now_ms(), 5_000)
}
/// Remembers that `arg` is being handed to Explorer.
pub fn note_forward(arg: &str) {
note_in(&forward_log(), arg, now_ms());
}
fn forwarded_within(log: &std::path::Path, arg: &str, now: u128, window_ms: u128) -> bool {
let Ok(text) = std::fs::read_to_string(log) else { return false };
text.lines().filter_map(|l| l.split_once('\t')).any(|(t, a)| a == arg && t.parse::<u128>().is_ok_and(|t| now.saturating_sub(t) <= window_ms))
}
fn note_in(log: &std::path::Path, arg: &str, now: u128) {
let old = std::fs::read_to_string(log).unwrap_or_default();
let mut lines: Vec<&str> = old.lines().filter(|l| !l.is_empty()).collect();
let keep = lines.len().saturating_sub(7);
lines.drain(..keep);
let mut out: String = lines.iter().map(|l| format!("{l}\n")).collect();
out.push_str(&format!("{now}\t{arg}\n"));
let _ = std::fs::write(log, out);
}
#[cfg(test)]
mod tests {
/// Issue (Discord, 2026-11-29): another file manager's `Directory\shell\open` is seen, taken over with a backup, and given back.
#[test]
fn another_programs_folder_handler_is_seen_taken_over_and_given_back() {
let root = format!(r"Software\rustyfiles-test-handler-{}\Classes", std::process::id());
let base = CURRENT_USER.create(&root).unwrap();
assert_eq!(other_folder_handler(&root), None, "nothing there");
base.create(r"Directory\shell").unwrap().set_string("", "open").unwrap();
base.create(r"Directory\shell\open\command").unwrap().set_string("", r#""E:\apps\fpilot\FPilot.exe" "%1""#).unwrap();
let h = other_folder_handler(&root).unwrap();
assert_eq!(h.program, Some(std::path::PathBuf::from(r"E:\apps\fpilot\FPilot.exe")));
take_over_folders(r"C:\x\rustyfiles.exe", &root).unwrap();
assert_eq!(other_folder_handler(&root), None, "ours now");
take_over_folders(r"C:\x\rustyfiles.exe", &root).unwrap();
disable(&root).unwrap();
assert_eq!(other_folder_handler(&root).map(|h| h.command), Some(r#""E:\apps\fpilot\FPilot.exe" "%1""#.to_string()), "the first program's own command back");
let _ = CURRENT_USER.remove_tree(root.trim_end_matches(r"\Classes"));
}
use super::*;
#[test]
fn enable_disable_in_scratch_key() {
let root = format!(r"Software\rustyfiles-test-{}\Classes", std::process::id());
enable(r"C:\x\rustyfiles.exe", &root).unwrap();
assert!(is_enabled(&root));
let k = CURRENT_USER.open(format!(r"{root}\{WIN_E_CLSID}\shell\opennewwindow\command")).unwrap();
assert_eq!(k.get_string("").unwrap(), "\"C:\\x\\rustyfiles.exe\"");
// Windows' own archive handlers stay Explorer's
assert!(!ARCHIVE_VERBS.iter().any(|v| ours(&root, v)));
assert!(app_registered(r"C:\x\rustyfiles.exe", &root));
let fa = CURRENT_USER.open(format!(r"Software\rustyfiles-test-{}\rustyfiles\Capabilities\FileAssociations", std::process::id())).unwrap();
assert_eq!(fa.get_string(".zip").unwrap(), PROGID);
// an older registration: its archive verb overrides go
let base = CURRENT_USER.create(&root).unwrap();
set_command(&base, &format!(r"{}\command", ARCHIVE_VERBS[1]), r#""C:\x\rustyfiles.exe" "%1""#).unwrap();
assert!(add_archives(r"C:\x\rustyfiles.exe", &root));
assert!(!ours(&root, ARCHIVE_VERBS[1]));
assert!(!add_archives(r"C:\x\rustyfiles.exe", &root)); // nothing left to do
// the open verb lost while the explore verb is ours: written again whole (issue 97)
let _ = base.remove_tree(r"Folder\shell\open\command");
assert!(!is_enabled(&root));
assert!(heal(&std::env::current_exe().unwrap().display().to_string(), &root));
assert!(is_enabled(&root));
disable(&root).unwrap();
assert!(!is_enabled(&root));
assert!(!ARCHIVE_VERBS.iter().any(|v| ours(&root, v)));
assert!(!app_registered(r"C:\x\rustyfiles.exe", &root));
assert!(CURRENT_USER.open(format!(r"{root}\{PROGID}")).is_err());
// another app's archive verb survives
set_command(&base, &format!(r"{}\command", ARCHIVE_VERBS[0]), r"C:\7z\7zFM.exe %1").unwrap();
disable(&root).unwrap();
assert!(CURRENT_USER.open(format!(r"{root}\{}\command", ARCHIVE_VERBS[0])).is_ok());
let _ = CURRENT_USER.remove_tree(format!(r"Software\rustyfiles-test-{}", std::process::id()));
assert!(should_forward_to_explorer("::{26EE0668-A00A-44D7-9371-BEB064C98683}"));
assert!(!should_forward_to_explorer(r"C:\Windows"));
}
#[test]
fn heals_a_missing_exe() {
let root = format!(r"Software\rustyfiles-heal-{}\Classes", std::process::id());
let me = std::env::current_exe().unwrap().display().to_string();
enable(r"C:\yok\rustyfiles.exe", &root).unwrap();
assert_eq!(registered_exe(&root), Some(std::path::PathBuf::from(r"C:\yok\rustyfiles.exe")));
// current_exe is a test binary: name it like the app for the "is it ours" check
let fake = std::env::temp_dir().join(format!("rustyfiles-heal-{}.exe", std::process::id()));
std::fs::copy(&me, &fake).unwrap();
assert!(heal(&fake.display().to_string(), &root));
assert_eq!(registered_exe(&root), Some(fake.clone()));
assert!(!heal(&fake.display().to_string(), &root)); // already fine
let _ = CURRENT_USER.remove_tree(format!(r"Software\rustyfiles-heal-{}", std::process::id()));
let _ = std::fs::remove_file(&fake);
}
#[test]
fn forward_loop_guard() {
let log = std::env::temp_dir().join(format!("rf-fwd-{}.txt", std::process::id()));
let _ = std::fs::remove_file(&log);
assert!(!forwarded_within(&log, r"\\nas", 1_000, 5_000));
note_in(&log, r"\\nas", 1_000);
assert!(forwarded_within(&log, r"\\nas", 4_000, 5_000));
assert!(!forwarded_within(&log, r"\\nas", 9_000, 5_000)); // long ago: forward again
assert!(!forwarded_within(&log, r"\\other", 2_000, 5_000));
for i in 0..20 {
note_in(&log, &format!("x{i}"), 2_000 + i);
}
assert_eq!(std::fs::read_to_string(&log).unwrap().lines().count(), 8); // bounded
let _ = std::fs::remove_file(&log);
}
}