1 files changed, 46 insertions, 0 deletions
diff --git a/LibBeatmapDownload/DomainStats.cs b/LibBeatmapDownload/DomainStats.cs
new file mode 100644
index 0000000..a026b7d
--- /dev/null
+++ b/LibBeatmapDownload/DomainStats.cs
@@ -0,0 +1,46 @@
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+
+namespace LibBeatmapDownload;
+
+public class DomainStats(string url) : INotifyPropertyChanged {
+ public string Domain { get; } = new Uri(url).Host;
+
+ private int _total = 0;
+
+ public int Total => Success + Failed;
+
+ private int _success = 0;
+
+ public int Success {
+ get => _success;
+ set => SetField(ref _success, value);
+ }
+
+ private int _failed = 0;
+
+ public int Failed {
+ get => _failed;
+ set => SetField(ref _failed, value);
+ }
+
+ public double Progress => Total == 0 ? 100 : (double)Success / Total * 100;
+ public string ProgressString => $"{Domain} {Progress/100:P0} ({Failed}/{Total} failed)";
+
+ public event PropertyChangedEventHandler? PropertyChanged;
+
+ private readonly Stopwatch sw = Stopwatch.StartNew();
+ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Progress)));
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ProgressString)));
+ }
+
+ protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null) {
+ if (EqualityComparer<T>.Default.Equals(field, value)) return false;
+ field = value;
+ OnPropertyChanged(propertyName);
+ return true;
+ }
+}
|