Skip to content

A cleaner for every drive: one engine for rs-du and WinRust Disk - #158

Open
Tkyoxx wants to merge 21 commits into
Lemxy:mainfrom
Tkyoxx:pr/13-cleaner
Open

Tkyoxx wants to merge 21 commits into
Lemxy:mainfrom
Tkyoxx:pr/13-cleaner

Conversation

@Tkyoxx

@Tkyoxx Tkyoxx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Stacked on #144, #148, #151, #145, #152, #149, #157. Until those are merged this branch also carries their commits, so the diff below is bigger than this PR. Its own change is 5 commits; I will rebase it as soon as #157 is in.

What

  • rs-du's cleaner moves to winrust-common (clean.rs) so a window can use it too: rs-du keeps its console list, WinRust Disk gets a cleaner page (the button at the right of its title bar, or wiztree --clean). Green and yellow come ticked, red waits for the user; a heading ticks its group, a right click shows the item in Explorer; red items gone for good (recycle bin) ask first; files go to the 30-day quarantine and one button brings them all back.
  • Every fixed NTFS drive, one at a time (a drive's MFT is a few hundred MB): project folders, Steam shader caches, recycle bins on all of them.
  • Exact copies of big files (64 MB and up), compared byte by byte after a size match from the MFT; the oldest stays. Cloud placeholders are not read.
  • Files of programs and games are left alone: outside the user's own folders, a file with an .exe or .dll (or a Binaries / Engine folder) beside or above it belongs to that program; a game's Trial.exe is byte for byte its main exe, and that was the first copy it found on a real PC.
  • New places: Opera, Opera GX, Vivaldi, thumbnails, Windows setup logs, MEMORY.DMP and LiveKernelReports, upgrade leftovers ($WINDOWS.~BT), Gradle, Yarn and Go caches. Nothing touched in the last two hours is wiped.
  • One quarantine list per drive in Program Files\WinRust (admin-only, shared by both tools); the old one next to rs-du.exe moves there by itself.
  • rust-search: a "Free up disk space" row on top when the query sounds like it (limpiar, free up, junk, очистить, 清理...) and WinRust Disk is installed. topbar's Disk Cleaner item opens the page (rs-du's console when WinRust Disk is missing). Without a drive letter, rs-du's --clean / --restore / --purge cover every drive.
  • The last commit is the fix of wiztree: ask for admin once, through Explorer when UAC cannot raise it #146 (WinRust Disk asks for admin once): the bar and the search start WinRust Disk with the "basic user" token, so without it this PR's entry points hit that loop. It drops out when wiztree: ask for admin once, through Explorer when UAC cannot raise it #146 is merged.

Screenshot (the cleaner page after scanning three drives, Windows 10 21H2, Spanish UI; the red group is folded)

The cleaner page of WinRust Disk

Test

  • cargo test -p winrust-common -p rs-du -p wiztree, cargo test in rust-search: rules give absolute paths, wipe keeps fresh files, copies found by bytes not size, files next to programs kept, quarantine list round trip.
  • On a real PC (Windows 10 21H2, three drives): the page listed ~4.9 GB, one clean ran (temp, browser and app caches, shader caches, setup logs, two recycle bins); the game copy above is what the program-file rule now skips.

- winrust-common: Lang::Es and Lang::ALL; t!/tf! take an optional es: arm
  after zh: (or after pt: in calls without zh:), and any language left out
  shows the English text, so nothing is ever blank or a raw key.
- No lang.txt: the Windows UI language when WinRust has it, else English.
- lang() re-reads lang.txt at most once a second and set_lang broadcasts
  style::msg(), so open windows switch without a restart: topbar now listens
  for the broadcast, rust-settings rebuilds its pages and rust-explorer its
  column headers and navigation pane when the language moved. The "restart
  the programs" notes say the switch is immediate now.
- The installer list, rust-settings and the bar's language page take their
  languages from Lang::ALL (Spanish included); --lang accepts es.
- Spanish for every t!/tf! call (1,246), the installer table, the Run box
  commands and the Start button menu, plus the few strings still English-only
  in rust-explorer.
- rs-launcher's counts gave "2 registry entrys" and Portuguese had no plural
  at all: every language now spells out its singular and plural.
…a switch

rust-explorer used to be the file manager and the Explorer replacement in one
step, so it could not be installed without topbar. Now:

- Its row installs the file manager only: folder/drive verbs and the Start
  menu shortcut. Explorer stays the shell with its own desktop and taskbar; no
  service tweaks, no rs-overlay task, no AutoRestartShell change.
- "Replace Explorer" in topbar's settings panel is the shell part. Turning it
  on ticks topbar and rust-explorer; unticking either turns it off. Turning it
  off later hands the session back to Explorer and keeps the file manager.
