Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

## Getting started

1. Select **Managed folders → Add folder…**. Choose a local fixed NTFS folder, such as `C:\zipxp-test`. Adding a folder starts read-only analysis. A WSL/UNC folder is not supported.
2. Inspect the overview and storage insights. Folder rows show their policy, known logical/allocation totals, candidate bytes, status, scan time, and native directory-default count. Double-click a folder in Insights to drill down, or choose **Largest files**.
3. Select **Folder settings** and turn on automatic compression. Subfolder inclusion and battery behavior are on the first screen; file exclusions, size/benefit thresholds, quiet period, cooldown, schedule, and free-space reserve are under **Advanced options**.
4. Eligible existing files are queued. New, copied-in, replaced, and changed files are discovered through notifications and periodic scans. The recommended quiet period is 60 seconds; reconciliation runs every two minutes. Busy files retry with backoff. Poor-benefit files stay excluded until their content fingerprint changes or a failed job is explicitly retried.
5. Close the window to keep the tray worker running. Reopen it from the tray. **Start when I sign in** explicitly registers this user's current launch command. **Pause all** / **Pause folder** stops new operations after the current one. **Quit ZipXP** finishes the file in progress, then ends the worker and leaves pending work persisted.
6. Use Activity to search/filter outcomes, copy diagnostics, and retry selected failures. Retry does not re-enable disabled automatic policies.

Adding a folder for analysis does not compress it. **Compress now** is an explicit one-off job; it does not turn on future automation. Each recursive action shows a scope preview first. Ordinary automatic files have no per-file confirmation dialog.
1. Select **Add folder** and choose a folder on a local NTFS drive, such as `C:\zipxp-test`. ZipXP selects it in **Managed folders** and scans it without changing files.
2. Check the folder’s estimated savings. **Compress once** previews a one-time job. **Turn on auto-compression** asks you to confirm before ZipXP starts handling eligible existing, new, copied and changed files in the background.
3. In **Overview**, **Estimated savings** comes from the latest scans. **Space saved by ZipXP** counts the net disk space change ZipXP measured from its own compression and restores. **Folder size on disk** shows how much space the measured files currently use.
4. Use **Folder settings** to choose subfolders, exclusions and when ZipXP can work. Use **Browse files** to inspect a folder and **Activity** to track progress or retry failed work.
5. Close the window to keep ZipXP running in the tray. Enable **Start when I sign in** if you want ZipXP to start with Windows. **Pause all folders** or **More actions → Pause folder** pauses work after the current file. **Quit ZipXP** stops background work and keeps the queue for next time.

### Decompression and stopping management

- **Restore original size…** (Overview for all folders, Managed folders toolbar per folder, or Storage insights for selected files) uncompresses files so they take their full space again; no files are deleted. It first disables automatic compression for that managed root and cancels pending compression. Re-enabling automation while decompression is pending is rejected.
- **Restore files** in Managed folders or **Restore selected** in Storage insights uncompresses files so they take their full space again; no files are deleted. It first disables automatic compression for that managed root and cancels pending compression. Re-enabling automation while decompression is pending is rejected.
- Decompression does not clear existing NTFS directory defaults. The preview reports those defaults, incomplete coverage, omitted entries, and the largest sequential operation's required headroom.
- **Turn off Windows' own folder compression** (More menu) is a separate recursive directory-only job within the current policy scope. Existing files stay compressed. Excluded/unreadable/unsupported directories may retain defaults; inspect the next scan.
- **Stop managing this folder** (More menu) removes the root, observations, and future jobs. Existing files and native defaults remain unchanged. Historical job measurements are retained.
Expand Down
95 changes: 73 additions & 22 deletions src/ZipXP.App/Web/DesktopBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@ private ManagedFolder Root(JsonElement args) => Engine.Store.Roots().FirstOrDefa
private static string Text(JsonElement args, string key) => args.TryGetProperty(key, out var value) && value.ValueKind == JsonValueKind.String
? value.GetString()! : throw new ArgumentException($"Missing {key}.");
private static bool Flag(JsonElement args, string key) => args.GetProperty(key).GetBoolean();
private bool Confirm(string text, string title) => !App.Instance.Exiting && MessageBox.Show(owner, text, title, MessageBoxButton.YesNo, title.Contains("Restore", StringComparison.Ordinal) || title.Contains("Stop managing", StringComparison.Ordinal) ? MessageBoxImage.Warning : MessageBoxImage.Information) == MessageBoxResult.Yes;
private bool Confirm(string text, string title) => !App.Instance.Exiting &&
MessageBox.Show(owner, text, title, MessageBoxButton.YesNo,
title.Contains("Restore", StringComparison.Ordinal) || title.Contains("Stop managing", StringComparison.Ordinal) ? MessageBoxImage.Warning : MessageBoxImage.Information,
MessageBoxResult.No) == MessageBoxResult.Yes;

