Removed readme as file option

This commit is contained in:
erri120 2020-04-15 19:40:41 +02:00
parent f8321f273a
commit a3305b08fe
No known key found for this signature in database
GPG Key ID: A8C0A18D8D4D3135
13 changed files with 24 additions and 202 deletions

View File

@ -9,19 +9,14 @@ using Wabbajack.Common;
using Wabbajack.Lib.CompilationSteps; using Wabbajack.Lib.CompilationSteps;
using Wabbajack.Lib.Downloaders; using Wabbajack.Lib.Downloaders;
using Wabbajack.Lib.ModListRegistry; using Wabbajack.Lib.ModListRegistry;
using Wabbajack.Lib.Validation;
using Wabbajack.VirtualFileSystem; using Wabbajack.VirtualFileSystem;
using Directory = Alphaleonis.Win32.Filesystem.Directory;
using File = Alphaleonis.Win32.Filesystem.File;
using Path = Alphaleonis.Win32.Filesystem.Path;
namespace Wabbajack.Lib namespace Wabbajack.Lib
{ {
public abstract class ACompiler : ABatchProcessor public abstract class ACompiler : ABatchProcessor
{ {
public string? ModListName, ModListAuthor, ModListDescription, ModListWebsite; public string? ModListName, ModListAuthor, ModListDescription, ModListWebsite, ModlistReadme;
public AbsolutePath ModListImage, ModListReadme; public AbsolutePath ModListImage;
public bool ReadmeIsWebsite;
protected Version? WabbajackVersion; protected Version? WabbajackVersion;
public abstract AbsolutePath VFSCacheName { get; } public abstract AbsolutePath VFSCacheName { get; }
@ -136,12 +131,6 @@ namespace Wabbajack.Lib
{ {
ModList.Image = (RelativePath)"modlist-image.png"; ModList.Image = (RelativePath)"modlist-image.png";
} }
if (ModListReadme.Exists)
{
ModList.Readme = $"readme{ModListReadme.Extension}";
}
ModList.ReadmeIsWebsite = ReadmeIsWebsite;
using (var of = ModListOutputFolder.Combine("modlist").Create()) using (var of = ModListOutputFolder.Combine("modlist").Create())
ModList.ToJson(of); ModList.ToJson(of);
@ -172,17 +161,6 @@ namespace Wabbajack.Lib
ins.CopyTo(os); ins.CopyTo(os);
} }
} }
// Copy in readme
if (ModListReadme.Exists)
{
var ze = za.CreateEntry(ModList.Readme);
using (var os = ze.Open())
using (var ins = ModListReadme.OpenRead())
{
ins.CopyTo(os);
}
}
} }
} }

View File

@ -18,7 +18,7 @@ namespace Wabbajack.Lib.CompilationSteps
{ {
var files = new HashSet<AbsolutePath> var files = new HashSet<AbsolutePath>
{ {
_compiler.ModListImage, _compiler.ModListReadme _compiler.ModListImage
}; };
if (!files.Any(f => source.AbsolutePath.Equals(f))) return null; if (!files.Any(f => source.AbsolutePath.Equals(f))) return null;
if (!source.AbsolutePath.Exists) return null; if (!source.AbsolutePath.Exists) return null;
@ -31,11 +31,6 @@ namespace Wabbajack.Lib.CompilationSteps
result.Type = PropertyType.Banner; result.Type = PropertyType.Banner;
_compiler.ModListImage = result.SourceDataID.RelativeTo(_compiler.ModListOutputFolder); _compiler.ModListImage = result.SourceDataID.RelativeTo(_compiler.ModListOutputFolder);
} }
else
{
result.Type = PropertyType.Readme;
_compiler.ModListReadme = result.SourceDataID.RelativeTo(_compiler.ModListOutputFolder);
}
return result; return result;
} }

View File

@ -81,15 +81,10 @@ namespace Wabbajack.Lib
public string Name = string.Empty; public string Name = string.Empty;
/// <summary> /// <summary>
/// readme path or website /// URL to the readme
/// </summary> /// </summary>
public string Readme = string.Empty; public string Readme = string.Empty;
/// <summary>
/// Whether readme is a website
/// </summary>
public bool ReadmeIsWebsite;
/// <summary> /// <summary>
/// The build version of Wabbajack used when compiling the Modlist /// The build version of Wabbajack used when compiling the Modlist
/// </summary> /// </summary>

View File

@ -301,7 +301,7 @@ namespace Wabbajack.Lib
Name = ModListName ?? MO2Profile, Name = ModListName ?? MO2Profile,
Author = ModListAuthor ?? "", Author = ModListAuthor ?? "",
Description = ModListDescription ?? "", Description = ModListDescription ?? "",
Readme = (string)ModListReadme, Readme = ModlistReadme ?? "",
Image = ModListImage != default ? ModListImage.FileName : default, Image = ModListImage != default ? ModListImage.FileName : default,
Website = ModListWebsite != null ? new Uri(ModListWebsite) : null Website = ModListWebsite != null ? new Uri(ModListWebsite) : null
}; };

