a lot of work
This commit is contained in:
232
ModpackUpdater.Apps.Manager/Ui/Models/MainWindowGridRow.cs
Normal file
232
ModpackUpdater.Apps.Manager/Ui/Models/MainWindowGridRow.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
using System.ComponentModel;
|
||||
using ModpackUpdater.Apps.Manager.Utils;
|
||||
using PropertyChanged;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Ui.Models;
|
||||
|
||||
public class MainWindowGridRow : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
private string? actionId;
|
||||
private string? actionName;
|
||||
private string? actionWebsite;
|
||||
private string? actionZipPath;
|
||||
private string? actionDestPath;
|
||||
private string? actionSourceUrl;
|
||||
private string? actionSourceOwner;
|
||||
private string? actionSourceName;
|
||||
private string? actionSourceRegEx;
|
||||
private string? actionSourceTag;
|
||||
private string? actionSrcPath;
|
||||
private string? actionInheritFrom;
|
||||
private readonly InstallAction action;
|
||||
private readonly IActionSet baseActions;
|
||||
|
||||
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 == actionInheritFrom) : null;
|
||||
private InstallAction Inherited => Base ?? action;
|
||||
|
||||
public bool IsUpdate => action is UpdateAction;
|
||||
public bool? IsValid { get; set; } = null;
|
||||
|
||||
[DependsOn(nameof(Id), nameof(InheritFrom))]
|
||||
public string? InheritedId => action is UpdateAction ua && !string.IsNullOrWhiteSpace(actionInheritFrom) ? actionInheritFrom : actionId;
|
||||
[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 => Base != null ? Base.DestPath : actionDestPath;
|
||||
|
||||
public MainWindowGridRow(InstallAction action, IActionSet baseActions)
|
||||
{
|
||||
this.action = action;
|
||||
this.baseActions = baseActions;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
public void Invalidate()
|
||||
{
|
||||
actionId = action.Id;
|
||||
actionName = action.Name;
|
||||
actionWebsite = action.Website;
|
||||
actionZipPath = action.ZipPath;
|
||||
actionDestPath = action.DestPath;
|
||||
actionSourceUrl = action.SourceUrl;
|
||||
actionSourceOwner = action.SourceOwner;
|
||||
actionSourceName = action.SourceName;
|
||||
actionSourceRegEx = action.SourceRegex;
|
||||
actionSourceTag = action.SourceTag;
|
||||
actionSrcPath = (action as UpdateAction)?.SrcPath;
|
||||
actionInheritFrom = (action as UpdateAction)?.InheritFrom;
|
||||
}
|
||||
|
||||
public string? Id
|
||||
{
|
||||
get => action.Id;
|
||||
set => action.Id = (actionId = value)?.Trim().Nullify();
|
||||
}
|
||||
|
||||
public string? Name
|
||||
{
|
||||
get => actionName;
|
||||
set
|
||||
{
|
||||
actionName = value;
|
||||
action.Name = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public string? Website
|
||||
{
|
||||
get => actionWebsite;
|
||||
set
|
||||
{
|
||||
actionWebsite = value;
|
||||
action.Website = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsZip
|
||||
{
|
||||
get => action.IsZip;
|
||||
set => action.IsZip = value;
|
||||
}
|
||||
|
||||
public string? ZipPath
|
||||
{
|
||||
get => actionZipPath;
|
||||
set
|
||||
{
|
||||
actionZipPath = value;
|
||||
action.ZipPath = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public string? DestPath
|
||||
{
|
||||
get => actionDestPath;
|
||||
set
|
||||
{
|
||||
actionDestPath = value;
|
||||
action.DestPath = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public string? SourceUrl
|
||||
{
|
||||
get => actionSourceUrl;
|
||||
set
|
||||
{
|
||||
actionSourceUrl = value;
|
||||
action.SourceUrl = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public SourceType SourceType
|
||||
{
|
||||
get => action.SourceType;
|
||||
set => action.SourceType = value;
|
||||
}
|
||||
|
||||
public string? SourceOwner
|
||||
{
|
||||
get => actionSourceOwner;
|
||||
set
|
||||
{
|
||||
actionSourceOwner = value;
|
||||
action.SourceOwner = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public string? SourceName
|
||||
{
|
||||
get => actionSourceName;
|
||||
set
|
||||
{
|
||||
actionSourceName = value;
|
||||
action.SourceName = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public string? SourceRegex
|
||||
{
|
||||
get => actionSourceRegEx;
|
||||
set
|
||||
{
|
||||
actionSourceRegEx = value;
|
||||
action.SourceRegex = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
|
||||
public string? SourceTag
|
||||
{
|
||||
get => actionSourceTag;
|
||||
set
|
||||
{
|
||||
actionSourceTag = value;
|
||||
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 => actionSrcPath;
|
||||
set
|
||||
{
|
||||
actionSrcPath = value;
|
||||
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 => actionInheritFrom;
|
||||
set
|
||||
{
|
||||
actionInheritFrom = value;
|
||||
if (action is UpdateAction ua)
|
||||
ua.InheritFrom = value?.Trim().Nullify();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user