private string PendingWorkNotice(ManagedFolder root) =>
Engine.Store.ActiveJobs().Any(j => j.RootId == root.Id)
? "\n\nThis will cancel the work still queued for this folder." : "";

private async Task<string> SavePolicyAsync(ManagedFolder root, FolderPolicy policy)
{
await Engine.SavePolicyAsync(root, policy);
if (!policy.Enabled) return "Settings saved. Auto-compression is off. Compressed files stay compressed.";
return "Settings saved. Auto-compression is on for existing, new and changed files." +
(Engine.Paused ? " Choose Resume all folders to continue." :
policy.Paused ? " Choose Resume folder from More actions to continue." : "");
}

public async Task<object?> ExecuteAsync(string command, JsonElement args)
{
Expand All @@ -32,25 +48,40 @@ private static string Text(JsonElement args, string key) => args.TryGetProperty(
case "pause": await Engine.SetPausedAsync(Flag(args, "paused")); return Engine.Paused ? "Paused. The current file will finish first." : "Background work resumed.";
case "pauseFolder": await Engine.SetFolderPausedAsync(Root(args).Id, Flag(args, "paused")); return "Folder pause setting updated.";
case "startup": StartupRegistration.Enabled = Flag(args, "enabled"); return "Sign-in preference saved.";
case "setAutoCompression":
var folder = Root(args);
var enabled = Flag(args, "enabled");
if (enabled == folder.Policy.Enabled) return "No changes made.";
var title = enabled ? "Turn on auto-compression" : "Turn off auto-compression";
var detail = enabled
? "ZipXP will compress eligible existing, new and changed files while it runs. Files will open as usual."
: "ZipXP will stop compressing files automatically here. Compressed files will stay compressed.";
if (!Confirm($"{title} for {folder.Name}?\n\n{detail}" + PendingWorkNotice(folder), title)) return "No changes made.";
return await SavePolicyAsync(folder, folder.Policy with { Enabled = enabled });
case "savePolicy":
var policy = args.GetProperty("policy").Deserialize<FolderPolicy>(Json) ?? throw new ArgumentException("Missing folder settings.");
// Pause is a separate action and cannot be accidentally overwritten by an open settings form.
var submitted = args.GetProperty("policy").Deserialize<FolderPolicy>(Json) ?? throw new ArgumentException("Missing folder settings.");
var root = Root(args);
await Engine.SavePolicyAsync(root, policy with { Paused = root.Policy.Paused });
return "Settings saved. Files already compressed stay compressed until you restore them.";
// Pause is a separate action and cannot be accidentally overwritten by an open settings form.
var policy = submitted with { Paused = root.Policy.Paused };
if (policy == root.Policy) return "No changes made.";
var pendingNotice = PendingWorkNotice(root);
if (pendingNotice.Length > 0 && !Confirm("Save changes to this folder’s settings?" + pendingNotice, "Save folder settings"))
return "No changes made.";
return await SavePolicyAsync(root, policy);
case "queue": return await QueueAsync(args);
case "restoreSelected":
var selectedRoot = Root(args);
var paths = args.GetProperty("paths").Deserialize<string[]>(Json) ?? [];
var wanted = paths.ToHashSet(StringComparer.OrdinalIgnoreCase);
var selected = Engine.Store.Observations(selectedRoot.Id).Where(o => wanted.Contains(o.Path) && o.File is { Directory: false, Compressed: true }).ToArray();
if (selected.Length == 0) return "No compressed files selected.";
var headroom = checked(selectedRoot.Policy.ReserveBytes + selected.Max(o => o.File!.Logical));
if (!Confirm($"Restore the original size of {selected.Length} selected files?\n\nNeeds at least {Display.Bytes(headroom)} free on the drive. Automatic compression for this folder will be turned off. No files are deleted.", "Restore selected files")) return "No changes made.";
var selected = Engine.Store.Observations(selectedRoot.Id).Where(o => wanted.Contains(o.Path)).ToArray();
var restorable = Engine.RestorableFiles(selectedRoot, selected).ToArray();
if (restorable.Length == 0) return "ZipXP found no selected files it can restore.";
var headroom = checked(selectedRoot.Policy.ReserveBytes + restorable.Max(f => f.Logical));
if (!Confirm($"Restore the original size of {Plain.Count(restorable.Length, "selected file")}?\n\nNeeds at least {Display.Bytes(headroom)} free on the drive. Automatic compression for this folder will be turned off. No files are deleted.", "Restore selected files")) return "No changes made.";
return Queued(await Engine.QueueSelectedAsync(selectedRoot.Id, selected));
case "remove":
var removing = Root(args);
if (!Confirm($"Stop managing {removing.Path}?\n\nFiles stay exactly as they are, including any existing compression. To uncompress them first, cancel and choose Restore original size.", "Stop managing folder")) return "No changes made.";
if (!Confirm($"Stop managing {removing.Path}?\n\nFiles stay exactly as they are, including any existing compression. To uncompress them first, cancel and choose Restore files.", "Stop managing folder")) return "No changes made.";
await Engine.RemoveAsync(removing.Id); return "Folder removed from ZipXP. Its files stay as they are.";
case "retry":
var retry = Engine.Store.Jobs().FirstOrDefault(j => j.Id == Text(args, "jobId")) ?? throw new ArgumentException("Activity item no longer exists.");
Expand All @@ -72,9 +103,11 @@ private object Snapshot()
{
var roots = Engine.Store.Roots();
var scans = Engine.Store.Scans();
var entries = roots.SelectMany(r => Engine.Store.Observations(r.Id)).ToArray();
var files = entries.Where(o => o.File is { Directory: false }).Select(o => o.File!).DistinctBy(f => f.Identity).ToArray();
var measured = files.Where(f => f.Allocated != null).ToArray();
var observations = roots.ToDictionary(r => r.Id, r => Engine.Store.Observations(r.Id));
var entries = observations.Values.SelectMany(items => items).ToArray();
var measured = entries.Where(o => o.File is { Directory: false, Allocated: not null })
.Select(o => o.File!).DistinctBy(f => f.Identity);
var savings = Engine.Store.MeasuredSince(DateTime.MinValue);
var volumes = new List<object>();
foreach (var name in roots.Select(r => Path.GetPathRoot(r.Path)!).Distinct(StringComparer.OrdinalIgnoreCase))
{
Expand All @@ -83,10 +116,19 @@ private object Snapshot()
}
return new
{
Folders = roots.Select(r => new { r.Id, r.Name, r.Path, r.Policy, Scan = scans.FirstOrDefault(s => s.RootId == r.Id), Status = Plain.Message(Engine.FolderStatus(r.Id)) }),
Folders = roots.Select(r => new
{
r.Id, r.Name, r.Path, r.Policy,
Scan = scans.FirstOrDefault(s => s.RootId == r.Id),
Status = Plain.Message(Engine.FolderStatus(r.Id)),
CanRestore = Engine.RestorableFiles(r, observations[r.Id]).Any()
}),
Jobs = Engine.Store.Jobs().Select(j => new { j.Id, j.RootId, j.Path, FileName = Path.GetFileName(j.Path), j.State, StateText = Plain.JobState(j.State).Text, Action = Plain.Action(j.Operation), Message = Plain.Message(j.Message), j.Delta, Utc = j.FinishedUtc ?? j.CreatedUtc, j.Pending }),
Engine.Paused, Startup = StartupRegistration.Enabled, Status = Plain.Message(Engine.Status), Engine.CurrentFile,
Original = measured.Sum(f => f.Logical), Allocated = measured.Sum(f => f.Allocated ?? 0), Unknown = entries.Count(e => e.File == null || (e.File.Directory == false && e.File.Allocated == null)), Volumes = volumes
Savings = new { savings.Delta, savings.Measured },
Allocated = measured.Sum(f => f.Allocated!.Value),
Unknown = entries.Count(e => e.File == null || (e.File.Directory == false && e.File.Allocated == null)),
Volumes = volumes
};
}

Expand Down Expand Up @@ -129,7 +171,7 @@ private object Insights(JsonElement args)
return new { Path = path, Parent = string.Equals(path, root.Path, StringComparison.OrdinalIgnoreCase) ? null : Path.GetDirectoryName(path), page.Rows, page.TotalRows };
}

private string Queued(int count) => $"{count} items queued." + (Engine.Paused ? " Choose Resume all to start." : " See Activity for progress.");
private string Queued(int count) => $"{count} items queued." + (Engine.Paused ? " Choose Resume all folders to start." : " See Activity for progress.");

private async Task<string> QueueAsync(JsonElement args)
{
Expand All @@ -140,19 +182,28 @@ private async Task<string> QueueAsync(JsonElement args)
: Engine.Store.Roots().Where(r => operation != "Compress" || !r.Policy.Paused).ToArray();
if (roots.Length == 0) return "Add a folder first.";
var previews = new List<(ManagedFolder Root, JobPreview Preview)>();
foreach (var root in roots) previews.Add((root, await Engine.PreviewAsync(root, operation)));
// A restore with zero eligible files still disables automatic compression, matching the native UI.
foreach (var root in roots)
{
var preview = await Engine.PreviewAsync(root, operation);
if (preview.Files > 0) previews.Add((root, preview));
}
if (previews.Count == 0) return operation switch
{
"Decompress" => "ZipXP found no compressed files it can restore.",
"ClearDefault" => "ZipXP found no folders with Windows compression to turn off.",
_ => "ZipXP found no files it can compress right now."
};
var count = previews.Sum(p => p.Preview.Files);
var headroom = previews.Max(p => p.Preview.RequiredHeadroom);
var explanation = operation switch
{
"Decompress" => "Files will take their original space again. Automatic compression will be turned off for these folders. No files are deleted. Windows folder compression, if enabled, can still compress new files independently.",
"ClearDefault" => "Windows will stop compressing new files in these folders by itself. Existing compressed files stay compressed.",
_ => "Files will be compressed once in the background. Automatic compression will not be enabled. You can restore their original size later."
_ => "ZipXP will compress these files once. Your auto-compression settings stay as they are. Use Restore files to undo."
};
var title = operation switch { "Decompress" => "Restore original size", "ClearDefault" => "Turn off Windows compression", _ => "Compress preview" };
var coverage = previews.All(p => p.Preview.Coverage == "Complete primary-stream scan") ? "Everything in these folders was checked." : "Partial scan: items that couldn't be read are left out.";
var scope = roots.Length == 1 ? roots[0].Path : $"{roots.Length} managed folders";
var title = operation switch { "Decompress" => "Restore original size", "ClearDefault" => "Turn off Windows compression", _ => "Compress once" };
var coverage = previews.All(p => p.Preview.Coverage == "Complete primary-stream scan") ? "The scan covered the files within your folder settings." : "Some items were skipped or could not be checked.";
var scope = previews.Count == 1 ? previews[0].Root.Path : $"{previews.Count} managed folders";
if (!Confirm($"{scope}\n\n{count} eligible items · {Display.Bytes(previews.Sum(p => p.Preview.LogicalBytes))} in total\nNeeds at least {Display.Bytes(headroom)} free on each affected drive while it works.\n{coverage}\n\n{explanation}\n\nGo ahead?", title)) return "No changes made.";
var queued = 0;
foreach (var (root, _) in previews) queued += await Engine.QueueScopeAsync(root.Id, operation);
Expand Down
15 changes: 10 additions & 5 deletions src/ZipXP.Core/Services/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,17 @@ public Task<JobPreview> PreviewAsync(ManagedFolder root, string operation) => Ex
scan.Summary.NativeDefaults, scan.Summary.Coverage);
});

