|
| 1 | +using MaterialDesignThemes.Wpf; |
| 2 | +using ReactiveUI; |
| 3 | +using ReactiveUI.Fody.Helpers; |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Collections.ObjectModel; |
| 7 | +using System.Linq; |
| 8 | + |
| 9 | +namespace YoutubeDl.Wpf.Models; |
| 10 | + |
| 11 | +public class ObservableSettings : ReactiveObject |
| 12 | +{ |
| 13 | + public BaseTheme AppColorMode { get; set; } |
| 14 | + |
| 15 | + [Reactive] |
| 16 | + public BackendTypes Backend { get; set; } |
| 17 | + |
| 18 | + [Reactive] |
| 19 | + public string BackendPath { get; set; } |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Gets or sets the list of arguments passed |
| 23 | + /// to the backend process for all types of operations. |
| 24 | + /// </summary> |
| 25 | + public ObservableCollection<BackendArgument> BackendGlobalArguments { get; set; } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Gets or sets the list of arguments passed |
| 29 | + /// to the backend process for download operations. |
| 30 | + /// </summary> |
| 31 | + public List<BackendArgument> BackendDownloadArguments { get; set; } |
| 32 | + |
| 33 | + [Reactive] |
| 34 | + public bool BackendAutoUpdate { get; set; } |
| 35 | + |
| 36 | + [Reactive] |
| 37 | + public DateTimeOffset BackendLastUpdateCheck { get; set; } |
| 38 | + |
| 39 | + [Reactive] |
| 40 | + public string FfmpegPath { get; set; } |
| 41 | + |
| 42 | + [Reactive] |
| 43 | + public string Proxy { get; set; } |
| 44 | + |
| 45 | + [Reactive] |
| 46 | + public int LoggingMaxEntries { get; set; } |
| 47 | + |
| 48 | + [Reactive] |
| 49 | + public Preset? SelectedPreset { get; set; } |
| 50 | + |
| 51 | + /// <summary> |
| 52 | + /// This is a hack to prevent <see cref="SelectedPreset"/> from being changed to null. |
| 53 | + /// Another solution is to manually implement equality for <see cref="Preset"/>, |
| 54 | + /// which is much harder to get it right, and would look terrible compared to this little hack. |
| 55 | + /// </summary> |
| 56 | + [Reactive] |
| 57 | + public string SelectedPresetText { get; set; } |
| 58 | + |
| 59 | + public List<Preset> CustomPresets { get; set; } |
| 60 | + |
| 61 | + [Reactive] |
| 62 | + public bool AddMetadata { get; set; } |
| 63 | + |
| 64 | + [Reactive] |
| 65 | + public bool DownloadThumbnail { get; set; } |
| 66 | + |
| 67 | + [Reactive] |
| 68 | + public bool DownloadSubtitles { get; set; } |
| 69 | + |
| 70 | + [Reactive] |
| 71 | + public bool DownloadSubtitlesAllLanguages { get; set; } |
| 72 | + |
| 73 | + [Reactive] |
| 74 | + public bool DownloadAutoGeneratedSubtitles { get; set; } |
| 75 | + |
| 76 | + [Reactive] |
| 77 | + public bool DownloadPlaylist { get; set; } |
| 78 | + |
| 79 | + [Reactive] |
| 80 | + public bool UseCustomOutputTemplate { get; set; } |
| 81 | + |
| 82 | + [Reactive] |
| 83 | + public string CustomOutputTemplate { get; set; } |
| 84 | + |
| 85 | + [Reactive] |
| 86 | + public bool UseCustomPath { get; set; } |
| 87 | + |
| 88 | + [Reactive] |
| 89 | + public string DownloadPath { get; set; } |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// Gets the list of download path history. |
| 93 | + /// New paths are always appended to the list. |
| 94 | + /// </summary> |
| 95 | + public List<string> DownloadPathHistory { get; set; } |
| 96 | + |
| 97 | + public ObservableSettings(Settings settings) |
| 98 | + { |
| 99 | + AppColorMode = settings.AppColorMode; |
| 100 | + Backend = settings.Backend; |
| 101 | + BackendPath = settings.BackendPath; |
| 102 | + BackendGlobalArguments = new(settings.BackendGlobalArguments); |
| 103 | + BackendDownloadArguments = new(settings.BackendDownloadArguments); |
| 104 | + BackendAutoUpdate = settings.BackendAutoUpdate; |
| 105 | + BackendLastUpdateCheck = settings.BackendLastUpdateCheck; |
| 106 | + FfmpegPath = settings.FfmpegPath; |
| 107 | + Proxy = settings.Proxy; |
| 108 | + LoggingMaxEntries = settings.LoggingMaxEntries; |
| 109 | + SelectedPreset = settings.SelectedPreset; |
| 110 | + SelectedPresetText = settings.SelectedPresetText; |
| 111 | + CustomPresets = new(settings.CustomPresets); |
| 112 | + AddMetadata = settings.AddMetadata; |
| 113 | + DownloadThumbnail = settings.DownloadThumbnail; |
| 114 | + DownloadSubtitles = settings.DownloadSubtitles; |
| 115 | + DownloadSubtitlesAllLanguages = settings.DownloadSubtitlesAllLanguages; |
| 116 | + DownloadAutoGeneratedSubtitles = settings.DownloadAutoGeneratedSubtitles; |
| 117 | + DownloadPlaylist = settings.DownloadPlaylist; |
| 118 | + UseCustomOutputTemplate = settings.UseCustomOutputTemplate; |
| 119 | + CustomOutputTemplate = settings.CustomOutputTemplate; |
| 120 | + UseCustomPath = settings.UseCustomPath; |
| 121 | + DownloadPath = settings.DownloadPath; |
| 122 | + DownloadPathHistory = new(settings.DownloadPathHistory); |
| 123 | + } |
| 124 | + |
| 125 | + public void UpdateSettings(Settings settings) |
| 126 | + { |
| 127 | + settings.AppColorMode = AppColorMode; |
| 128 | + settings.Backend = Backend; |
| 129 | + settings.BackendPath = BackendPath; |
| 130 | + settings.BackendGlobalArguments = BackendGlobalArguments.ToArray(); |
| 131 | + settings.BackendDownloadArguments = BackendDownloadArguments.ToArray(); |
| 132 | + settings.BackendAutoUpdate = BackendAutoUpdate; |
| 133 | + settings.BackendLastUpdateCheck = BackendLastUpdateCheck; |
| 134 | + settings.FfmpegPath = FfmpegPath; |
| 135 | + settings.Proxy = Proxy; |
| 136 | + settings.LoggingMaxEntries = LoggingMaxEntries; |
| 137 | + settings.SelectedPreset = SelectedPreset; |
| 138 | + settings.SelectedPresetText = SelectedPresetText; |
| 139 | + settings.CustomPresets = CustomPresets.ToArray(); |
| 140 | + settings.AddMetadata = AddMetadata; |
| 141 | + settings.DownloadThumbnail = DownloadThumbnail; |
| 142 | + settings.DownloadSubtitles = DownloadSubtitles; |
| 143 | + settings.DownloadSubtitlesAllLanguages = DownloadSubtitlesAllLanguages; |
| 144 | + settings.DownloadAutoGeneratedSubtitles = DownloadAutoGeneratedSubtitles; |
| 145 | + settings.DownloadPlaylist = DownloadPlaylist; |
| 146 | + settings.UseCustomOutputTemplate = UseCustomOutputTemplate; |
| 147 | + settings.CustomOutputTemplate = CustomOutputTemplate; |
| 148 | + settings.UseCustomPath = UseCustomPath; |
| 149 | + settings.DownloadPath = DownloadPath; |
| 150 | + settings.DownloadPathHistory = DownloadPathHistory.ToArray(); |
| 151 | + } |
| 152 | +} |
0 commit comments