- An installed rust-explorer whose switch moved shows "Will be changed" and is
  installed again; giving the shell back runs before anything else in the
  same run, so topbar is never removed while it is the only bar.
- Express never moves the shell; a plain update keeps the current mode.
- Uninstalling topbar while rust-explorer is the shell gives the shell back to
  Explorer first (command line included).
- Command line: install/update rust-explorer [--shell|--no-shell]; --shell
  pulls topbar in when it is missing.
- The upstream rs-overlay start (schtasks /run, shortcut as the fallback) is
  kept as is, it just lives in the shell part now.
- Win+S / Win+Q open the card through a low-level keyboard hook on its own
  thread, set again every 30 s like topbar's. Win+Shift+S stays the snip; a
  dummy key keeps Start from opening on release, and the key still goes down
  the hook chain so topbar's Start knows Win was not pressed alone. On Windows
  10 that was the missing piece: SearchHost.exe (the window that is blocked)
  is Windows 11's, so Win+S kept opening Windows Search there.
- Windows 10's own search window (SearchApp.exe / SearchUI.exe) is left
  alone on purpose. Blocked, it made Explorer wait out DCOM's activation
  timeout every time it asked for it (System log 10010, TWinUI 5961), which
  froze the desktop's right click for seconds. With WSearch off it has
  nothing to search, and Win+S no longer reaches it.
- Alt+Space and Win+S can each be switched off from a gear on rust-search's
  row (%ProgramData%\WinRust\search-keys.txt, applied live through the style
  broadcast). At least one stays on.
- A taken Alt+Space is no longer fatal (said once, off the UI thread); a
  named mutex keeps one launcher per session instead.
- The installer's settings panels are generic now: one gear per plugin with
  options, the panel sized to its switches. topbar's keeps OneDrive and
  "Replace Explorer".
"Closing the window minimizes to tray" was on by default and easy to miss, so
the task manager kept running after people closed it. Now closing quits, like
the stock one, until the first close asks once: Yes = tray, No = quit,
Cancel = keep the window. Old settings files get the question once too
(tray_asked). The Settings card and the menu switch still flip it any time.
Without align-left.txt the buttons were always centered, so on Windows 10 the
bar looked like a different system from the first second. Now the default
follows the build: left on Windows 10, centered on Windows 11. A choice made in
the bar menu (the file says 1 or 0) still wins either way.

common: windows_build() / win11() read CurrentBuildNumber once, natively, and
reg::get_str reads a REG_SZ without starting reg.exe.
Until the user moved an icon, every tray icon sat behind the arrow, including
the ones people had told Windows to keep in sight. Now:

- Windows 11: its per-icon "show on taskbar" choices (NotifyIconSettings,
  IsPromoted) seed the bar's list until the user makes their own.
- Windows 10 has no per-icon list that can be read, only "Always show all
  icons" (EnableAutoTray 0). That maps to a new switch, "Every tray icon on the
  bar" (style::tray_all, tray-all.txt), also in the bar menu.

common: reg::subkeys enumerates a key natively; style gets a small Flag
helper for 0/1 files with a computed default.
A see-through bar showed the windows under it sharp, which makes the clock and
the buttons hard to read. "Blur behind the bar" (Colors and transparency page,
style::bar_blur, off by default) asks Windows for the blur its own taskbar
uses, through SetWindowCompositionAttribute (looked up at run time; a Windows
without it just gets no blur).

Fading the whole layered window would fade the text too, so with the blur on
the bar is painted into a 32-bit DIB and only the pixels the background left
alone get the opacity (premultiplied); text, icons and pills stay solid. The
background copy it compares against is kept with bg_layer's key, so an
animation frame copies nothing. Switching the blur on at 100 % opacity drops
it to 85 %, since nothing shows through a solid bar.

Checked on Windows 10 19044; the same API draws it on Windows 11.
…uest

- topbar's settings panel gets the look switches, all live through the style
  broadcast: centered buttons, every tray icon on the bar, see-through bar
  (85 %), blur behind it. OneDrive and "Replace Explorer" stay where they were.
- The PowerShell profile block (cat->bat, grep->rg, ll, zoxide) was written
  into the user's profile with every topbar, unasked. It is a switch now, off
  for a fresh install; installs from before keep it. Flipping it marks topbar
  "Will be changed", and installing it again writes or removes the block.
  Command line: --ps-aliases / --no-ps-aliases. The applied state lives in
  HKLM\SOFTWARE\plugin-launcher\topbar.
- A fresh install shows the OneDrive icon (topbar.cfg is written with it on);
  installs from before keep it hidden, as the bar's default was.
- reshell is not optional: besides the desktop hotkeys it is the watchdog that
  brings the taskbar back if the bar dies, and the Win+E/D/I handler.