public static IEnumerable<FileRecord> RestorableFiles(ManagedFolder root, IEnumerable<Observation> entries) =>
Eligible(entries, root, "Decompress");

private static IEnumerable<FileRecord> Eligible(IEnumerable<Observation> entries, ManagedFolder root, string operation) =>
entries.Where(o => o.File != null && !Rules.Excluded(Path.GetRelativePath(root.Path, o.Path), root.Policy))
.Select(o => o.File!).Where(f => operation == "ClearDefault"
? f.Directory && f.Compressed && Rules.AttributeReason(f.Attributes) == null
: !f.Directory && f.Compressed == (operation == "Decompress") &&
Rules.Eligibility(f, root.Policy, operation == "Compress", DateTime.UtcNow) == null);
entries.Where(o => o.File is { } f &&
(operation == "ClearDefault"
? f.Directory && f.Compressed && Rules.AttributeReason(f.Attributes) == null
: !f.Directory && f.Compressed == (operation == "Decompress") &&
Rules.Eligibility(f, root.Policy, operation == "Compress", DateTime.UtcNow) == null) &&
!Rules.Excluded(Path.GetRelativePath(root.Path, o.Path), root.Policy))
.Select(o => o.File!);

private static string DecisionKey(FileRecord file, string operation) => operation == "Compress" ? file.Fingerprint : file.Fingerprint + ":" + operation;

Expand Down
2 changes: 1 addition & 1 deletion src/ZipXP.UI/e2e/desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function openApp(page: Page, scenario: Scenario = {}) {
snapshot.folders = [];
snapshot.jobs = [];
snapshot.volumes = [];
snapshot.original = 0;
snapshot.savings = { delta: 0, measured: 0 };
snapshot.allocated = 0;
}
if (scenario.folderCount) {
Expand Down
Loading
Loading