diff --git a/docs/architecture/mapped-organize.md b/docs/architecture/mapped-organize.md index 9f6748982..87e546191 100644 --- a/docs/architecture/mapped-organize.md +++ b/docs/architecture/mapped-organize.md @@ -41,23 +41,51 @@ Ordinary organization never targets mapped widgets: they are filtered out in `DesktopOrganizationRuleResolver.Resolve`, `CreateExecutionPlan` and `GetDestinationOptions`. -## Native desktop icons (user accepted hiding) - -Choice: hide the desktop `SysListView32` (child of the desktop -`SHELLDLL_DefView`) with `ShowWindow(SW_HIDE)` -(`Services/DesktopIconVisibilityService.cs`), **not** Explorer's persisted -"Show desktop icons" setting. - -* Not persisted by Explorer → no failure mode can leave the user permanently - without icons (Explorer restart / sign-out always shows them again). -* Hidden while ≥1 mapped widget exists; shown when the last one is dissolved, - on DeskBox shutdown (`ShutdownStep "mapped-organize"`), and best-effort in - `AppDomain.ProcessExit`. -* Crash safety: `desktopIconsHiddenByDeskBox` is written *before* hiding. On - the next start `MappedOrganizeService.Initialize` either re-applies (mapped - widgets exist) or restores (none left). It runs even if widget restore fails. -* Explorer restarts recreate a visible list view; a 4 s dispatcher timer - re-hides it while mapped widgets exist. +## Global 「整理方式」 (organize mode) + +* Settings → 桌面整理 → 「整理方式」: 「移动到格子」 (default, upstream) / + 「只映射,不移动文件」. Stored in `/fork-organize.json` + (`{"organizeMode":"move|mapOnly"}`, `Services/ForkOrganizeModeSettings.cs`), + written by the settings process, read by the main process at use time and + watched by `MappedOrganizeService` (FileSystemWatcher). +* The preview no longer has a checkbox: its footer shows the current mode + (link opens the setting) and 「开始整理」 follows it. +* Automatic organization of new files: in 「只映射」 mode the upstream + `DesktopAutoOrganizationWatcher` never moves; it hands the settled file to + `MappedOrganizeService.TryTakeOverAutoOrganization` (mapped routing). +* Switching back to 「移动到格子」 dissolves every mapped widget and restores + every hidden desktop item. Startup: installs that already have mapped widgets + but no mode file adopt 「只映射」. + +## Desktop visibility: per item (replaces hiding the whole list view) + +* Only mapped entries are hidden, by setting `FILE_ATTRIBUTE_HIDDEN`. + Unmapped and 「放回桌面」 entries stay visible as normal desktop icons. +* Ledger `data/mapped-organize.hidden` lists every path DeskBox hid; it is + written *before* an attribute is set. Files that were already hidden are + never recorded and never touched. Pure rules: `MappedOrganizeHiddenLedger`. +* Restore (`Reconcile` with nothing desired / member removed): entry leaves its + widget, 「放回桌面」, 「退出映射整理」, switching to move mode, DeskBox exit + (shutdown step + ProcessExit), next start after a crash (members re-hidden, + stale records restored), and the uninstaller + (`installer/DeskBox.ForkMappedOrganize.iss`, after the process is stopped). +* `MappedOrganizeHiddenRegistry` lets the widget folder loader + (`FileService`: snapshot filter, `ClassifyExistingEntry`, `ShouldDisplayEntry`) + keep listing DeskBox-hidden members; it is seeded lazily from the ledger. +* The legacy `desktopIconsHiddenByDeskBox` marker (whole list view hidden by + older builds) is repaired once at startup. +* Settings warns when Explorer shows hidden items (HKCU …\Explorer\Advanced + `Hidden`=1): mapped entries then still appear as faded icons. + +## 「放回桌面」 + +The item menu row 「移回桌面」 reads 「放回桌面」 in mapped widgets and calls +`MappedOrganizeService.KeepOnDesktop` (single and multi-select): membership +removed, attribute restored, path recorded in `data/mapped-organize.kept` so +automatic sorting and 「一键整理」 skip it (follows renames, dropped on delete). +Dragging it into a mapped widget or confirming a preview that maps it clears +the mark. Entries deselected in a confirmed mapped preview are kept the same +way. 「退出映射整理」 clears the list. ## Multi-monitor / sleep @@ -74,17 +102,25 @@ topology profiles and wake recovery apply unchanged. * `DesktopOrganizationRuleResolver.cs`, `DesktopOrganizationCoordinator.cs`: exclude mapped widgets. * `DesktopOrganizationTaskView.xaml` (+ `.Actions.cs` one call), - `FileSurfaceContent.SelectionAndMenus.cs` (one call). + `FileSurfaceContent.SelectionAndMenus.cs` (blank menu call, item-menu + localizer, 「放回桌面」 interception). +* `FileService.cs`: DeskBox-hidden members stay displayable (3 conditions). +* `DesktopAutoOrganizationWatcher.cs`: 只映射 hand-off (one block). +* `DesktopOrganizationSettingsSection.xaml`: one host panel for the mode card. +* `installer/DeskBox.Uninstall.iss`: include + one call. * `Strings/*.json`: 6 keys inserted after `DesktopOrganization.Preview.Title` (zh-CN / zh-TW translated, other locales English fallback). ## Known gaps -* Manual mode: new desktop files stay unassigned (and therefore invisible - while icons are hidden) until 「一键整理」. +* Manual mode: new desktop files stay unassigned (visible on the desktop) + until 「一键整理」. +* Public Desktop entries need admin rights to change attributes; when that + fails they stay visible on the desktop as well as in the widget. +* Hidden entries are also hidden in File Explorer's Desktop folder view. * Preview "use existing widget" destination choices are ignored in mapped mode (grouping is per category). -* No dedicated entry in the Settings window yet; the auto/manual switch is in - the mapped widget's blank-area menu. +* The auto/manual switch for mapped widgets stays in the mapped widget's + blank-area menu. * Not runtime-verified on a real desktop in this change (CI builds and runs unit tests only). diff --git a/installer/DeskBox.ForkMappedOrganize.iss b/installer/DeskBox.ForkMappedOrganize.iss new file mode 100644 index 000000000..29f404c07 --- /dev/null +++ b/installer/DeskBox.ForkMappedOrganize.iss @@ -0,0 +1,58 @@ +// GOXF/DeskBox fork: 「映射整理」 hides mapped desktop entries by setting the +// hidden attribute and records every entry it hid in +// data\mapped-organize.hidden (one absolute path per line). The app restores +// them when mapping ends or DeskBox exits; the uninstaller stops DeskBox +// forcibly, so restore the recorded entries here as well. Entries that were +// hidden before DeskBox touched them are never recorded and stay hidden. +// Included from DeskBox.Uninstall.iss (inside its [Code] section). + +const + DeskBoxMappedOrganizeHiddenLedgerPath = '{localappdata}\DeskBox\data\mapped-organize.hidden'; + DeskBoxFileAttributeHidden = $2; + DeskBoxInvalidFileAttributes = $FFFFFFFF; + +function DeskBoxGetFileAttributes(lpFileName: String): Cardinal; + external 'GetFileAttributesW@kernel32.dll stdcall'; +function DeskBoxSetFileAttributes(lpFileName: String; dwFileAttributes: Cardinal): Boolean; + external 'SetFileAttributesW@kernel32.dll stdcall'; + +procedure RestoreMappedOrganizeHiddenDesktopItems; +var + LedgerPath: string; + Lines: TArrayOfString; + Index: Integer; + ItemPath: string; + Attributes: Cardinal; + Restored: Integer; +begin + LedgerPath := ExpandConstant(DeskBoxMappedOrganizeHiddenLedgerPath); + if not FileExists(LedgerPath) then + Exit; + + if not LoadStringsFromFile(LedgerPath, Lines) then + begin + Log('DeskBox uninstall could not read the mapped-organize hidden ledger.'); + Exit; + end; + + Restored := 0; + for Index := 0 to GetArrayLength(Lines) - 1 do + begin + ItemPath := Trim(Lines[Index]); + if ItemPath = '' then + Continue; + + Attributes := DeskBoxGetFileAttributes(ItemPath); + if (Attributes <> DeskBoxInvalidFileAttributes) and + ((Attributes and DeskBoxFileAttributeHidden) <> 0) then + begin + if DeskBoxSetFileAttributes(ItemPath, Attributes and (not DeskBoxFileAttributeHidden)) then + Restored := Restored + 1 + else + Log('DeskBox uninstall could not restore a hidden desktop item: ' + ItemPath); + end; + end; + + SaveStringToFile(LedgerPath, '', False); + Log(Format('DeskBox uninstall restored %d desktop items hidden by mapped organize.', [Restored])); +end; diff --git a/installer/DeskBox.Uninstall.iss b/installer/DeskBox.Uninstall.iss index 29d78c3a3..4d799df9c 100644 --- a/installer/DeskBox.Uninstall.iss +++ b/installer/DeskBox.Uninstall.iss @@ -949,10 +949,15 @@ begin end; end; +#include "DeskBox.ForkMappedOrganize.iss" + procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); begin if CurUninstallStep = usUninstall then + begin StopDeskBoxProcess; + RestoreMappedOrganizeHiddenDesktopItems; + end; if CurUninstallStep = usPostUninstall then begin diff --git a/src/DeskBox/Controls/DesktopOrganizationTaskView.MappedOrganize.cs b/src/DeskBox/Controls/DesktopOrganizationTaskView.MappedOrganize.cs index 384cfcc1f..7a6463db7 100644 --- a/src/DeskBox/Controls/DesktopOrganizationTaskView.MappedOrganize.cs +++ b/src/DeskBox/Controls/DesktopOrganizationTaskView.MappedOrganize.cs @@ -6,31 +6,62 @@ namespace DeskBox.Controls; /// -/// Fork feature 「映射整理」: the preview's 「只映射,不移动文件」 option. When -/// checked, confirming the preview creates mapped-organize widgets that only -/// record membership; no file leaves the Desktop folders. +/// Fork feature 「映射整理」: the preview follows the global 「整理方式」 setting +/// (设置 → 桌面整理). The footer shows the current mode read-only with a link +/// to the setting; in 「只映射」 mode confirming the preview creates +/// mapped-organize widgets that only record membership and no file leaves the +/// Desktop folders. /// public sealed partial class DesktopOrganizationTaskView { - private bool _mapOnlyInitialized; + private bool _organizeModeInitialized; - private void MapOnlyCheckBox_Loaded(object sender, RoutedEventArgs e) + private void OrganizeModeLink_Loaded(object sender, RoutedEventArgs e) { - if (_mapOnlyInitialized) + RefreshOrganizeModeLink(); + if (_organizeModeInitialized) { return; } - _mapOnlyInitialized = true; - MapOnlyCheckBox.Content = T("MappedOrganize.Preview.MapOnly"); - ToolTipService.SetToolTip(MapOnlyCheckBox, T("MappedOrganize.Preview.MapOnlyDescription")); - OrganizationCompleted += (_, _) => MapOnlyCheckBox.Visibility = Visibility.Collapsed; + _organizeModeInitialized = true; + OrganizationCompleted += (_, _) => OrganizeModeLink.Visibility = Visibility.Collapsed; + ForkOrganizeModeSettings.Changed += _ => DispatcherQueue?.TryEnqueue(RefreshOrganizeModeLink); + } + + private void OrganizeModeLink_Click(object sender, RoutedEventArgs e) + { + try + { + App.Current.ShowSettings("DesktopOrganizationSettings"); + } + catch (Exception ex) + { + App.Log($"[MappedOrganize] Opening the organize-mode setting failed: {ex.Message}"); + } + } + + private void RefreshOrganizeModeLink() + { + DesktopOrganizeMode mode = ForkOrganizeModeSettings.Load(); + OrganizeModeLink.Content = ForkOrganizeModeText.Format( + ForkOrganizeModeText.Key.PreviewModeFormat, + ForkOrganizeModeText.ModeName(mode)) + + ForkOrganizeModeText.Get(ForkOrganizeModeText.Key.PreviewChange); + ToolTipService.SetToolTip(OrganizeModeLink, ForkOrganizeModeText.Get(mode == DesktopOrganizeMode.MapOnly + ? ForkOrganizeModeText.Key.PreviewTooltipMapOnly + : ForkOrganizeModeText.Key.PreviewTooltipMove)); + Microsoft.UI.Xaml.Automation.AutomationProperties.SetName( + OrganizeModeLink, + ForkOrganizeModeText.Get(ForkOrganizeModeText.Key.SettingTitle)); } /// Returns true when the mapped path handled the confirm click. private async Task TryRunMappedOrganizeAsync(DesktopOrganizationPlan previewPlan) { - if (MapOnlyCheckBox.IsChecked != true) + DesktopOrganizeMode mode = ForkOrganizeModeSettings.Load(); + RefreshOrganizeModeLink(); + if (!ForkOrganizeModePolicy.ConfirmMapsInsteadOfMoving(mode)) { return false; } @@ -44,6 +75,15 @@ private async Task TryRunMappedOrganizeAsync(DesktopOrganizationPlan previ return true; } + // Entries the user deselected in the preview stay on the desktop + // (「放回桌面」) instead of being swept up by automatic sorting. + List keepOnDesktop = previewPlan.Targets + .SelectMany(target => + _targetSelections.TryGetValue(target.SourceBucketId, out DesktopOrganizationTargetSelection? selection) && + !selection.IsSelected + ? target.Items.Select(item => item.SourcePath) + : target.Items.Where(item => _excludedSourcePaths.Contains(item.SourcePath)).Select(item => item.SourcePath)) + .ToList(); List groups = previewPlan.Targets .Where(target => !_targetSelections.TryGetValue(target.SourceBucketId, out DesktopOrganizationTargetSelection? selection) || selection.IsSelected) @@ -70,10 +110,10 @@ private async Task TryRunMappedOrganizeAsync(DesktopOrganizationPlan previ _isExecuting = true; ExecuteButton.IsEnabled = false; CancelButton.IsEnabled = false; - MapOnlyCheckBox.IsEnabled = false; + OrganizeModeLink.IsEnabled = false; try { - int count = await service.ApplyGroupsAsync(groups); + int count = await service.ApplyGroupsAsync(groups, keepOnDesktop); _hasCompletedExecution = true; ResultInfo.Severity = InfoBarSeverity.Success; ResultInfo.Title = T("DesktopOrganization.Result.SuccessTitle"); @@ -100,7 +140,7 @@ private async Task TryRunMappedOrganizeAsync(DesktopOrganizationPlan previ { _isExecuting = false; CancelButton.IsEnabled = true; - MapOnlyCheckBox.IsEnabled = true; + OrganizeModeLink.IsEnabled = true; DoneButton.IsEnabled = true; } diff --git a/src/DeskBox/Controls/DesktopOrganizationTaskView.xaml b/src/DeskBox/Controls/DesktopOrganizationTaskView.xaml index 8a5ecd449..9b4920e2e 100644 --- a/src/DeskBox/Controls/DesktopOrganizationTaskView.xaml +++ b/src/DeskBox/Controls/DesktopOrganizationTaskView.xaml @@ -228,8 +228,8 @@ - +