using Mlaumcherb.Client.Avalonia.зримое; using Mlaumcherb.Client.Avalonia.холопы; namespace Mlaumcherb.Client.Avalonia.классы; public class GameVersionProps : IComparable, IEquatable { public string Name { get; } public IOPath LocalDescriptorPath { get; } public RemoteVersionDescriptorProps? RemoteProps { get; } private bool _isDownloaded; public bool IsDownloaded { get => _isDownloaded; set { if(_isDownloaded != value) { _isDownloaded = value; StatusChanged?.Invoke(value); } } } public event Action? StatusChanged; private GameVersionProps(string name, RemoteVersionDescriptorProps? remoteProps) { Name = name; RemoteProps = remoteProps; LocalDescriptorPath = PathHelper.GetVersionDescriptorPath(name); IsDownloaded = File.Exists(PathHelper.GetVersionJarFilePath(name)); } public GameVersionProps(string name) : this(name, null) { } public GameVersionProps(RemoteVersionDescriptorProps remoteProps) : this(remoteProps.id, remoteProps) { } public void DeleteFiles() { IsDownloaded = false; LauncherApp.Logger.LogInfo(Name, "Deleting files..."); var verdir = PathHelper.GetVersionDir(Name); if(Directory.Exists(verdir)) Directory.Delete(verdir); LauncherApp.Logger.LogInfo(Name, "Files deleted"); } 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; } }