63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using Mlaumcherb.Client.Avalonia.холопы;
|
||
|
||
namespace Mlaumcherb.Client.Avalonia.классы;
|
||
|
||
public class GameVersionProps : IComparable<GameVersionProps>, IEquatable<GameVersionProps>
|
||
{
|
||
public string Name { get; }
|
||
public IOPath LocalDescriptorPath { get; }
|
||
public string? RemoteDescriptorUrl { get; }
|
||
private bool _isDownloaded;
|
||
public bool IsDownloaded
|
||
{
|
||
get => _isDownloaded;
|
||
set
|
||
{
|
||
bool downloadCompleted = value && !_isDownloaded;
|
||
_isDownloaded = value;
|
||
if(downloadCompleted)
|
||
OnDownloadCompleted?.Invoke();
|
||
}
|
||
}
|
||
public event Action? OnDownloadCompleted;
|
||
|
||
public GameVersionProps(string name, string? url)
|
||
{
|
||
Name = name;
|
||
LocalDescriptorPath = PathHelper.GetVersionDescriptorPath(name);
|
||
RemoteDescriptorUrl = url;
|
||
IsDownloaded = File.Exists(PathHelper.GetVersionJarFilePath(name));
|
||
}
|
||
|
||
public override string ToString() => Name;
|
||
|
||
public override int GetHashCode() => Name.GetHashCode();
|
||
|
||
public int CompareTo(GameVersionProps? other)
|
||
{
|
||
if (ReferenceEquals(this, other)) return 0;
|
||
if (other is null) return 1;
|
||
|
||
if (Version.TryParse(Name, out var version1) && Version.TryParse(other.Name, out var version2))
|
||
{
|
||
return version1.CompareTo(version2);
|
||
}
|
||
|
||
return String.Compare(Name, other.Name, StringComparison.InvariantCulture);
|
||
}
|
||
|
||
public bool Equals(GameVersionProps? other)
|
||
{
|
||
if (other is null) return false;
|
||
if (ReferenceEquals(this, other)) return true;
|
||
return Name == other.Name;
|
||
}
|
||
|
||
public override bool Equals(object? obj)
|
||
{
|
||
if (obj is GameVersionProps other) return Equals(other);
|
||
if (ReferenceEquals(this, obj)) return true;
|
||
return false;
|
||
}
|
||
}
|