View File

@ -122,7 +122,6 @@ namespace Wabbajack
public string Author { get; set; } public string Author { get; set; }
public string Description { get; set; } public string Description { get; set; }
public string Website { get; set; } public string Website { get; set; }
public bool ReadmeIsWebsite { get; set; }
public string Readme { get; set; } public string Readme { get; set; }
public AbsolutePath SplashScreen { get; set; } public AbsolutePath SplashScreen { get; set; }
} }

View File

@ -186,8 +186,7 @@ namespace Wabbajack
ModListDescription = ModlistSettings.Description, ModListDescription = ModlistSettings.Description,
ModListImage = ModlistSettings.ImagePath.TargetPath, ModListImage = ModlistSettings.ImagePath.TargetPath,
ModListWebsite = ModlistSettings.Website, ModListWebsite = ModlistSettings.Website,
//ModListReadme = ModlistSettings.ReadmeIsWebsite ? ModlistSettings.ReadmeWebsite : ModlistSettings.ReadmeFilePath.TargetPath, ModlistReadme = ModlistSettings.Readme,
ReadmeIsWebsite = ModlistSettings.ReadmeIsWebsite,
MO2DownloadsFolder = DownloadLocation.TargetPath, MO2DownloadsFolder = DownloadLocation.TargetPath,
}) })
{ {

View File

@ -11,7 +11,7 @@ namespace Wabbajack
{ {
public class ModlistSettingsEditorVM : ViewModel public class ModlistSettingsEditorVM : ViewModel
{ {
private CompilationModlistSettings _settings; private readonly CompilationModlistSettings _settings;
[Reactive] [Reactive]
public string ModListName { get; set; } public string ModListName { get; set; }
@ -24,49 +24,28 @@ namespace Wabbajack
public FilePickerVM ImagePath { get; } public FilePickerVM ImagePath { get; }
public FilePickerVM ReadmeFilePath { get; }
[Reactive] [Reactive]
public string ReadmeWebsite { get; set; } public string Readme { get; set; }
[Reactive] [Reactive]
public string Website { get; set; } public string Website { get; set; }
[Reactive]
public bool ReadmeIsWebsite { get; set; }
public IObservable<bool> InError { get; } public IObservable<bool> InError { get; }
public ICommand SwapToTextReadmeCommand { get; }
public ICommand SwapToWebsiteReadmeCommand { get; }
public ModlistSettingsEditorVM(CompilationModlistSettings settings) public ModlistSettingsEditorVM(CompilationModlistSettings settings)
{ {
this._settings = settings; _settings = settings;
ImagePath = new FilePickerVM() ImagePath = new FilePickerVM()
{ {
ExistCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty, ExistCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty,
PathType = FilePickerVM.PathTypeOptions.File, PathType = FilePickerVM.PathTypeOptions.File,
}; };
ImagePath.Filters.Add(new CommonFileDialogFilter("Banner image", "*.png")); ImagePath.Filters.Add(new CommonFileDialogFilter("Banner image", "*.png"));
ReadmeFilePath = new FilePickerVM()
{
PathType = FilePickerVM.PathTypeOptions.File,
ExistCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty,
};
ReadmeFilePath.Filters.Add(new CommonFileDialogFilter("Text", "*.txt"));
ReadmeFilePath.Filters.Add(new CommonFileDialogFilter("HTML File", "*.html"));
InError = Observable.CombineLatest( InError = this.WhenAny(x => x.ImagePath.ErrorState)
this.WhenAny(x => x.ImagePath.ErrorState).Select(err => err.Failed), .Select(err => err.Failed)
this.WhenAny(x => x.ReadmeFilePath.ErrorState).Select(err => err.Failed),
this.WhenAny(x => x.ReadmeIsWebsite),
resultSelector: (img, readme, isWebsite) => img || (readme && !isWebsite))
.Publish() .Publish()
.RefCount(); .RefCount();
SwapToTextReadmeCommand = ReactiveCommand.Create(() => ReadmeIsWebsite = false);
SwapToWebsiteReadmeCommand = ReactiveCommand.Create(() => ReadmeIsWebsite = true);
} }
public void Init() public void Init()
@ -77,17 +56,7 @@ namespace Wabbajack
ModListName = _settings.ModListName; ModListName = _settings.ModListName;
} }
Description = _settings.Description; Description = _settings.Description;
ReadmeIsWebsite = _settings.ReadmeIsWebsite; Readme = _settings.Readme;
if (ReadmeIsWebsite)
{
// TODO README
// ReadmeWebsite = _settings.Readme;
}
else
{
// TODO README
//ReadmeFilePath.TargetPath = _settings.Readme;
}
ImagePath.TargetPath = _settings.SplashScreen; ImagePath.TargetPath = _settings.SplashScreen;
Website = _settings.Website; Website = _settings.Website;
} }
@ -97,16 +66,7 @@ namespace Wabbajack
_settings.Author = AuthorText; _settings.Author = AuthorText;
_settings.ModListName = ModListName; _settings.ModListName = ModListName;
_settings.Description = Description; _settings.Description = Description;
_settings.ReadmeIsWebsite = ReadmeIsWebsite; _settings.Readme = Readme;
if (ReadmeIsWebsite)
{
_settings.Readme = ReadmeWebsite;
}
else
{
// TODO README
//_settings.Readme = ReadmeFilePath.TargetPath;
}
_settings.SplashScreen = ImagePath.TargetPath; _settings.SplashScreen = ImagePath.TargetPath;
_settings.Website = Website; _settings.Website = Website;
} }

