Files
minecraft-modpack-updater/ModpackUpdater.Apps.Manager/Ui/Models/MainWindow/MainWindowGridRow.cs
2025-11-19 07:30:56 +01:00

165 lines
4.7 KiB
C#

using System.ComponentModel;
using Avalonia.Media;
using ModpackUpdater.Apps.Manager.LangRes;
using ModpackUpdater.Apps.Manager.Utils;
using PropertyChanged;
namespace ModpackUpdater.Apps.Manager.Ui.Models.MainWindow;
public class MainWindowGridRow(InstallAction action, IActionSet baseActions) : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
public static Dictionary<SourceType, string> SourceTypes { get; } = Enum.GetValues<SourceType>().ToDictionary(n => n, n => SourceTypeLangRes.ResourceManager.GetString( Enum.GetName(n)!)!);
public static Dictionary<Side, string> Sides { get; } = Enum.GetValues<Side>().ToDictionary(n => n, n => SideLangRes.ResourceManager.GetString(Enum.GetName(n)!)!);
public static Dictionary<UpdateActionType, string> UpdateActionTypes { get; } = Enum.GetValues<UpdateActionType>().ToDictionary(n => n, n => UpdateActionTypeLangRes.ResourceManager.GetString(Enum.GetName(n)!)!);
public InstallAction Action => action;
private InstallAction? Base => action is UpdateAction ua ? baseActions.Actions.FirstOrDefault(n => n.Id == ua.InheritFrom) : null;
private InstallAction Inherited => Base ?? action;
public bool IsUpdate => action is UpdateAction;
public IImage? StateImage { get; set; }
[DependsOn(nameof(Id), nameof(InheritFrom))]
public string? InheritedId => action is UpdateAction ua && !string.IsNullOrWhiteSpace(ua.InheritFrom) ? ua.InheritFrom : action.Id;
[DependsOn(nameof(Side), nameof(InheritedId), nameof(Id))]
public string InheritedSide => Sides[Inherited.Side];
[DependsOn(nameof(UpdateType), nameof(InheritedId), nameof(Id))]
public string InheritedUpdateType => action is UpdateAction ua ? UpdateActionTypes[ua.Type] : string.Empty;
[DependsOn(nameof(SourceType), nameof(InheritedId), nameof(Id))]
public string InheritedSourceType => SourceTypes[Inherited.SourceType];
[DependsOn(nameof(DestPath), nameof(InheritedId), nameof(Id))]
public string? InheritedDestPath => Inherited.DestPath;
[DependsOn(nameof(Name), nameof(InheritedId), nameof(Id))]
public string? InheritedName => Inherited.Name;
public string? Id
{
get => action.Id;
set => action.Id = value?.Trim().Nullify();
}
public string? Name
{
get => action.Name;
set => action.Name = value?.Trim().Nullify();
}
public string? Website
{
get => action.Website;
set => action.Website = value?.Trim().Nullify();
}
public bool IsZip
{
get => action.IsZip;
set => action.IsZip = value;
}
public string? ZipPath
{
get => action.ZipPath;
set => action.ZipPath = value?.Trim().Nullify();
}
public string? DestPath
{
get => action.DestPath;
set => action.DestPath = value?.Trim().Nullify();
}
public string? SourceUrl
{
get => action.SourceUrl;
set => action.SourceUrl = value?.Trim().Nullify();
}
public SourceType SourceType
{
get => action.SourceType;
set => action.SourceType = value;
}
public string? SourceOwner
{
get => action.SourceOwner;
set => action.SourceOwner = value?.Trim().Nullify();
}
public string? SourceName
{
get => action.SourceName;
set => action.SourceName = value?.Trim().Nullify();
}
public string? SourceRegex
{
get => action.SourceRegex;
set => action.SourceRegex = value?.Trim().Nullify();
}
public string? SourceTag
{
get => action.SourceTag;
set => action.SourceTag = value?.Trim().Nullify();
}
public Side Side
{
get => action.Side;
set => action.Side = value;
}
public bool IsExtra
{
get => action.IsExtra;
set => action.IsExtra = value;
}
public UpdateActionType UpdateType
{
get => action is UpdateAction ua ? ua.Type : default;
set
{
if (action is UpdateAction ua)
ua.Type = value;
}
}
public string? SrcPath
{
get => (action as UpdateAction)?.SrcPath;
set
{
if (action is UpdateAction ua)
ua.SrcPath = value?.Trim().Nullify();
}
}
public bool IsDirectory
{
get => action is UpdateAction ua && ua.IsDirectory;
set
{
if (action is UpdateAction ua)
ua.IsDirectory = value;
}
}
public string? InheritFrom
{
get => (action as UpdateAction)?.InheritFrom;
set
{
if (action is UpdateAction ua)
ua.InheritFrom = value?.Trim().Nullify();
}
}
}