Skip to content

Commit

Permalink
🎱 Upgrade to .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
database64128 committed Mar 19, 2024
1 parent b7abb6b commit 752d8ff
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 129 deletions.
2 changes: 1 addition & 1 deletion YoutubeDl.Wpf.Tests/YoutubeDl.Wpf.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-windows10.0.22621.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>

<IsPackable>false</IsPackable>

Expand Down
2 changes: 1 addition & 1 deletion YoutubeDl.Wpf/Models/BackendInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class BackendInstance : ReactiveObject, IEnableLogger
private readonly BackendService _backendService;
private readonly Process _process;

public List<string> GeneratedDownloadArguments { get; } = new();
public List<string> GeneratedDownloadArguments { get; } = [];

[Reactive]
public double DownloadProgressPercentage { get; set; } // 0.99 is 99%.
Expand Down
10 changes: 3 additions & 7 deletions YoutubeDl.Wpf/Models/BackendService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

namespace YoutubeDl.Wpf.Models;

public class BackendService : ReactiveObject, IEnableLogger
public class BackendService(ObservableSettings settings) : ReactiveObject, IEnableLogger
{
private readonly ObservableSettings _settings;

public List<BackendInstance> Instances { get; } = new();
public List<BackendInstance> Instances { get; } = [];

[Reactive]
public bool CanUpdate { get; set; } = true;
Expand All @@ -24,11 +22,9 @@ public class BackendService : ReactiveObject, IEnableLogger
[Reactive]
public TaskbarItemProgressState ProgressState { get; set; }

public BackendService(ObservableSettings settings) => _settings = settings;

public BackendInstance CreateInstance()
{
var instance = new BackendInstance(_settings, this);
var instance = new BackendInstance(settings, this);
Instances.Add(instance);
return instance;
}
Expand Down
101 changes: 34 additions & 67 deletions YoutubeDl.Wpf/Models/ObservableSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,141 +4,108 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace YoutubeDl.Wpf.Models;

public class ObservableSettings : ReactiveObject
public class ObservableSettings(Settings settings) : ReactiveObject
{
public Settings AppSettings { get; }
public Settings AppSettings { get; } = settings;

public BaseTheme AppColorMode { get; set; }
public BaseTheme AppColorMode { get; set; } = settings.AppColorMode;

[Reactive]
public double WindowWidth { get; set; }
public double WindowWidth { get; set; } = settings.WindowWidth;

[Reactive]
public double WindowHeight { get; set; }
public double WindowHeight { get; set; } = settings.WindowHeight;

[Reactive]
public BackendTypes Backend { get; set; }
public BackendTypes Backend { get; set; } = settings.Backend;

[Reactive]
public string BackendPath { get; set; }
public string BackendPath { get; set; } = settings.BackendPath;

/// <summary>
/// Gets or sets the list of arguments passed
/// to the backend process for all types of operations.
/// </summary>
public ObservableCollection<BackendArgument> BackendGlobalArguments { get; set; }
public ObservableCollection<BackendArgument> BackendGlobalArguments { get; set; } = new(settings.BackendGlobalArguments);

/// <summary>
/// Gets or sets the list of arguments passed
/// to the backend process for download operations.
/// </summary>
public List<BackendArgument> BackendDownloadArguments { get; set; }
public List<BackendArgument> BackendDownloadArguments { get; set; } = new(settings.BackendDownloadArguments);

[Reactive]
public bool BackendAutoUpdate { get; set; }
public bool BackendAutoUpdate { get; set; } = settings.BackendAutoUpdate;

[Reactive]
public DateTimeOffset BackendLastUpdateCheck { get; set; }
public DateTimeOffset BackendLastUpdateCheck { get; set; } = settings.BackendLastUpdateCheck;

[Reactive]
public string FfmpegPath { get; set; }
public string FfmpegPath { get; set; } = settings.FfmpegPath;

[Reactive]
public string Proxy { get; set; }
public string Proxy { get; set; } = settings.Proxy;

[Reactive]
public int LoggingMaxEntries { get; set; }
public int LoggingMaxEntries { get; set; } = settings.LoggingMaxEntries;

[Reactive]
public Preset? SelectedPreset { get; set; }
public Preset? SelectedPreset { get; set; } = settings.SelectedPreset;

/// <summary>
/// This is a hack to prevent <see cref="SelectedPreset"/> from being changed to null.
/// Another solution is to manually implement equality for <see cref="Preset"/>,
/// which is much harder to get it right, and would look terrible compared to this little hack.
/// </summary>
[Reactive]
public string SelectedPresetText { get; set; }
public string SelectedPresetText { get; set; } = settings.SelectedPreset.DisplayName;

public List<Preset> CustomPresets { get; set; }
public List<Preset> CustomPresets { get; set; } = new(settings.CustomPresets);

[Reactive]
public bool AddMetadata { get; set; }
public bool AddMetadata { get; set; } = settings.AddMetadata;

[Reactive]
public bool DownloadThumbnail { get; set; }
public bool DownloadThumbnail { get; set; } = settings.DownloadThumbnail;

[Reactive]
public bool DownloadSubtitles { get; set; }
public bool DownloadSubtitles { get; set; } = settings.DownloadSubtitles;

[Reactive]
public bool DownloadSubtitlesAllLanguages { get; set; }
public bool DownloadSubtitlesAllLanguages { get; set; } = settings.DownloadSubtitlesAllLanguages;

[Reactive]
public bool DownloadAutoGeneratedSubtitles { get; set; }
public bool DownloadAutoGeneratedSubtitles { get; set; } = settings.DownloadAutoGeneratedSubtitles;

[Reactive]
public bool DownloadPlaylist { get; set; }
public bool DownloadPlaylist { get; set; } = settings.DownloadPlaylist;

[Reactive]
public bool UseCustomOutputTemplate { get; set; }
public bool UseCustomOutputTemplate { get; set; } = settings.UseCustomOutputTemplate;

[Reactive]
public string CustomOutputTemplate { get; set; }
public string CustomOutputTemplate { get; set; } = settings.CustomOutputTemplate;

/// <summary>
/// Gets the list of used output templates.
/// New templates are appended to the list.
/// </summary>
public List<string> OutputTemplateHistory { get; }
public List<string> OutputTemplateHistory { get; } = new(settings.OutputTemplateHistory);

[Reactive]
public bool UseCustomPath { get; set; }
public bool UseCustomPath { get; set; } = settings.UseCustomPath;

[Reactive]
public string DownloadPath { get; set; }
public string DownloadPath { get; set; } = settings.DownloadPath;

/// <summary>
/// Gets the list of used download paths.
/// New paths are appended to the list.
/// </summary>
public List<string> DownloadPathHistory { get; }

public ObservableSettings(Settings settings)
{
AppSettings = settings;
AppColorMode = settings.AppColorMode;
WindowWidth = settings.WindowWidth;
WindowHeight = settings.WindowHeight;
Backend = settings.Backend;
BackendPath = settings.BackendPath;
BackendGlobalArguments = new(settings.BackendGlobalArguments);
BackendDownloadArguments = new(settings.BackendDownloadArguments);
BackendAutoUpdate = settings.BackendAutoUpdate;
BackendLastUpdateCheck = settings.BackendLastUpdateCheck;
FfmpegPath = settings.FfmpegPath;
Proxy = settings.Proxy;
LoggingMaxEntries = settings.LoggingMaxEntries;
SelectedPreset = settings.SelectedPreset;
SelectedPresetText = settings.SelectedPreset.DisplayName;
CustomPresets = new(settings.CustomPresets);
AddMetadata = settings.AddMetadata;
DownloadThumbnail = settings.DownloadThumbnail;
DownloadSubtitles = settings.DownloadSubtitles;
DownloadSubtitlesAllLanguages = settings.DownloadSubtitlesAllLanguages;
DownloadAutoGeneratedSubtitles = settings.DownloadAutoGeneratedSubtitles;
DownloadPlaylist = settings.DownloadPlaylist;
UseCustomOutputTemplate = settings.UseCustomOutputTemplate;
CustomOutputTemplate = settings.CustomOutputTemplate;
OutputTemplateHistory = new(settings.OutputTemplateHistory);
UseCustomPath = settings.UseCustomPath;
DownloadPath = settings.DownloadPath;
DownloadPathHistory = new(settings.DownloadPathHistory);
}
public List<string> DownloadPathHistory { get; } = new(settings.DownloadPathHistory);

public void UpdateAppSettings()
{
Expand All @@ -147,15 +114,15 @@ public void UpdateAppSettings()
AppSettings.WindowHeight = WindowHeight;
AppSettings.Backend = Backend;
AppSettings.BackendPath = BackendPath;
AppSettings.BackendGlobalArguments = BackendGlobalArguments.ToArray();
AppSettings.BackendDownloadArguments = BackendDownloadArguments.ToArray();
AppSettings.BackendGlobalArguments = [.. BackendGlobalArguments];
AppSettings.BackendDownloadArguments = [.. BackendDownloadArguments];
AppSettings.BackendAutoUpdate = BackendAutoUpdate;
AppSettings.BackendLastUpdateCheck = BackendLastUpdateCheck;
AppSettings.FfmpegPath = FfmpegPath;
AppSettings.Proxy = Proxy;
// AppSettings.LoggingMaxEntries is managed by the validation handler.
AppSettings.SelectedPreset = SelectedPreset ?? Preset.Auto;
AppSettings.CustomPresets = CustomPresets.ToArray();
AppSettings.CustomPresets = [.. CustomPresets];
AppSettings.AddMetadata = AddMetadata;
AppSettings.DownloadThumbnail = DownloadThumbnail;
AppSettings.DownloadSubtitles = DownloadSubtitles;
Expand All @@ -165,8 +132,8 @@ public void UpdateAppSettings()
AppSettings.UseCustomOutputTemplate = UseCustomOutputTemplate;
AppSettings.CustomOutputTemplate = CustomOutputTemplate;
AppSettings.UseCustomPath = UseCustomPath;
AppSettings.OutputTemplateHistory = OutputTemplateHistory.ToArray();
AppSettings.OutputTemplateHistory = [.. OutputTemplateHistory];
AppSettings.DownloadPath = DownloadPath;
AppSettings.DownloadPathHistory = DownloadPathHistory.ToArray();
AppSettings.DownloadPathHistory = [.. DownloadPathHistory];
}
}
4 changes: 2 additions & 2 deletions YoutubeDl.Wpf/Models/Preset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public IEnumerable<string> ToArgs()
public static readonly Preset Empty = new();

public static readonly Preset[] PredefinedPresets =
{
[
Auto,
new(FormatArg: "bestvideo+bestaudio/best", IsPredefined: true),
new(FormatArg: "bestvideo+bestaudio", IsPredefined: true),
Expand Down Expand Up @@ -105,5 +105,5 @@ public IEnumerable<string> ToArgs()
new(ContainerArg: "ogg", IsPredefined: true),
new(ContainerArg: "m4a", IsPredefined: true),
new(ContainerArg: "mp3", IsPredefined: true),
};
];
}
17 changes: 4 additions & 13 deletions YoutubeDl.Wpf/Models/QueuedTextBoxSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@