View File

@ -199,7 +199,7 @@ namespace Wabbajack
ModListDescription = ModlistSettings.Description, ModListDescription = ModlistSettings.Description,
ModListImage = ModlistSettings.ImagePath.TargetPath, ModListImage = ModlistSettings.ImagePath.TargetPath,
ModListWebsite = ModlistSettings.Website, ModListWebsite = ModlistSettings.Website,
ModListReadme = ModlistSettings.ReadmeIsWebsite ? ModlistSettings.ReadmeWebsite : ModlistSettings.ReadmeFilePath.TargetPath, ModListReadme = ModlistSettings.ReadmeIsWebsite ? ModlistSettings.Readme : ModlistSettings.ReadmeFilePath.TargetPath,
ReadmeIsWebsite = ModlistSettings.ReadmeIsWebsite, ReadmeIsWebsite = ModlistSettings.ReadmeIsWebsite,
}) })
{ {

View File

@ -102,7 +102,7 @@ namespace Wabbajack
{ {
try try
{ {
modList.OpenReadmeWindow(); modList.OpenReadme();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -313,7 +313,7 @@ namespace Wabbajack
new ManifestWindow(ModList.SourceModList).Show(); new ManifestWindow(ModList.SourceModList).Show();
}); });
OpenReadmeCommand = ReactiveCommand.Create( OpenReadmeCommand = ReactiveCommand.Create(
execute: () => this.ModList?.OpenReadmeWindow(), execute: () => this.ModList?.OpenReadme(),
canExecute: this.WhenAny(x => x.ModList) canExecute: this.WhenAny(x => x.ModList)
.Select(modList => !string.IsNullOrEmpty(modList?.Readme)) .Select(modList => !string.IsNullOrEmpty(modList?.Readme))
.ObserveOnGuiThread()); .ObserveOnGuiThread());
@ -367,7 +367,7 @@ namespace Wabbajack
Completed = ErrorResponse.Create(success); Completed = ErrorResponse.Create(success);
try try
{ {
this.ModList?.OpenReadmeWindow(); this.ModList?.OpenReadme();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -1,6 +1,5 @@
using ReactiveUI; using ReactiveUI;
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Reactive; using System.Reactive;
@ -89,37 +88,10 @@ namespace Wabbajack
.RefCount(); .RefCount();
} }
public void OpenReadmeWindow() public void OpenReadme()
{ {
if (string.IsNullOrEmpty(Readme)) return; if (string.IsNullOrEmpty(Readme)) return;
if (SourceModList.ReadmeIsWebsite) Utils.OpenWebsite(new Uri(Readme));
{
Utils.OpenWebsite(new Uri(Readme));
}
else
{
using var fs = ModListPath.OpenShared();
using var ar = new ZipArchive(fs, ZipArchiveMode.Read);
using var ms = new MemoryStream();
var entry = ar.GetEntry(Readme);
if (entry == null)
{
Utils.Log($"Tried to open a non-existent readme: {Readme}");
return;
}
using (var e = entry.Open())
{
e.CopyTo(ms);
}
ms.Seek(0, SeekOrigin.Begin);
using var reader = new StreamReader(ms);
var viewer = new TextViewer(reader.ReadToEnd(), Name);
viewer.Show();
}
} }
public override void Dispose() public override void Dispose()
@ -127,7 +99,7 @@ namespace Wabbajack
base.Dispose(); base.Dispose();
// Just drop reference explicitly, as it's large, so it can be GCed // Just drop reference explicitly, as it's large, so it can be GCed
// Even if someone is holding a stale reference to the VM // Even if someone is holding a stale reference to the VM
this.SourceModList = null; SourceModList = null;
} }
} }
} }

