using System; using System.Globalization; namespace StreamPlayer.Desktop.Models; public sealed record UpdateInfo( int VersionCode, string VersionName, string ReleaseNotes, string DownloadUrl, string DownloadFileName, long DownloadSizeBytes, int DownloadCount, string ReleasePageUrl, int MinSupportedVersionCode, bool ForceUpdate) { public bool IsUpdateAvailable(int currentVersionCode) => VersionCode > currentVersionCode; public bool IsMandatory(int currentVersionCode) => ForceUpdate || (MinSupportedVersionCode > 0 && currentVersionCode < MinSupportedVersionCode); public string GetReleaseNotesPreview(int maxLength = 900) { if (string.IsNullOrWhiteSpace(ReleaseNotes)) { return string.Empty; } if (ReleaseNotes.Length <= maxLength) { return ReleaseNotes.Trim(); } return ReleaseNotes[..maxLength].TrimEnd() + Environment.NewLine + "…"; } public string FormatSize() { if (DownloadSizeBytes <= 0) { return string.Empty; } string[] suffixes = { "B", "KB", "MB", "GB" }; double size = DownloadSizeBytes; int index = 0; while (size >= 1024 && index < suffixes.Length - 1) { size /= 1024; index++; } return $"{size:0.##} {suffixes[index]}"; } }