mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Port AuthorFilesVM
This commit is contained in:
parent
26aabf413c
commit
eb0b5b0ea5
@ -14,8 +14,10 @@ using System.Threading.Tasks;
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using Wabbajack.Common;
|
using Wabbajack.Common;
|
||||||
|
using Wabbajack.Hashing.xxHash64;
|
||||||
using Wabbajack.Lib.Extensions;
|
using Wabbajack.Lib.Extensions;
|
||||||
using Wabbajack.Paths;
|
using Wabbajack.Paths;
|
||||||
|
using Wabbajack.Paths.IO;
|
||||||
|
|
||||||
namespace Wabbajack
|
namespace Wabbajack
|
||||||
{
|
{
|
||||||
@ -38,12 +40,12 @@ namespace Wabbajack
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!path.Exists)
|
if (!path.FileExists())
|
||||||
{
|
{
|
||||||
bitmapImage = default;
|
bitmapImage = default;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bitmapImage = new BitmapImage(new Uri((string)path, UriKind.RelativeOrAbsolute));
|
bitmapImage = new BitmapImage(new Uri(path.ToString(), UriKind.RelativeOrAbsolute));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@ -64,7 +66,7 @@ namespace Wabbajack
|
|||||||
|
|
||||||
public static void OpenFolder(AbsolutePath path)
|
public static void OpenFolder(AbsolutePath path)
|
||||||
{
|
{
|
||||||
Process.Start(new ProcessStartInfo(AbsolutePath.WindowsFolder.Combine("explorer.exe").ToString(), path.ToString())
|
Process.Start(new ProcessStartInfo(KnownFolders.Windows.Combine("explorer.exe").ToString(), path.ToString())
|
||||||
{
|
{
|
||||||
CreateNoWindow = true,
|
CreateNoWindow = true,
|
||||||
});
|
});
|
||||||
@ -81,24 +83,6 @@ namespace Wabbajack
|
|||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IDisposable BindCpuStatus(IObservable<CPUStatus> status, ObservableCollectionExtended<CPUDisplayVM> list)
|
|
||||||
{
|
|
||||||
return status.ObserveOn(RxApp.TaskpoolScheduler)
|
|
||||||
.ToObservableChangeSet(x => x.ID)
|
|
||||||
.Batch(TimeSpan.FromMilliseconds(50), RxApp.TaskpoolScheduler)
|
|
||||||
.EnsureUniqueChanges()
|
|
||||||
.ObserveOnGuiThread()
|
|
||||||
.TransformAndCache(
|
|
||||||
onAdded: (key, cpu) => new CPUDisplayVM(cpu),
|
|
||||||
onUpdated: (change, vm) => vm.AbsorbStatus(change.Current))
|
|
||||||
.AutoRefresh(x => x.IsWorking)
|
|
||||||
.AutoRefresh(x => x.StartTime)
|
|
||||||
.Filter(i => i.IsWorking && i.ID != WorkQueue.UnassignedCpuId)
|
|
||||||
.Sort(SortExpressionComparer<CPUDisplayVM>.Ascending(s => s.StartTime))
|
|
||||||
.Bind(list)
|
|
||||||
.Subscribe();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IObservable<BitmapImage> DownloadBitmapImage(this IObservable<string> obs, Action<Exception> exceptionHandler)
|
public static IObservable<BitmapImage> DownloadBitmapImage(this IObservable<string> obs, Action<Exception> exceptionHandler)
|
||||||
{
|
{
|
||||||
return obs
|
return obs
|
||||||
@ -150,20 +134,20 @@ namespace Wabbajack
|
|||||||
|
|
||||||
private static async Task WriteCachedImage(string url, byte[] data)
|
private static async Task WriteCachedImage(string url, byte[] data)
|
||||||
{
|
{
|
||||||
var folder = Consts.LocalAppDataPath.Combine("ModListImages");
|
var folder = KnownFolders.WabbajackAppLocal.Combine("ModListImages");
|
||||||
if (!folder.Exists) folder.CreateDirectory();
|
if (!folder.DirectoryExists()) folder.CreateDirectory();
|
||||||
|
|
||||||
var path = folder.Combine(Encoding.UTF8.GetBytes(url).xxHash().ToHex());
|
var path = folder.Combine(Encoding.UTF8.GetBytes(url).Hash().ToHex());
|
||||||
await path.WriteAllBytesAsync(data);
|
await path.WriteAllBytesAsync(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<(bool Found, MemoryStream data)> FindCachedImage(string uri)
|
private static async Task<(bool Found, MemoryStream data)> FindCachedImage(string uri)
|
||||||
{
|
{
|
||||||
var folder = Consts.LocalAppDataPath.Combine("ModListImages");
|
var folder = KnownFolders.WabbajackAppLocal.Combine("ModListImages");
|
||||||
if (!folder.Exists) folder.CreateDirectory();
|
if (!folder.DirectoryExists()) folder.CreateDirectory();
|
||||||
|
|
||||||
var path = folder.Combine(Encoding.UTF8.GetBytes(uri).xxHash().ToHex());
|
var path = folder.Combine(Encoding.UTF8.GetBytes(uri).Hash().ToHex());
|
||||||
return path.Exists ? (true, new MemoryStream(await path.ReadAllBytesAsync())) : (false, default);
|
return path.FileExists() ? (true, new MemoryStream(await path.ReadAllBytesAsync())) : (false, default);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,27 +1,23 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Reactive;
|
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using System.Reactive.Subjects;
|
using System.Reactive.Subjects;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Threading;
|
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using ReactiveUI.Fody.Helpers;
|
using ReactiveUI.Fody.Helpers;
|
||||||
using Wabbajack.Common;
|
using Wabbajack.Lib;
|
||||||
using Wabbajack.Lib.AuthorApi;
|
using Wabbajack.Networking.WabbajackClientApi;
|
||||||
using Wabbajack.Lib.FileUploader;
|
|
||||||
using Wabbajack.Networking.Http.Interfaces;
|
|
||||||
using Wabbajack.Services.OSIntegrated.TokenProviders;
|
using Wabbajack.Services.OSIntegrated.TokenProviders;
|
||||||
|
|
||||||
namespace Wabbajack
|
namespace Wabbajack.View_Models.Settings
|
||||||
{
|
{
|
||||||
public class AuthorFilesVM : BackNavigatingVM
|
public class AuthorFilesVM : BackNavigatingVM
|
||||||
{
|
{
|
||||||
private readonly ObservableAsPropertyHelper<Visibility> _isVisible;
|
private readonly ObservableAsPropertyHelper<Visibility> _isVisible;
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public Visibility IsVisible { get; set; };
|
public Visibility IsVisible { get; set; }
|
||||||
|
|
||||||
public ICommand SelectFile { get; }
|
public ICommand SelectFile { get; }
|
||||||
public ICommand HyperlinkCommand { get; }
|
public ICommand HyperlinkCommand { get; }
|
||||||
@ -32,13 +28,15 @@ namespace Wabbajack
|
|||||||
[Reactive] public string FinalUrl { get; set; }
|
[Reactive] public string FinalUrl { get; set; }
|
||||||
public FilePickerVM Picker { get;}
|
public FilePickerVM Picker { get;}
|
||||||
|
|
||||||
private Subject<bool> _isUploading = new Subject<bool>();
|
private Subject<bool> _isUploading = new();
|
||||||
private readonly WabbajackApiTokenProvider _token;
|
private readonly WabbajackApiTokenProvider _token;
|
||||||
|
private readonly Client _wjClient;
|
||||||
private IObservable<bool> IsUploading { get; }
|
private IObservable<bool> IsUploading { get; }
|
||||||
|
|
||||||
public AuthorFilesVM(WabbajackApiTokenProvider token, SettingsVM vm) : base(vm.MWVM)
|
public AuthorFilesVM(WabbajackApiTokenProvider token, Client wjClient, SettingsVM vm) : base(vm.MWVM)
|
||||||
{
|
{
|
||||||
_token = token;
|
_token = token;
|
||||||
|
_wjClient = wjClient;
|
||||||
IsUploading = _isUploading;
|
IsUploading = _isUploading;
|
||||||
Picker = new FilePickerVM(this);
|
Picker = new FilePickerVM(this);
|
||||||
|
|
||||||
@ -57,8 +55,8 @@ namespace Wabbajack
|
|||||||
|
|
||||||
ManageFiles = ReactiveCommand.Create(async () =>
|
ManageFiles = ReactiveCommand.Create(async () =>
|
||||||
{
|
{
|
||||||
var authorApiKey = await AuthorAPI.GetAPIKey();
|
var authorApiKey = (await token.Get())!.AuthorKey;
|
||||||
Utils.OpenWebsite(new Uri($"{Consts.WabbajackBuildServerUri}author_controls/login/{authorApiKey}"));
|
UIUtils.OpenWebsite(new Uri($"{Consts.WabbajackBuildServerUri}author_controls/login/{authorApiKey}"));
|
||||||
});
|
});
|
||||||
|
|
||||||
Upload = ReactiveCommand.Create(async () =>
|
Upload = ReactiveCommand.Create(async () =>
|
||||||
@ -66,14 +64,17 @@ namespace Wabbajack
|
|||||||
_isUploading.OnNext(true);
|
_isUploading.OnNext(true);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var queue = new WorkQueue();
|
var (progress, task) = _wjClient.UploadAuthorFile(Picker.TargetPath);
|
||||||
var result = await (await Client.Create()).UploadFile(queue, Picker.TargetPath,
|
|
||||||
(msg, progress) =>
|
var disposable = progress.Subscribe(m =>
|
||||||
{
|
{
|
||||||
FinalUrl = msg;
|
FinalUrl = m.Message;
|
||||||
UploadProgress = (double)progress;
|
UploadProgress = (double)m.PercentDone;
|
||||||
});
|
});
|
||||||
FinalUrl = result.ToString();
|
|
||||||
|
var final = await task;
|
||||||
|
disposable.Dispose();
|
||||||
|
FinalUrl = final.ToString();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using Wabbajack.Lib;
|
using Wabbajack.Lib;
|
||||||
|
using Wabbajack.View_Models.Settings;
|
||||||
|
|
||||||
namespace Wabbajack
|
namespace Wabbajack
|
||||||
{
|
{
|
||||||
|
@ -6,9 +6,10 @@
|
|||||||
xmlns:local="clr-namespace:Wabbajack"
|
xmlns:local="clr-namespace:Wabbajack"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:rxui="http://reactiveui.net"
|
xmlns:rxui="http://reactiveui.net"
|
||||||
|
xmlns:settings="clr-namespace:Wabbajack.View_Models.Settings"
|
||||||
d:DesignHeight="450"
|
d:DesignHeight="450"
|
||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
x:TypeArguments="local:AuthorFilesVM"
|
x:TypeArguments="settings:AuthorFilesVM"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<Border
|
<Border
|
||||||
x:Name="AuthorFiles"
|
x:Name="AuthorFiles"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
using Wabbajack.View_Models.Settings;
|
||||||
|
|
||||||
namespace Wabbajack
|
namespace Wabbajack
|
||||||
{
|
{
|
||||||
|
@ -18,4 +18,5 @@ public abstract class IPS4OAuth2 : ADownloadState, IMetaState
|
|||||||
public Uri? ImageURL { get; set; }
|
public Uri? ImageURL { get; set; }
|
||||||
public bool IsNSFW { get; set; }
|
public bool IsNSFW { get; set; }
|
||||||
public string? Description { get; set; }
|
public string? Description { get; set; }
|
||||||
|
public Uri? LinkUrl => null;
|
||||||
}
|
}
|
@ -26,6 +26,7 @@ public class Nexus : ADownloadState, IMetaState
|
|||||||
public bool IsNSFW { get; set; }
|
public bool IsNSFW { get; set; }
|
||||||
|
|
||||||
public string? Description { get; set; }
|
public string? Description { get; set; }
|
||||||
|
public Uri? LinkUrl => new($"https://www.nexusmods.com/{Game.MetaData().NexusName}/mods/{ModID}");
|
||||||
|
|
||||||
public async Task<bool> LoadMetaData()
|
public async Task<bool> LoadMetaData()
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace Wabbajack.Lib;
|
namespace Wabbajack.Lib;
|
||||||
|
|
||||||
public static class Consts
|
public static class Consts
|
||||||
{
|
{
|
||||||
public static string AppName = "Wabbajack";
|
public static string AppName = "Wabbajack";
|
||||||
|
public static Uri WabbajackBuildServerUri => new("https://build.wabbajack.org");
|
||||||
}
|
}
|
@ -329,4 +329,9 @@ public class Client
|
|||||||
if (!result.IsSuccessStatusCode)
|
if (!result.IsSuccessStatusCode)
|
||||||
throw new HttpException(result);
|
throw new HttpException(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public (IObservable<(Percent PercentDone, string Message)> Progress, Task<Uri> Task) UploadAuthorFile(AbsolutePath pickerTargetPath)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user