Replaced VersionRegex with Version.TryParse

This commit is contained in:
erri120 2020-04-16 17:31:12 +02:00
parent 50613fa438
commit 8aa8013725
No known key found for this signature in database
GPG Key ID: A8C0A18D8D4D3135
4 changed files with 16 additions and 10 deletions

View File

@ -139,7 +139,5 @@ namespace Wabbajack.Common
public static RelativePath ModOrganizer2Exe = (RelativePath)"ModOrganizer.exe";
public static RelativePath ModOrganizer2Ini = (RelativePath)"ModOrganizer.ini";
public static string AuthorAPIKeyFile = "author-api-key.txt";
public static Regex VersionRegex = new Regex(@"^(\d{1,3}\.?){1,3}[^\.]$");
}
}

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

@ -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

@ -20,6 +20,9 @@ namespace Wabbajack
[Reactive]
public string VersionText { get; set; }
private ObservableAsPropertyHelper<Version> _version;
public Version Version => _version.Value;
[Reactive]
public string AuthorText { get; set; }
@ -46,18 +49,21 @@ namespace Wabbajack
};
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 =>
{
if (string.IsNullOrWhiteSpace(x))
return false;
var match = Consts.VersionRegex.Match(x);
return match.Success;
}),
.Select(x => Version.TryParse(x, out _)),
(image, version) => !image && !version)
.Publish()
.RefCount();