Files
Windows-Tool/src/WindowsToolbox.Core/Models.cs
T
leefer e70cd0f604 新增下载目录整理、修复计划任务状态回显并优化启动检测速度
- 下载目录整理:按当天日期在下载目录内建子目录,文件按类型分类(安装包/压缩包/文档/图片/视频/音频/其他),文件夹进日期目录根;跳过下载中临时文件、日期格式旧目录和系统项;支持撤销与每月计划任务
- 修复:重开软件后目录整理页现在回填已保存配置,并以任务计划程序实际状态为准显示开关;撤销按 profile 过滤,桌面与下载互不干扰
- 性能:激活状态查询移出启动流程,仅在 KMS 页/相关操作/手动刷新时按需执行;Defender 状态后台异步刷新;新增状态缓存供下次启动首显
- 去除 D:\desktop 硬编码默认值;Verification 增加下载整理、同日合并、排除规则与撤销过滤测试
2026-09-19 21:47:47 +08:00

184 lines
6.4 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
namespace WindowsToolbox.Core;
public enum ToolboxCommandKind
{
DetectStatus,
EnableClassicContextMenu,
RestoreContextMenu,
HideShortcutArrow,
RestoreShortcutArrow,
PauseWindowsUpdate,
DisableWindowsUpdate,
RestoreWindowsUpdate,
ConfigureUpdateRenewal,
DisableDefenderProtection,
RestoreDefenderProtection,
PrepareAutoLogon,
RestoreAutoLogonPreparation,
ArchiveDesktop,
UndoDesktopArchive,
ConfigureDesktopSchedule,
TidyDownloads,
UndoDownloadsTidy,
ConfigureDownloadsSchedule,
ActivateWindowsKms,
RestoreKmsConfiguration
}
public sealed record ToolboxCommand
{
public required string Id { get; init; }
public required ToolboxCommandKind Kind { get; init; }
public Dictionary<string, string> Arguments { get; init; } = new(StringComparer.OrdinalIgnoreCase);
public DateTimeOffset CreatedAt { get; init; } = DateTimeOffset.Now;
public string? ResultPath { get; init; }
}
public sealed record CommandStepResult(
string Name,
bool Success,
string Message,
bool RequiresRestart = false);
public sealed record CommandResult
{
public required string CommandId { get; init; }
public required ToolboxCommandKind Kind { get; init; }
public bool Success { get; init; }
public string Summary { get; init; } = string.Empty;
public List<CommandStepResult> Steps { get; init; } = [];
public DateTimeOffset CompletedAt { get; init; } = DateTimeOffset.Now;
}
public sealed record SystemStatus
{
public string ProductName { get; init; } = "Windows";
public string EditionId { get; init; } = "Unknown";
public string DisplayVersion { get; init; } = "Unknown";
public string Build { get; init; } = "Unknown";
public bool IsWindows11 { get; init; }
public bool IsAdministrator { get; init; }
public bool ClassicContextMenuEnabled { get; init; }
public bool ShortcutArrowHidden { get; init; }
public string UpdateMode { get; init; } = "检测中";
public DateTimeOffset? UpdatePauseUntil { get; init; }
public bool? DefenderRealtimeProtectionEnabled { get; init; }
public bool? TamperProtectionEnabled { get; init; }
public bool AutoLogonOptionPrepared { get; init; }
public string ActivationStatus { get; init; } = "未知";
public string? PartialProductKey { get; init; }
public string? KmsHost { get; init; }
}
public sealed record RegistryValueSnapshot
{
public required string Hive { get; init; }
public required string KeyPath { get; init; }
public required string ValueName { get; init; }
public bool Exists { get; init; }
public int Kind { get; init; }
public string? TextValue { get; init; }
public string[]? TextValues { get; init; }
public byte[]? BinaryValue { get; init; }
public long? NumericValue { get; init; }
}
public sealed record FeatureSnapshot
{
public required string Id { get; init; }
public required string Feature { get; init; }
public DateTimeOffset CreatedAt { get; init; } = DateTimeOffset.Now;
public List<RegistryValueSnapshot> RegistryValues { get; init; } = [];
public Dictionary<string, string?> Metadata { get; init; } = new(StringComparer.OrdinalIgnoreCase);
}
public sealed record DesktopArchiveProfile
{
public string Id { get; init; } = "default";
public required string DestinationRoot { get; init; }
public bool ExcludeShortcuts { get; init; } = true;
public bool RenameOnCollision { get; init; } = true;
public int MonthlyDay { get; init; } = 1;
public TimeOnly RunAt { get; init; } = new(9, 0);
}
public sealed record DownloadsTidyProfile
{
public string Id { get; init; } = "downloads";
public bool RenameOnCollision { get; init; } = true;
public int MonthlyDay { get; init; } = 1;
public TimeOnly RunAt { get; init; } = new(9, 0);
}
public sealed record ArchivedFile(string OriginalPath, string ArchivedPath, long Length, bool IsDirectory = false);
public sealed record ArchiveManifest
{
public required string Id { get; init; }
public required string ProfileId { get; init; }
public required string DestinationFolder { get; init; }
public DateTimeOffset CreatedAt { get; init; } = DateTimeOffset.Now;
public List<ArchivedFile> Files { get; init; } = [];
public List<string> Skipped { get; init; } = [];
public List<string> Errors { get; init; } = [];
}
public sealed record KmsKeyEntry(
string EditionId,
string DisplayName,
string ProductKey,
string AppliesTo,
bool Supported = true);
public sealed record OperationLogEntry
{
public required string Id { get; init; }
public required string Feature { get; init; }
public required string Action { get; init; }
public required bool Success { get; init; }
public required string Summary { get; init; }
public DateTimeOffset Timestamp { get; init; } = DateTimeOffset.Now;
public List<CommandStepResult> Steps { get; init; } = [];
}
public static class JsonDefaults
{
public static readonly JsonSerializerOptions Options = new()
{
WriteIndented = true,
PropertyNameCaseInsensitive = true,
Converters = { new JsonStringEnumConverter() }
};
}
public sealed record StatusCache
{
public DateTimeOffset UpdatedAt { get; init; } = DateTimeOffset.Now;
public bool? DefenderRealtimeProtectionEnabled { get; init; }
public bool? TamperProtectionEnabled { get; init; }
public string ActivationStatus { get; init; } = "未知";
public string? PartialProductKey { get; init; }
}
public static class ToolboxPaths
{
public static string UserRoot => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"WindowsToolbox");
public static string MachineRoot => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
"WindowsToolbox");
public static string PendingCommands => Path.Combine(UserRoot, "Pending");
public static string Profiles => Path.Combine(UserRoot, "Profiles");
public static string Manifests => Path.Combine(UserRoot, "ArchiveManifests");
public static string Logs => Path.Combine(UserRoot, "Logs");
public static string Cache => Path.Combine(UserRoot, "Cache");
public static string Snapshots => Path.Combine(MachineRoot, "Snapshots");
public static string Assets => Path.Combine(MachineRoot, "Assets");
}