Add Windows desktop version
This commit is contained in:
52
windows/StreamPlayer.Desktop/Models/UpdateInfo.cs
Normal file
52
windows/StreamPlayer.Desktop/Models/UpdateInfo.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
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]}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user