namespace YoutubeDl.Wpf.Models;

public class QueuedTextBoxSink : ReactiveObject, ILogEventSink
public class QueuedTextBoxSink(Settings settings, IFormatProvider? formatProvider = null) : ReactiveObject, ILogEventSink
{
private readonly object _locker = new();
private readonly Settings _settings;
private readonly Queue<string> _queuedLogMessages;
private readonly IFormatProvider? _formatProvider;
private readonly Queue<string> _queuedLogMessages = new(settings.LoggingMaxEntries);
private int _contentLength;

[Reactive]
public string Content { get; set; } = "";

public QueuedTextBoxSink(Settings settings, IFormatProvider? formatProvider = null)
{
_settings = settings;
_queuedLogMessages = new(settings.LoggingMaxEntries);
_formatProvider = formatProvider;
}

public void Emit(LogEvent logEvent)
{
// Workaround for https://github.com/reactiveui/ReactiveUI/issues/3415 before upstream has a fix.
Expand All @@ -34,7 +25,7 @@ public void Emit(LogEvent logEvent)
return;
}

var renderedMessage = logEvent.RenderMessage(_formatProvider);
var renderedMessage = logEvent.RenderMessage(formatProvider);

// 2023-04-24T10:24:00.000+00:00 [I] Hi!
var length = 29 + 1 + 3 + 1 + renderedMessage.Length + Environment.NewLine.Length;
Expand Down Expand Up @@ -65,7 +56,7 @@ public void Emit(LogEvent logEvent)

lock (_locker)
{
while (_queuedLogMessages.Count >= _settings.LoggingMaxEntries)
while (_queuedLogMessages.Count >= settings.LoggingMaxEntries)
{
var dequeuedMessage = _queuedLogMessages.Dequeue();
_contentLength -= dequeuedMessage.Length;
Expand Down
10 changes: 5 additions & 5 deletions YoutubeDl.Wpf/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public class Settings

public string BackendPath { get; set; } = "";

public BackendArgument[] BackendGlobalArguments { get; set; } = Array.Empty<BackendArgument>();
public BackendArgument[] BackendGlobalArguments { get; set; } = [];

public BackendArgument[] BackendDownloadArguments { get; set; } = Array.Empty<BackendArgument>();
public BackendArgument[] BackendDownloadArguments { get; set; } = [];

public bool BackendAutoUpdate { get; set; } = true;

Expand All @@ -69,7 +69,7 @@ public class Settings

public Preset SelectedPreset { get; set; } = Preset.Auto;

public Preset[] CustomPresets { get; set; } = Array.Empty<Preset>();
public Preset[] CustomPresets { get; set; } = [];

public bool AddMetadata { get; set; } = true;

Expand All @@ -87,13 +87,13 @@ public class Settings

public string CustomOutputTemplate { get; set; } = DefaultCustomOutputTemplate;

public string[] OutputTemplateHistory { get; set; } = Array.Empty<string>();
public string[] OutputTemplateHistory { get; set; } = [];

public bool UseCustomPath { get; set; }

public string DownloadPath { get; set; } = "";

public string[] DownloadPathHistory { get; set; } = Array.Empty<string>();
public string[] DownloadPathHistory { get; set; } = [];

/// <summary>
/// Loads settings from Settings.json.
Expand Down
15 changes: 4 additions & 11 deletions YoutubeDl.Wpf/ViewModels/ArgumentChipViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@

namespace YoutubeDl.Wpf.ViewModels;

public class ArgumentChipViewModel : ReactiveValidationObject
public class ArgumentChipViewModel(BackendArgument argument, bool isRemovable, Action<ArgumentChipViewModel> action) : ReactiveValidationObject
{
[Reactive]
public BackendArgument Argument { get; set; }
public BackendArgument Argument { get; set; } = argument;

[Reactive]
public bool IsRemovable { get; set; }
public bool IsRemovable { get; set; } = isRemovable;

public ReactiveCommand<ArgumentChipViewModel, Unit> RemoveArgumentCommand { get; }

public ArgumentChipViewModel(BackendArgument argument, bool isRemovable, Action<ArgumentChipViewModel> action)
{
Argument = argument;
IsRemovable = isRemovable;
RemoveArgumentCommand = ReactiveCommand.Create(action);
}
public ReactiveCommand<ArgumentChipViewModel, Unit> RemoveArgumentCommand { get; } = ReactiveCommand.Create(action);
}
12 changes: 3 additions & 9 deletions YoutubeDl.Wpf/ViewModels/HistoryItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@

namespace YoutubeDl.Wpf.ViewModels;

public class HistoryItemViewModel : ReactiveValidationObject
public class HistoryItemViewModel(string text, Action<HistoryItemViewModel> action) : ReactiveValidationObject
{
[Reactive]
public string Text { get; set; }
public string Text { get; set; } = text;

public ReactiveCommand<HistoryItemViewModel, Unit> DeleteItemCommand { get; }

public HistoryItemViewModel(string text, Action<HistoryItemViewModel> action)
{
Text = text;
DeleteItemCommand = ReactiveCommand.Create(action);
}
public ReactiveCommand<HistoryItemViewModel, Unit> DeleteItemCommand { get; } = ReactiveCommand.Create(action);

public override string ToString() => Text;
}
2 changes: 1 addition & 1 deletion YoutubeDl.Wpf/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class HomeViewModel : ReactiveValidationObject

public PresetDialogViewModel PresetDialogVM { get; }

public ObservableCollection<Preset> Presets { get; } = new();
public ObservableCollection<Preset> Presets { get; } = [];

/// <summary>
/// Gets the output template history.
Expand Down
Loading

0 comments on commit 752d8ff

Please sign in to comment.