Merge pull request #718 from erri120/issue-686

Version field
This commit is contained in:
Timothy Baldridge 2020-04-16 17:07:43 -06:00 committed by GitHub
commit 166b3256e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 57 additions and 63 deletions

View File

@ -1,7 +1,6 @@
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Alphaleonis.Win32.Filesystem;
using CommandLine;
@ -38,7 +37,7 @@ namespace Wabbajack.CLI.Verbs
protected override async Task<ExitCode> Run()
{
var orignalPath = (AbsolutePath)Original;
var originalPath = (AbsolutePath)Original;
var updatePath = (AbsolutePath)Update;
if (Original == null)
return ExitCode.BadArguments;
@ -49,7 +48,7 @@ namespace Wabbajack.CLI.Verbs
try
{
original = AInstaller.LoadFromFile(orignalPath);
original = AInstaller.LoadFromFile(originalPath);
}
catch (Exception e)
{
@ -74,22 +73,8 @@ namespace Wabbajack.CLI.Verbs
var downloadSizeChanges = original.DownloadSize - update.DownloadSize;
var installSizeChanges = original.InstallSize - update.InstallSize;
var versionRegex = new Regex(@"\s([0-9](\.|\s)?){1,4}");
var matchOriginal = versionRegex.Match(original.Name);
var matchUpdated = versionRegex.Match(update.Name);
if (!matchOriginal.Success || !matchUpdated.Success)
{
return CLIUtils.Exit(
!matchOriginal.Success
? "The name of the original modlist did not match the version check regex!"
: "The name of the updated modlist did not match the version check regex!", ExitCode.Error);
}
var version = matchUpdated.Value.Trim();
var mdText =
$"## {version}\n\n" +
$"## {update.Version}\n\n" +
$"**Build at:** `{File.GetCreationTime(Update)}`\n\n" +
"**Info**:\n\n" +
$"- Download Size change: {downloadSizeChanges.ToFileSizeString()} (Total: {update.DownloadSize.ToFileSizeString()})\n" +
@ -153,20 +138,20 @@ namespace Wabbajack.CLI.Verbs
if (IncludeLoadOrderChanges)
{
var loadorder_txt = (RelativePath)"loadorder.txt";
var loadorderTxt = (RelativePath)"loadorder.txt";
var originalLoadOrderFile = original.Directives
.Where(d => d is InlineFile)
.Where(d => d.To.FileName == loadorder_txt)
.Where(d => d.To.FileName == loadorderTxt)
.Cast<InlineFile>()
.First();
var updatedLoadOrderFile = update.Directives
.Where(d => d is InlineFile)
.Where(d => d.To.FileName == loadorder_txt)
.Where(d => d.To.FileName == loadorderTxt)
.Cast<InlineFile>()
.First();
var originalLoadOrder = GetTextFileFromModlist(orignalPath, original, originalLoadOrderFile.SourceDataID).Result.Split("\n");
var originalLoadOrder = GetTextFileFromModlist(originalPath, original, originalLoadOrderFile.SourceDataID).Result.Split("\n");
var updatedLoadOrder = GetTextFileFromModlist(updatePath, update, updatedLoadOrderFile.SourceDataID).Result.Split("\n");
var addedPlugins = updatedLoadOrder
@ -208,7 +193,7 @@ namespace Wabbajack.CLI.Verbs
.Cast<InlineFile>()
.First();
var originalModlist = GetTextFileFromModlist(orignalPath, original, originalModlistFile.SourceDataID).Result.Split("\n");
var originalModlist = GetTextFileFromModlist(originalPath, original, originalModlistFile.SourceDataID).Result.Split("\n");
var updatedModlist = GetTextFileFromModlist(updatePath, update, updatedModlistFile.SourceDataID).Result.Split("\n");
var removedMods = originalModlist
@ -294,7 +279,7 @@ namespace Wabbajack.CLI.Verbs
if (hasToc)
{
markdown.Insert(tocLine, $"- [{version}](#{ToTocLink(version)})");
markdown.Insert(tocLine, $"- [{update.Version}](#{ToTocLink(update.Version.ToString())})");
line++;
}
@ -307,7 +292,7 @@ namespace Wabbajack.CLI.Verbs
}
var text = "# Changelog\n\n" +
$"- [{version}](#{ToTocLink(version)})\n\n" +
$"- [{update.Version}](#{ToTocLink(update.Version.ToString())})\n\n" +
$"{mdText}";
File.WriteAllText(output, text);

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using Alphaleonis.Win32.Filesystem;
using Wabbajack.Common.IO;

View File

@ -16,6 +16,7 @@ namespace Wabbajack.Lib
public abstract class ACompiler : ABatchProcessor
{
public string? ModListName, ModListAuthor, ModListDescription, ModListWebsite, ModlistReadme;
public Version? ModlistVersion;
public AbsolutePath ModListImage;
protected Version? WabbajackVersion;

View File

@ -95,6 +95,11 @@ namespace Wabbajack.Lib
/// </summary>
public Uri? Website;
/// <summary>
/// Current Version of the Modlist
/// </summary>
public Version Version = new Version(1, 0, 0, 0);
/// <summary>
/// The size of all the archives once they're downloaded
/// </summary>

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Wabbajack.Common;
using Wabbajack.Common.Serialization.Json;
@ -9,6 +10,7 @@ namespace Wabbajack.Lib
public class Manifest
{
public string Name;
public Version Version;
public string Author;
public string Description;
@ -28,6 +30,7 @@ namespace Wabbajack.Lib
public Manifest(ModList modlist)
{
Name = modlist.Name;
Version = modlist.Version;
Author = modlist.Author;
Description = modlist.Description;

View File

@ -119,6 +119,7 @@ namespace Wabbajack
public class CompilationModlistSettings
{
public string ModListName { get; set; }
public string Version { get; set; }
public string Author { get; set; }
public string Description { get; set; }
public string Website { get; set; }

View File

@ -188,6 +188,7 @@ namespace Wabbajack
ModListWebsite = ModlistSettings.Website,
ModlistReadme = ModlistSettings.Readme,
MO2DownloadsFolder = DownloadLocation.TargetPath,
ModlistVersion = ModlistSettings.Version
})
{
Parent.MWVM.Settings.Performance.AttachToBatchProcessor(ActiveCompilation);

View File

@ -5,6 +5,7 @@ using DynamicData;
using Microsoft.WindowsAPICodePack.Dialogs;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Common;
using Wabbajack.Lib;
namespace Wabbajack
@ -16,6 +17,12 @@ namespace Wabbajack
[Reactive]
public string ModListName { get; set; }
[Reactive]
public string VersionText { get; set; }
private ObservableAsPropertyHelper<Version> _version;
public Version Version => _version.Value;
[Reactive]
public string AuthorText { get; set; }
@ -35,15 +42,29 @@ namespace Wabbajack
public ModlistSettingsEditorVM(CompilationModlistSettings settings)
{
_settings = settings;
ImagePath = new FilePickerVM()
ImagePath = new FilePickerVM
{
ExistCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty,
PathType = FilePickerVM.PathTypeOptions.File,
};
ImagePath.Filters.Add(new CommonFileDialogFilter("Banner image", "*.png"));
_version = this.WhenAny(x => x.VersionText)
.Select(x =>
{
if (string.IsNullOrWhiteSpace(x))
return new Version(0, 0);
return !Version.TryParse(x, out var version) ? new Version(0, 0) : version;
}).ObserveOnGuiThread()
.ToProperty(this, x => x.Version);
InError = this.WhenAny(x => x.ImagePath.ErrorState)
.Select(err => err.Failed)
.CombineLatest(
this.WhenAny(x => x.VersionText)
.Select(x => Version.TryParse(x, out _)),
(image, version) => !image && !version)
.Publish()
.RefCount();
}
@ -59,10 +80,12 @@ namespace Wabbajack
Readme = _settings.Readme;
ImagePath.TargetPath = _settings.SplashScreen;
Website = _settings.Website;
VersionText = _settings.Version;
}
public void Save()
{
_settings.Version = VersionText;
_settings.Author = AuthorText;
_settings.ModListName = ModListName;
_settings.Description = Description;

View File

@ -21,6 +21,7 @@ namespace Wabbajack
public string Description => SourceModList?.Description;
public Uri Website => SourceModList?.Website;
public ModManager ModManager => SourceModList?.ModManager ?? ModManager.MO2;
public Version Version => SourceModList?.Version;
// Image isn't exposed as a direct property, but as an observable.
// This acts as a caching mechanism, as interested parties will trigger it to be created,

View File

@ -121,6 +121,8 @@
</StackPanel.Resources>
<TextBlock Margin="{StaticResource TitleMargin}" Text="ModList Name" />
<TextBox x:Name="ModListNameSetting" Style="{StaticResource ValueStyle}" />
<TextBlock Margin="{StaticResource TitleMargin}" Text="Version" />
<TextBox x:Name="VersionSetting" Style="{StaticResource ValueStyle}" MaxLength="9" />
<TextBlock Margin="{StaticResource TitleMargin}" Text="Author" />
<TextBox x:Name="AuthorNameSetting" Style="{StaticResource ValueStyle}" />
<TextBlock Margin="{StaticResource TitleMargin}" Text="Description" />

View File

@ -63,6 +63,8 @@ namespace Wabbajack
.DisposeWith(dispose);
this.BindStrict(this.ViewModel, x => x.CurrentModlistSettings.ModListName, x => x.ModListNameSetting.Text)
.DisposeWith(dispose);
this.BindStrict(ViewModel, x => x.CurrentModlistSettings.VersionText, x => x.VersionSetting.Text)
.DisposeWith(dispose);
this.BindStrict(this.ViewModel, x => x.CurrentModlistSettings.AuthorText, x => x.AuthorNameSetting.Text)
.DisposeWith(dispose);
this.BindStrict(this.ViewModel, x => x.CurrentModlistSettings.Description, x => x.DescriptionSetting.Text)

View File

@ -24,7 +24,8 @@
</ScrollViewer.Resources>
<StackPanel Margin="8" x:Name="DynamicStackPanel">
<TextBlock x:Name="Name" FontSize="32" HorizontalAlignment="Center" Style="{StaticResource HeaderStyle}"/>
<TextBlock x:Name="Author" FontSize="14" Padding="0 12 0 3"/>
<TextBlock x:Name="Version" FontSize="14" Padding="0 12 0 3"/>
<TextBlock x:Name="Author" FontSize="14" Padding="0 3 0 3"/>
<TextBlock x:Name="Description" FontSize="18" TextWrapping="Wrap"/>
<TextBlock x:Name="InstallSize" Padding="0 24 0 0" FontSize="24"/>

View File

@ -20,8 +20,7 @@ namespace Wabbajack
Modlist = modlist;
var manifest = new Manifest(modlist);
if(ViewModel == null)
ViewModel = new ManifestVM(manifest);
ViewModel ??= new ManifestVM(manifest);
InitializeComponent();
@ -29,6 +28,8 @@ namespace Wabbajack
{
this.OneWayBind(ViewModel, x => x.Name, x => x.Name.Text)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.Manifest.Version, x => x.Version.Text)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.Author, x => x.Author.Text)
.DisposeWith(disposable);
this.OneWayBind(ViewModel, x => x.Description, x => x.Description.Text)

View File

@ -1,21 +0,0 @@
<mah:MetroWindow
x:Class="Wabbajack.TextViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Wabbajack"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
Title="TextViewer"
Width="800"
Height="450"
WindowTitleBrush="{StaticResource MahApps.Brushes.Accent}"
Style="{StaticResource {x:Type Window}}"
mc:Ignorable="d">
<Grid>
<TextBlock
Name="TextBlock"
FontSize="20"
TextWrapping="Wrap" />
</Grid>
</mah:MetroWindow>

View File

@ -1,12 +0,0 @@
namespace Wabbajack
{
public partial class TextViewer
{
public TextViewer(string text, string title)
{
InitializeComponent();
TextBlock.Text = text;
Title = title;
}
}
}