180 lines
4.7 KiB
C#
180 lines
4.7 KiB
C#
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace ModpackUpdater.Apps.Manager.Ui.Models;
|
|
|
|
public class InstallActionViewModel(InstallAction action, IActionSet baseActions) : INotifyPropertyChanged
|
|
{
|
|
#region Implementation of INotifyPropertyChanged
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
#endregion Implementation of INotifyPropertyChanged
|
|
|
|
public static Dictionary<SourceType, string> SourceTypes { get; } = Enum.GetValues<SourceType>().ToDictionary(n => n, n => Enum.GetName(n)!);
|
|
public static Dictionary<Side, string> Sides { get; } = Enum.GetValues<Side>().ToDictionary(n => n, n => Enum.GetName(n)!);
|
|
public static Dictionary<UpdateActionType, string> UpdateActionTypes { get; } = Enum.GetValues<UpdateActionType>().ToDictionary(n => n, n => 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 string InheritedId => action is UpdateAction ua && !string.IsNullOrWhiteSpace(ua.InheritFrom) ? ua.InheritFrom : action.Id;
|
|
public string InheritedSide => Sides[Inherited.Side];
|
|
public string InheritedUpdateType => action is UpdateAction ua ? UpdateActionTypes[ua.Type] : string.Empty;
|
|
public string InheritedSourceType => SourceTypes[Inherited.SourceType];
|
|
public string InheritedDestPath => Inherited.DestPath;
|
|
|
|
public string Id
|
|
{
|
|
get => action.Id;
|
|
set
|
|
{
|
|
action.Id = value;
|
|
OnPropertyChanged();
|
|
OnPropertyChanged(nameof(InheritedId));
|
|
}
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get => action.Name;
|
|
set => action.Name = value;
|
|
}
|
|
|
|
public string Website
|
|
{
|
|
get => action.Website;
|
|
set => action.Website = value;
|
|
}
|
|
|
|
public bool IsZip
|
|
{
|
|
get => action.IsZip;
|
|
set => action.IsZip = value;
|
|
}
|
|
|
|
public string ZipPath
|
|
{
|
|
get => action.ZipPath;
|
|
set => action.ZipPath = value;
|
|
}
|
|
|
|
public string DestPath
|
|
{
|
|
get => action.DestPath;
|
|
set
|
|
{
|
|
action.DestPath = value;
|
|
OnPropertyChanged();
|
|
OnPropertyChanged(nameof(InheritedDestPath));
|
|
}
|
|
}
|
|
|
|
public string SourceUrl
|
|
{
|
|
get => action.SourceUrl;
|
|
set => action.SourceUrl = value;
|
|
}
|
|
|
|
public SourceType SourceType
|
|
{
|
|
get => action.SourceType;
|
|
set
|
|
{
|
|
action.SourceType = value;
|
|
OnPropertyChanged();
|
|
OnPropertyChanged(nameof(InheritedSourceType));
|
|
}
|
|
}
|
|
|
|
public string SourceOwner
|
|
{
|
|
get => action.SourceOwner;
|
|
set => action.SourceOwner = value;
|
|
}
|
|
|
|
public string SourceName
|
|
{
|
|
get => action.SourceName;
|
|
set => action.SourceName = value;
|
|
}
|
|
|
|
public string SourceRegex
|
|
{
|
|
get => action.SourceRegex;
|
|
set => action.SourceRegex = value;
|
|
}
|
|
|
|
public string SourceTag
|
|
{
|
|
get => action.SourceTag;
|
|
set => action.SourceTag = value;
|
|
}
|
|
|
|
public Side Side
|
|
{
|
|
get => action.Side;
|
|
set
|
|
{
|
|
action.Side = value;
|
|
OnPropertyChanged();
|
|
OnPropertyChanged(nameof(InheritedSide));
|
|
}
|
|
}
|
|
|
|
public bool IsExtra
|
|
{
|
|
get => action.IsExtra;
|
|
set => action.IsExtra = value;
|
|
}
|
|
|
|
public UpdateActionType Type
|
|
{
|
|
get => action is UpdateAction ua ? ua.Type : default;
|
|
set
|
|
{
|
|
if (action is UpdateAction ua)
|
|
ua.Type = value;
|
|
}
|
|
}
|
|
|
|
public string SrcPath
|
|
{
|
|
get => action is UpdateAction ua ? ua.SrcPath : string.Empty;
|
|
set
|
|
{
|
|
if (action is UpdateAction ua)
|
|
ua.SrcPath = value;
|
|
}
|
|
}
|
|
|
|
public bool IsDirectory
|
|
{
|
|
get => action is UpdateAction ua && ua.IsDirectory;
|
|
set
|
|
{
|
|
if (action is UpdateAction ua)
|
|
ua.IsDirectory = value;
|
|
}
|
|
}
|
|
|
|
public string InheritFrom
|
|
{
|
|
get => action is UpdateAction ua ? ua.InheritFrom : string.Empty;
|
|
set
|
|
{
|
|
if (action is UpdateAction ua)
|
|
ua.InheritFrom = value;
|
|
OnPropertyChanged();
|
|
OnPropertyChanged(nameof(InheritedId));
|
|
}
|
|
}
|
|
} |