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 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 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 RegistryValues { get; init; } = []; public Dictionary 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 Files { get; init; } = []; public List Skipped { get; init; } = []; public List 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 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"); }