mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Several high-level compile errors fixed, ported several files
This commit is contained in:
parent
4bfd108702
commit
33161f9817
@ -2,10 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.Serialization.Json;
|
||||
using Wabbajack.DTOs;
|
||||
using Wabbajack.DTOs.JsonConverters;
|
||||
using Wabbajack.Lib;
|
||||
using Wabbajack.Lib.ModListRegistry;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using ReactiveUI;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Paths;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
@ -51,7 +52,7 @@ namespace Wabbajack
|
||||
|
||||
if (@from is AbsolutePath abs)
|
||||
{
|
||||
result = (string)abs;
|
||||
result = abs.ToString();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using ReactiveUI;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.RateLimiter;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
|
106
Wabbajack.App.Wpf/Error States/ErrorResponse.cs
Normal file
106
Wabbajack.App.Wpf/Error States/ErrorResponse.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using System;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public struct ErrorResponse : IErrorResponse
|
||||
{
|
||||
public readonly static ErrorResponse Success = Succeed();
|
||||
public readonly static ErrorResponse Failure = new ErrorResponse();
|
||||
|
||||
public bool Succeeded { get; }
|
||||
public Exception? Exception { get; }
|
||||
private readonly string _reason;
|
||||
|
||||
public bool Failed => !Succeeded;
|
||||
public string Reason
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Exception != null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_reason))
|
||||
{
|
||||
return Exception.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"{_reason}: {Exception.Message}";
|
||||
}
|
||||
}
|
||||
return _reason;
|
||||
}
|
||||
}
|
||||
|
||||
bool IErrorResponse.Succeeded => Succeeded;
|
||||
Exception? IErrorResponse.Exception => Exception;
|
||||
|
||||
private ErrorResponse(
|
||||
bool succeeded,
|
||||
string? reason = null,
|
||||
Exception? ex = null)
|
||||
{
|
||||
Succeeded = succeeded;
|
||||
_reason = reason ?? string.Empty;
|
||||
Exception = ex;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"({(Succeeded ? "Success" : "Fail")}, {Reason})";
|
||||
}
|
||||
|
||||
#region Factories
|
||||
public static ErrorResponse Succeed()
|
||||
{
|
||||
return new ErrorResponse(true);
|
||||
}
|
||||
|
||||
public static ErrorResponse Succeed(string reason)
|
||||
{
|
||||
return new ErrorResponse(true, reason);
|
||||
}
|
||||
|
||||
public static ErrorResponse Fail(string reason, Exception? ex = null)
|
||||
{
|
||||
return new ErrorResponse(false, reason: reason, ex: ex);
|
||||
}
|
||||
|
||||
public static ErrorResponse Fail(Exception ex)
|
||||
{
|
||||
return new ErrorResponse(false, ex: ex);
|
||||
}
|
||||
|
||||
public static ErrorResponse Fail()
|
||||
{
|
||||
return new ErrorResponse(false);
|
||||
}
|
||||
|
||||
public static ErrorResponse Create(bool successful, string? reason = null)
|
||||
{
|
||||
return new ErrorResponse(successful, reason);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static ErrorResponse Convert(IErrorResponse err, bool nullIsSuccess = true)
|
||||
{
|
||||
if (err == null) return Create(nullIsSuccess);
|
||||
return new ErrorResponse(err.Succeeded, err.Reason, err.Exception);
|
||||
}
|
||||
|
||||
public static ErrorResponse FirstFail(params ErrorResponse[] responses)
|
||||
{
|
||||
foreach (var resp in responses)
|
||||
{
|
||||
if (resp.Failed) return resp;
|
||||
}
|
||||
return ErrorResponse.Success;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IErrorResponse
|
||||
{
|
||||
bool Succeeded { get; }
|
||||
Exception? Exception { get; }
|
||||
string Reason { get; }
|
||||
}
|
||||
}
|
135
Wabbajack.App.Wpf/Error States/GetResponse.cs
Normal file
135
Wabbajack.App.Wpf/Error States/GetResponse.cs
Normal file
@ -0,0 +1,135 @@
|
||||
using System;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public struct GetResponse<T> : IEquatable<GetResponse<T>>, IErrorResponse
|
||||
{
|
||||
public static readonly GetResponse<T> Failure = new GetResponse<T>();
|
||||
|
||||
public readonly T Value;
|
||||
public readonly bool Succeeded;
|
||||
public readonly Exception? Exception;
|
||||
private readonly string _reason;
|
||||
|
||||
public bool Failed => !Succeeded;
|
||||
public string Reason
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Exception != null)
|
||||
{
|
||||
return Exception.ToString();
|
||||
}
|
||||
return _reason;
|
||||
}
|
||||
}
|
||||
|
||||
bool IErrorResponse.Succeeded => Succeeded;
|
||||
Exception? IErrorResponse.Exception => Exception;
|
||||
|
||||
private GetResponse(
|
||||
bool succeeded,
|
||||
T? val = default,
|
||||
string? reason = null,
|
||||
Exception? ex = null)
|
||||
{
|
||||
Value = val!;
|
||||
Succeeded = succeeded;
|
||||
_reason = reason ?? string.Empty;
|
||||
Exception = ex;
|
||||
}
|
||||
|
||||
public bool Equals(GetResponse<T> other)
|
||||
{
|
||||
return Succeeded == other.Succeeded
|
||||
&& Equals(Value, other.Value);
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (!(obj is GetResponse<T> rhs)) return false;
|
||||
return Equals(rhs);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
System.HashCode hash = new HashCode();
|
||||
hash.Add(Value);
|
||||
hash.Add(Succeeded);
|
||||
return hash.ToHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"({(Succeeded ? "Success" : "Fail")}, {Value}, {Reason})";
|
||||
}
|
||||
|
||||
public GetResponse<R> BubbleFailure<R>()
|
||||
{
|
||||
return new GetResponse<R>(
|
||||
succeeded: false,
|
||||
reason: _reason,
|
||||
ex: Exception);
|
||||
}
|
||||
|
||||
public GetResponse<R> Bubble<R>(Func<T, R> conv)
|
||||
{
|
||||
return new GetResponse<R>(
|
||||
succeeded: Succeeded,
|
||||
val: conv(Value),
|
||||
reason: _reason,
|
||||
ex: Exception);
|
||||
}
|
||||
|
||||
public T EvaluateOrThrow()
|
||||
{
|
||||
if (Succeeded)
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
throw new ArgumentException(Reason);
|
||||
}
|
||||
|
||||
#region Factories
|
||||
public static GetResponse<T> Succeed(T value)
|
||||
{
|
||||
return new GetResponse<T>(true, value);
|
||||
}
|
||||
|
||||
public static GetResponse<T> Succeed(T value, string reason)
|
||||
{
|
||||
return new GetResponse<T>(true, value, reason);
|
||||
}
|
||||
|
||||
public static GetResponse<T> Fail(string reason)
|
||||
{
|
||||
return new GetResponse<T>(false, reason: reason);
|
||||
}
|
||||
|
||||
public static GetResponse<T> Fail(T val, string reason)
|
||||
{
|
||||
return new GetResponse<T>(false, val, reason);
|
||||
}
|
||||
|
||||
public static GetResponse<T> Fail(Exception ex)
|
||||
{
|
||||
return new GetResponse<T>(false, ex: ex);
|
||||
}
|
||||
|
||||
public static GetResponse<T> Fail(T val, Exception ex)
|
||||
{
|
||||
return new GetResponse<T>(false, val, ex: ex);
|
||||
}
|
||||
|
||||
public static GetResponse<T> Fail(T val)
|
||||
{
|
||||
return new GetResponse<T>(false, val);
|
||||
}
|
||||
|
||||
public static GetResponse<T> Create(bool successful, T? val = default(T), string? reason = null)
|
||||
{
|
||||
return new GetResponse<T>(successful, val!, reason);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,13 +1,8 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.Serialization.Json;
|
||||
using Wabbajack.Compiler;
|
||||
using Wabbajack.DTOs.JsonConverters;
|
||||
using Wabbajack.Lib;
|
||||
using Wabbajack.Paths;
|
||||
using Consts = Wabbajack.Lib.Consts;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
|
@ -10,6 +10,8 @@ using System.Reactive.Linq;
|
||||
using System.Windows.Input;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib;
|
||||
using Wabbajack.Lib.Extensions;
|
||||
using Wabbajack.Paths;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
|
@ -98,7 +98,7 @@ namespace Wabbajack
|
||||
|
||||
var sourceList = Observable.Return(Unit.Default)
|
||||
.ObserveOn(RxApp.TaskpoolScheduler)
|
||||
.SelectTask(async _ =>
|
||||
.SelectMany(async _ =>
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -16,9 +16,14 @@ using DynamicData;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Downloaders;
|
||||
using Wabbajack.DTOs;
|
||||
using Wabbajack.Lib;
|
||||
using Wabbajack.Lib.Downloaders;
|
||||
using Wabbajack.Lib.Extensions;
|
||||
using Wabbajack.Lib.ModListRegistry;
|
||||
using Wabbajack.Paths;
|
||||
using Wabbajack.RateLimiter;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.DTOs;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
|
@ -21,8 +21,12 @@ using System.Collections.Generic;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.WindowsAPICodePack.Dialogs;
|
||||
using Microsoft.WindowsAPICodePack.Shell;
|
||||
using Wabbajack.Common.IO;
|
||||
using Wabbajack.Lib.Extensions;
|
||||
using Wabbajack.Lib.Interventions;
|
||||
using Wabbajack.Paths;
|
||||
using Wabbajack.RateLimiter;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
|
@ -5,18 +5,23 @@ using System.Reactive.Subjects;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib.AuthorApi;
|
||||
using Wabbajack.Lib.FileUploader;
|
||||
using Wabbajack.Networking.Http.Interfaces;
|
||||
using Wabbajack.Services.OSIntegrated.TokenProviders;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
public class AuthorFilesVM : BackNavigatingVM
|
||||
{
|
||||
private readonly ObservableAsPropertyHelper<Visibility> _isVisible;
|
||||
public Visibility IsVisible => _isVisible.Value;
|
||||
|
||||
[Reactive]
|
||||
public Visibility IsVisible { get; set; };
|
||||
|
||||
public ICommand SelectFile { get; }
|
||||
public ICommand HyperlinkCommand { get; }
|
||||
@ -25,21 +30,26 @@ namespace Wabbajack
|
||||
|
||||
[Reactive] public double UploadProgress { get; set; }
|
||||
[Reactive] public string FinalUrl { get; set; }
|
||||
|
||||
private WorkQueue Queue = new WorkQueue(1);
|
||||
|
||||
public FilePickerVM Picker { get;}
|
||||
|
||||
private Subject<bool> _isUploading = new Subject<bool>();
|
||||
private readonly WabbajackApiTokenProvider _token;
|
||||
private IObservable<bool> IsUploading { get; }
|
||||
|
||||
public AuthorFilesVM(SettingsVM vm) : base(vm.MWVM)
|
||||
public AuthorFilesVM(WabbajackApiTokenProvider token, SettingsVM vm) : base(vm.MWVM)
|
||||
{
|
||||
_token = token;
|
||||
IsUploading = _isUploading;
|
||||
Picker = new FilePickerVM(this);
|
||||
|
||||
_isVisible = AuthorAPI.HaveAuthorAPIKey.Select(h => h ? Visibility.Visible : Visibility.Collapsed)
|
||||
.ToProperty(this, x => x.IsVisible);
|
||||
|
||||
IsVisible = Visibility.Hidden;
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var isAuthor = string.IsNullOrWhiteSpace((await _token.Get())?.AuthorKey);
|
||||
IsVisible = isAuthor ? Visibility.Visible : Visibility.Collapsed;
|
||||
});
|
||||
|
||||
SelectFile = Picker.ConstructTypicalPickerCommand(IsUploading.StartWith(false).Select(u => !u));
|
||||
|
||||
|
@ -10,8 +10,10 @@ using System.Reactive.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.DTOs.DownloadStates;
|
||||
using Wabbajack.Lib;
|
||||
using Wabbajack.Lib.Downloaders;
|
||||
using Wabbajack.Lib.Extensions;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CefSharp;
|
||||
using CefSharp.Wpf;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.Lib;
|
||||
@ -18,11 +19,13 @@ namespace Wabbajack
|
||||
{
|
||||
public class WebBrowserVM : ViewModel, IBackNavigatingVM, IDisposable
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
[Reactive]
|
||||
public string Instructions { get; set; }
|
||||
|
||||
public IWebBrowser Browser { get; } = new ChromiumWebBrowser();
|
||||
public CefSharpWrapper Driver => new CefSharpWrapper(Browser);
|
||||
public CefSharpWrapper Driver => new(_logger, Browser);
|
||||
|
||||
[Reactive]
|
||||
public ViewModel NavigateBackTarget { get; set; }
|
||||
@ -33,16 +36,17 @@ namespace Wabbajack
|
||||
public Subject<bool> IsBackEnabledSubject { get; } = new Subject<bool>();
|
||||
public IObservable<bool> IsBackEnabled { get; }
|
||||
|
||||
private WebBrowserVM(string url = "http://www.wabbajack.org")
|
||||
private WebBrowserVM(ILogger logger, string url = "http://www.wabbajack.org")
|
||||
{
|
||||
_logger = logger;
|
||||
IsBackEnabled = IsBackEnabledSubject.StartWith(true);
|
||||
Instructions = "Wabbajack Web Browser";
|
||||
}
|
||||
|
||||
public static async Task<WebBrowserVM> GetNew(string url = "http://www.wabbajack.org")
|
||||
public static async Task<WebBrowserVM> GetNew(ILogger logger, string url = "http://www.wabbajack.org")
|
||||
{
|
||||
// Make sure libraries are extracted first
|
||||
return new WebBrowserVM(url);
|
||||
return new WebBrowserVM(logger, url);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
|
@ -85,10 +85,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Compression.BSA\Compression.BSA.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.CLI\Wabbajack.CLI.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Common\Wabbajack.Common.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Lib\Wabbajack.Lib.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Services.OSIntegrated\Wabbajack.Services.OSIntegrated.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,4 +1,3 @@
|
||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<ReactiveUI />
|
||||
<ModuleInit />
|
||||
</Weavers>
|
@ -25,12 +25,6 @@
|
||||
<PackageReference Include="Genbox.AlphaFS">
|
||||
<Version>2.2.2.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="HtmlAgilityPack">
|
||||
<Version>1.11.34</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MegaApiClient">
|
||||
<Version>1.9.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CSharp">
|
||||
<Version>4.7.0</Version>
|
||||
</PackageReference>
|
||||
@ -61,22 +55,13 @@
|
||||
<PackageReference Include="System.ServiceModel.Syndication">
|
||||
<Version>5.0.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="WebSocketSharp-netstandard">
|
||||
<Version>1.0.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="XC.BouncyCastle.Crypto">
|
||||
<Version>1.0.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="YamlDotNet.NetCore">
|
||||
<Version>1.0.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Compression.BSA\Compression.BSA.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Common\Wabbajack.Common.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Downloaders.Dispatcher\Wabbajack.Downloaders.Dispatcher.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Networking.WabbajackClientApi\Wabbajack.Networking.WabbajackClientApi.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.VirtualFileSystem\Wabbajack.VirtualFileSystem.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="LibCefHelpers\cefsharp.7z" />
|
||||
|
Loading…
Reference in New Issue
Block a user