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(ref T field, T value, [CallerMemberName] string? propertyName = null) { if (EqualityComparer.Default.Equals(field, value)) return false; field = value; OnPropertyChanged(propertyName); return true; } }