View File

@ -107,7 +107,7 @@
x:Key="ValueStyle" x:Key="ValueStyle"
BasedOn="{StaticResource MainTextBoxStyle}" BasedOn="{StaticResource MainTextBoxStyle}"
TargetType="TextBox"> TargetType="TextBox">
<Setter Property="MaxLength" Value="50" /> <Setter Property="MaxLength" Value="150" />
<Setter Property="AcceptsTab" Value="False" /> <Setter Property="AcceptsTab" Value="False" />
<Setter Property="FontSize" Value="15" /> <Setter Property="FontSize" Value="15" />
<Setter Property="Margin" Value="0,0,0,6" /> <Setter Property="Margin" Value="0,0,0,6" />
@ -143,66 +143,8 @@
<TextBlock <TextBlock
Margin="{StaticResource TitleMargin}" Margin="{StaticResource TitleMargin}"
Text="Readme" Text="Readme"
ToolTip="Path to a readme file." /> ToolTip="Link to the Readme." />
<Grid Margin="0,0,0,6"> <TextBox x:Name="ReadmeSetting" Style="{StaticResource ValueStyle}"/>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<local:FilePicker
x:Name="ReadmeFilePickerSetting"
Grid.Column="0"
Height="27"
Margin="0,0,3,0"
VerticalAlignment="Center"
ToolTip="Path to a readme file." />
<TextBox
x:Name="ReadmeWebsiteSetting"
Grid.Column="0"
Height="27"
Margin="0,0,3,0"
VerticalAlignment="Center"
ToolTip="Readme website" />
<Button
x:Name="SwapToReadmeWebsiteButton"
Grid.Column="1"
Width="27"
ToolTip="Set readme to be a website">
<Button.Style>
<Style BasedOn="{StaticResource IconBareButtonStyle}" TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding CurrentModlistSettings.ReadmeIsWebsite}" Value="True">
<Setter Property="Foreground" Value="{StaticResource SecondaryBrush}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
<icon:PackIconMaterial
Width="20"
Height="20"
Kind="Web" />
</Button>
<Button
x:Name="SwapToReadmeFileButton"
Grid.Column="2"
Width="27"
ToolTip="Source readme from a local file (txt | html)">
<Button.Style>
<Style BasedOn="{StaticResource IconBareButtonStyle}" TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding CurrentModlistSettings.ReadmeIsWebsite}" Value="False">
<Setter Property="Foreground" Value="{StaticResource SecondaryBrush}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
<icon:PackIconMaterial
Width="20"
Height="20"
Kind="File" />
</Button>
</Grid>
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
<Border <Border

View File

@ -72,25 +72,7 @@ namespace Wabbajack
.DisposeWith(dispose); .DisposeWith(dispose);
this.BindStrict(this.ViewModel, x => x.CurrentModlistSettings.Website, x => x.WebsiteSetting.Text) this.BindStrict(this.ViewModel, x => x.CurrentModlistSettings.Website, x => x.WebsiteSetting.Text)
.DisposeWith(dispose); .DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.CurrentModlistSettings.ReadmeFilePath) this.BindStrict(this.ViewModel, x => x.CurrentModlistSettings.Readme, x => x.ReadmeSetting.Text)
.BindToStrict(this, x => x.ReadmeFilePickerSetting.PickerVM)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.CurrentModlistSettings.ReadmeIsWebsite)
.Select(isWebsite => isWebsite ? Visibility.Collapsed : Visibility.Visible)
.BindToStrict(this, x => x.ReadmeFilePickerSetting.Visibility)
.DisposeWith(dispose);
this.BindStrict(this.ViewModel, x => x.CurrentModlistSettings.ReadmeWebsite, x => x.ReadmeWebsiteSetting.Text)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.CurrentModlistSettings.ReadmeIsWebsite)
.Select(isWebsite => isWebsite ? Visibility.Visible : Visibility.Collapsed)
.BindToStrict(this, x => x.ReadmeWebsiteSetting.Visibility)
.DisposeWith(dispose);
this.MarkAsNeeded<CompilerView, CompilerVM, bool>(this.ViewModel, x => x.CurrentModlistSettings.ReadmeIsWebsite);
this.WhenAny(x => x.ViewModel.CurrentModlistSettings.SwapToWebsiteReadmeCommand)
.BindToStrict(this, x => x.SwapToReadmeWebsiteButton.Command)
.DisposeWith(dispose);
this.WhenAny(x => x.ViewModel.CurrentModlistSettings.SwapToTextReadmeCommand)
.BindToStrict(this, x => x.SwapToReadmeFileButton.Command)
.DisposeWith(dispose); .DisposeWith(dispose);
// Bottom Compiler Settings // Bottom Compiler Settings