With no tray icon at all (a PC without tray apps, or all of them hidden) the bar broadcast TaskbarCreated to every top-level window in the session every 4 s, forever. Now every 4 s for the first minute after start, which covers apps that start late, then once a minute.
The installer's "Hide the OneDrive icon" only reached the bar the next time
OneDrive registered its icon, usually at the next sign-in. The installer now
sends the style broadcast after writing topbar.cfg, and the bar drops the icon
or asks for it again (TaskbarCreated) when the value really changed; theme and
language broadcasts leave the tray alone.
The WinRust windows paint everything themselves except the caption, so on
Windows 10 each one wore the old system title bar on top of a modern page.

caption.rs takes the standard caption away (WM_NCCALCSIZE: the whole window
is client area) and lets the window paint flat minimize / maximize / close
buttons in its own colours, with Windows 11's hover shades and the red close.
The hit test answers with the real HT* codes, so dragging, double-click to
maximize, Aero Snap and Shake, the window menu (right click, Alt+Space),
resizing from every edge and Windows 11's snap layouts keep working. Clicks
on the buttons are handled here, not by DefWindowProc, which would paint the
classic buttons over ours while tracking them. A maximized window keeps its
frame off-screen out of the client area; one pixel of DWM frame keeps the
shadow on Windows 10. A child window lying over the caption can paint the
buttons and pass the free parts through with HTTRANSPARENT.

The installer's dark header is the title bar now: it drags the window, the
language list moved left to clear the buttons.
The buttons sit at the top right and the page title's band drags the window, as in Windows 11 Settings; the sidebar's page list stays clickable where it reaches into that band. The caption colour attributes are gone with the caption.
Like a browser: the tabs sit in the caption, its free space drags the window and the buttons sit at its right end. The chrome child answers HTTRANSPARENT there, so the top-level window does the caption's work, and it paints the buttons itself. Tabs leave room for them. The desktop window (--desktop) is left alone.
WinRust Disk's path line is the caption. The photo viewer gets a thin strip with the file's name, position and size over the picture area; zoom and panning count from under it.
The band drags the window except over the menu button and the page buttons, which move left to clear the caption buttons. The search box is a window of its own and keeps working as before.
- README.es.md, the full README in Spanish, linked from every language.
- Every README, the same edits in each language: rust-explorer installs
  alone and "Replace Explorer" is the switch that needs topbar; rust-search
  opens with Alt+Space or Win+S and blocks the Windows 10 search window too;
  topbar's PowerShell block is opt-in and its gear has the look; the language
  list has Spanish and switches open windows at once; the command line's
  --shell / --no-shell / --ps-aliases / --no-ps-aliases; the language macro
  with es:.
- ROADMAP (en, ru): Win+S is done, the profile block is on request.
- The repository notes list README.es.md with the READMEs edited together.
rs-du's cleaner moves to winrust-common so a window can use it too, and
gets better at its job:
- every fixed NTFS drive, read one at a time (a drive's MFT is a few
  hundred MB): project folders, Steam shader caches and recycle bins on
  all of them, not only C:
- exact copies of big files, compared byte by byte; the oldest stays
- big forgotten files outside C:\Users too
- files of programs and games are left alone: outside the user's own
  folders, anything with an .exe or .dll beside or above it (a game's
  Trial.exe is byte for byte its main exe)
- Opera, Opera GX, Vivaldi, thumbnails, setup logs, memory dumps,
  Windows upgrade leftovers, Gradle, Yarn and Go caches
- nothing touched in the last two hours is wiped (a running installer)
- one quarantine list per drive in Program Files\WinRust, shared by
  both tools; the old one next to rs-du.exe moves there by itself
Without a drive letter rs-du --clean, --restore and --purge cover every
drive.
The button at the right of the title bar switches between the disk map
and a list of what can go, grouped by risk: green and yellow come
ticked, red waits for the user. A click ticks, a heading ticks its
group, a right click shows the item in Explorer. Red items that would
be gone for good (the recycle bin) ask first; files go to the 30-day
quarantine, and one button brings them all back. wiztree --clean opens
on that page.
Typing what sounds like a wish for disk space (limpiar, free up, junk,
очистить, 清理...) puts a "Free up disk space" row on top, when WinRust
Disk is installed; Enter opens its cleaner. The row has no file menu.
A window for every drive when WinRust Disk is installed; otherwise
rs-du's list in a console, now for every drive too.
A copy that was not admin asked for it and quit, with no limit. Started
from the bar, the search or a file manager they opened (WinRust gives
those the runas /trustlevel "basic user" token), UAC cannot raise the
token: on a PC set to elevate without prompting each request quietly
started another copy without rights, about one a second, forever (the
busy cursor never stopped).
- That token goes through Explorer instead (the shell's own token can be
  raised); the arguments wait in a note Explorer's copy picks up.
- One request at most: a copy started for it and still not admin says
  so and stops.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant