Revert "Fix login logout buttons"

This commit is contained in:
Timothy Baldridge 2021-11-10 16:04:57 -07:00 committed by GitHub
parent 9ea30334f5
commit e1b753edd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 76 additions and 380 deletions

View File

@ -9,7 +9,6 @@
<Application.Styles>
<StyleInclude Source="avares://Material.Icons.Avalonia/App.xaml" />
<FluentTheme Mode="Dark" />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
<StyleInclude Source="avares://Wabbajack.App/Assets/Wabbajack.axaml" />
<Style Selector="Button:not(:pointerover) /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent" />

View File

@ -41,12 +41,6 @@
<Setter Property="CornerRadius" Value="4"></Setter>
</Style>
<Style Selector="Border.StandardBorder">
<Setter Property="BorderThickness" Value="2"></Setter>
<Setter Property="BorderBrush" Value="DarkGray"></Setter>
<Setter Property="CornerRadius" Value="4"></Setter>
</Style>
<Style Selector="Border.Settings Grid">
<Setter Property="Margin" Value="4"></Setter>
</Style>

View File

@ -1,6 +1,6 @@
using Wabbajack.Paths;
namespace Wabbajack.Services.OSIntegrated;
namespace Wabbajack.App;
public class Configuration
{

View File

@ -21,7 +21,6 @@ using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
using Wabbajack.Services.OSIntegrated;
using Wabbajack.VFS;
namespace Wabbajack.App.Controls;

View File

@ -4,10 +4,13 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Controls.ResourceView">
<Grid RowDefinitions="Auto" ColumnDefinitions="140, 100, 140, 100">
<TextBlock Grid.Column="0" VerticalAlignment="Center" Margin="4, 0" x:Name="ResourceName"></TextBlock>
<TextBox Grid.Column="1" Text="32" Margin="4, 0" x:Name="MaxTasks"></TextBox>
<TextBox Grid.Column="2" Margin="4, 0" x:Name="MaxThroughput"></TextBox>
<TextBlock Grid.Column="3" Text="42GB" VerticalAlignment="Center" Margin="4, 0" x:Name="CurrentThroughput"></TextBlock>
</Grid>
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="ResourceName" Width="100" HorizontalAlignment="Left" VerticalAlignment="Center" />
<Label Width="100" HorizontalContentAlignment="Right" VerticalAlignment="Center">Tasks:</Label>
<TextBox x:Name="MaxTasks" Width="20" HorizontalAlignment="Left" VerticalAlignment="Center" />
<Label Width="100" HorizontalContentAlignment="Right" VerticalAlignment="Center">Throughput:</Label>
<TextBox x:Name="MaxThroughput" Width="20" HorizontalAlignment="Left" VerticalAlignment="Center" />
<Label Width="100" HorizontalContentAlignment="Right" VerticalAlignment="Center">Status:</Label>
<TextBlock x:Name="CurrentThrougput" Width="50" HorizontalAlignment="Left" VerticalAlignment="Center" />
</StackPanel>
</UserControl>

View File

@ -17,21 +17,10 @@ public partial class ResourceView : ReactiveUserControl<ResourceViewModel>, IAct
this.Bind(ViewModel, vm => vm.MaxTasks, view => view.MaxTasks.Text)
.DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.MaxThroughput, view => view.MaxThroughput.Text,
l => l is 0 or long.MaxValue ? "∞" : (l / 1024 / 1024).ToString(),
v =>
{
v = v.Trim();
if (v is "0" or "∞" || v == long.MaxValue.ToString())
{
return long.MaxValue;
}
return long.TryParse(v, out var l) ? l * 1024 * 1024 : long.MaxValue;
})
this.Bind(ViewModel, vm => vm.MaxThroughput, view => view.MaxThroughput.Text)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.CurrentThroughput, view => view.CurrentThroughput.Text,
this.OneWayBind(ViewModel, vm => vm.CurrentThroughput, view => view.CurrentThrougput.Text,
val => val.FileSizeToString())
.DisposeWith(disposables);
});

View File

@ -2,11 +2,9 @@ using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Timers;
using Avalonia.Threading;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.ViewModels;
using Wabbajack.Common;
using Wabbajack.RateLimiter;
namespace Wabbajack.App.Controls;
@ -20,7 +18,7 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab
{
Activator = new ViewModelActivator();
_resource = resource;
_timer = new Timer(250);
_timer = new Timer(1.0);
Name = resource.Name;
@ -35,8 +33,13 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab
_timer.Elapsed -= TimerElapsed;
}).DisposeWith(disposables);
MaxTasks = _resource.MaxTasks;
MaxThroughput = _resource.MaxThroughput;
this.WhenAnyValue(vm => vm.MaxThroughput)
.Skip(1)
.Subscribe(v => { _resource.MaxThroughput = MaxThroughput; }).DisposeWith(disposables);
this.WhenAnyValue(vm => vm.MaxTasks)
.Skip(1)
.Subscribe(v => { _resource.MaxTasks = MaxTasks; }).DisposeWith(disposables);
});
}
@ -48,8 +51,6 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab
[Reactive] public string Name { get; set; }
[Reactive] public string ThroughputHumanFriendly { get; set; }
public void Dispose()
{
@ -58,9 +59,8 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab
private void TimerElapsed(object? sender, ElapsedEventArgs e)
{
Dispatcher.UIThread.Post(() => {
MaxTasks = _resource.MaxTasks;
MaxThroughput = _resource.MaxThroughput;
CurrentThroughput = _resource.StatusReport.Transferred;
ThroughputHumanFriendly = _resource.StatusReport.Transferred.ToFileSizeString();
});
}
}

View File

@ -12,7 +12,6 @@ using Wabbajack.Hashing.xxHash64;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
using Wabbajack.Services.OSIntegrated;
using Wabbajack.VFS;
namespace Wabbajack.App.Models;

View File

@ -9,7 +9,7 @@ using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
namespace Wabbajack.Services.OSIntegrated;
namespace Wabbajack.App.Models;
public class SettingsManager
{
@ -35,11 +35,7 @@ public class SettingsManager
var tmp = GetPath(key).WithExtension(Ext.Temp);
await using (var s = tmp.Open(FileMode.Create, FileAccess.Write))
{
var opts = new JsonSerializerOptions(_dtos.Options)
{
WriteIndented = true
};
await JsonSerializer.SerializeAsync(s, value, opts);
await JsonSerializer.SerializeAsync(s, value, _dtos.Options);
}
await tmp.MoveToAsync(GetPath(key), true, CancellationToken.None);

View File

@ -31,7 +31,7 @@ namespace Wabbajack.App.Screens;
public class BrowseViewModel : ViewModelBase, IActivatableViewModel
{
private readonly Wabbajack.Services.OSIntegrated.Configuration _configuration;
private readonly Configuration _configuration;
private readonly DownloadDispatcher _dispatcher;
private readonly IResource<DownloadDispatcher> _dispatcherLimiter;
private readonly DTOSerializer _dtos;
@ -54,7 +54,7 @@ public class BrowseViewModel : ViewModelBase, IActivatableViewModel
IResource<HttpClient> limiter, FileHashCache hashCache,
IResource<DownloadDispatcher> dispatcherLimiter, DownloadDispatcher dispatcher, GameLocator gameLocator,
ImageCache imageCache,
DTOSerializer dtos, Wabbajack.Services.OSIntegrated.Configuration configuration)
DTOSerializer dtos, Configuration configuration)
{
LoadingLock = new LoadingLock();
Activator = new ViewModelActivator();

View File

@ -18,7 +18,6 @@ using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Installer;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.Services.OSIntegrated;
using Consts = Wabbajack.Compiler.Consts;
namespace Wabbajack.App.Screens;

View File

@ -24,9 +24,9 @@
<TextBox Grid.Column="1" Grid.Row="1" IsEnabled="False" Height="20" x:Name="InstallPath" />
<Grid Grid.Column="1" Grid.Row="3" Grid.ColumnDefinitions="*, *, *" HorizontalAlignment="Center">
<Button Grid.Column="0" x:Name="WebsiteButton" Click="ShowWebsite">Website</Button>
<Button Grid.Column="1" x:Name="ReadmeButton" Click="ShowReadme">Readme</Button>
<Button Grid.Column="2" x:Name="LocalFilesButton" Click="ShowLocalFiles">Local Files</Button>
<Button Grid.Column="0" x:Name="WebsiteButton">Website</Button>
<Button Grid.Column="1" x:Name="ReadmeButton">Readme</Button>
<Button Grid.Column="2" x:Name="LocalFilesButton">Local Files</Button>
</Grid>
<controls:LargeIconButton x:Name="PlayGame" Margin="40, 0, 0, 0" Grid.Row="0" Grid.Column="2"

View File

@ -1,10 +1,6 @@
using System;
using System.Reactive.Disposables;
using Avalonia.Interactivity;
using ReactiveUI;
using Wabbajack.App.Utilities;
using Wabbajack.App.Views;
using Wabbajack.Installer;
namespace Wabbajack.App.Screens;
@ -29,19 +25,4 @@ public partial class LauncherView : ScreenBase<LauncherViewModel>
.DisposeWith(disposables);
});
}
private void ShowWebsite(object? sender, RoutedEventArgs e)
{
OSUtil.OpenWebsite(ViewModel!.Setting!.StrippedModListData?.Website!);
}
private void ShowReadme(object? sender, RoutedEventArgs e)
{
OSUtil.OpenWebsite(new Uri(ViewModel!.Setting!.StrippedModListData?.Readme!));
}
private void ShowLocalFiles(object? sender, RoutedEventArgs e)
{
OSUtil.OpenFolder(ViewModel!.Setting!.Install);
}
}

View File

@ -34,28 +34,22 @@
</Grid>
</Border>
<Border x:Name="ResourcesBorder" Margin="5" BorderThickness="1" Classes="ResourceSettings StandardBorder">
<Grid RowDefinitions="Auto, Auto, Auto, Auto" ColumnDefinitions="140, 100, 140, 100">
<TextBlock Grid.Row="0" Text="Resources" FontSize="20" Grid.ColumnSpan="4" Margin="4"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Name" FontWeight="Bold" Margin="4, 4"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="1" Text="Max Tasks" FontWeight="Bold" Margin="4, 4"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="2" Text="Max Throughput" FontWeight="Bold" Margin="4, 4"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="3" Text="Transferred" FontWeight="Bold" Margin="4, 4"></TextBlock>
<Border x:Name="ResourcesBorder" Margin="5" BorderThickness="1" Classes="Settings">
<Grid RowDefinitions="Auto, Auto">
<TextBlock FontSize="20" Grid.ColumnSpan="4">Resource Limits</TextBlock>
<ItemsRepeater Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" x:Name="ResourcesList" Margin="0, 4">
<ItemsRepeater.Layout>
<StackLayout></StackLayout>
</ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate>
<ItemsControl Grid.Row="1" x:Name="ResourceList">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:ResourceView></controls:ResourceView>
<controls:ResourceView />
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
<Button Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" HorizontalAlignment="Stretch" Margin="4" Click="SaveSettingsAndRestart">
<TextBlock Text="Save Settings and Restart Wabbajack" HorizontalAlignment="Center" TextAlignment="Center"></TextBlock>
</Button>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Border>

View File

@ -1,8 +1,6 @@
using System.Reactive.Disposables;
using Avalonia.Interactivity;
using ReactiveUI;
using Wabbajack.App.Views;
using Wabbajack.Common;
namespace Wabbajack.App.Screens;
@ -17,27 +15,8 @@ public partial class SettingsView : ScreenBase<SettingsViewModel>
.DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.NexusLogout, view => view.NexusLogOut)
.DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.LoversLabLogin, view => view.LoversLabLogIn)
this.OneWayBind(ViewModel, vm => vm.Resources, view => view.ResourceList.Items)
.DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.LoversLabLogout, view => view.LoversLabLogOut)
.DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.VectorPlexusLogin, view => view.VectorPlexusLogIn)
.DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.VectorPlexusLogout, view => view.VectorPlexusLogOut)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.Resources, view => view.ResourcesList.Items)
.DisposeWith(disposables);
});
}
private void SaveSettingsAndRestart(object? sender, RoutedEventArgs e)
{
ViewModel!.SaveResourceSettingsAndRestart().FireAndForget();
}
}

View File

@ -1,25 +1,18 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using ReactiveUI;
using Wabbajack.App.Controls;
using Wabbajack.App.Messages;
using Wabbajack.App.Models;
using Wabbajack.App.ViewModels;
using Wabbajack.Common;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
using Wabbajack.Services.OSIntegrated;
using Wabbajack.Services.OSIntegrated.TokenProviders;
namespace Wabbajack.App.Screens;
@ -29,26 +22,16 @@ public class SettingsViewModel : ViewModelBase
private readonly Subject<AbsolutePath> _fileSystemEvents = new();
private readonly ILogger<SettingsViewModel> _logger;
public readonly IEnumerable<ResourceViewModel> Resources;
private readonly ResourceSettingsManager _resourceSettingsManager;
public SettingsViewModel(ILogger<SettingsViewModel> logger, Configuration configuration,
ResourceSettingsManager resourceSettingsManager,
NexusApiTokenProvider nexusProvider, IEnumerable<IResource> resources, LoversLabTokenProvider llProvider, VectorPlexusTokenProvider vpProvider)
NexusApiTokenProvider nexusProvider, IEnumerable<IResource> resources)
{
_resourceSettingsManager = resourceSettingsManager;
_logger = logger;
Resources = resources.Select(r => new ResourceViewModel(r))
.OrderBy(o => o.Name)
.ToArray();
Resources = resources.Select(r => new ResourceViewModel(r)).ToArray();
Activator = new ViewModelActivator();
this.WhenActivated(disposables =>
{
foreach (var resource in Resources)
{
resource.Activator.Activate().DisposeWith(disposables);
}
configuration.EncryptedDataLocation.CreateDirectory();
Watcher = new FileSystemWatcher(configuration.EncryptedDataLocation.ToString());
Watcher.DisposeWith(disposables);
@ -67,61 +50,16 @@ public class SettingsViewModel : ViewModelBase
ReactiveCommand.Create(() => { MessageBus.Current.SendMessage(new NavigateTo(typeof(NexusLoginViewModel))); },
haveNexusToken.Select(x => !x));
NexusLogout = ReactiveCommand.Create(nexusProvider.DeleteToken, haveNexusToken.Select(x => x));
var haveLLToken = _fileSystemEvents
.StartWith(AbsolutePath.Empty)
.Select(_ => llProvider.HaveToken());
LoversLabLogin =
ReactiveCommand.Create(() => { MessageBus.Current.SendMessage(new NavigateTo(typeof(LoversLabOAuthLoginViewModel))); },
haveLLToken.Select(x => !x));
LoversLabLogout = ReactiveCommand.Create(llProvider.DeleteToken, haveLLToken.Select(x => x));
var haveVectorPlexusToken = _fileSystemEvents
.StartWith(AbsolutePath.Empty)
.Select(_ => vpProvider.HaveToken());
VectorPlexusLogin =
ReactiveCommand.Create(() => { MessageBus.Current.SendMessage(new NavigateTo(typeof(VectorPlexusOAuthLoginViewModel))); },
haveVectorPlexusToken.Select(x => !x));
VectorPlexusLogout = ReactiveCommand.Create(vpProvider.DeleteToken, haveVectorPlexusToken.Select(x => x));
});
}
public ReactiveCommand<Unit, Unit> NexusLogin { get; set; }
public ReactiveCommand<Unit, Unit> NexusLogout { get; set; }
public ReactiveCommand<Unit, Unit> LoversLabLogin { get; set; }
public ReactiveCommand<Unit, Unit> LoversLabLogout { get; set; }
public ReactiveCommand<Unit, Unit> VectorPlexusLogin { get; set; }
public ReactiveCommand<Unit, Unit> VectorPlexusLogout { get; set; }
public FileSystemWatcher Watcher { get; set; }
private void Pulse(object sender, FileSystemEventArgs e)
{
_fileSystemEvents.OnNext(e.FullPath?.ToAbsolutePath() ?? default);
}
public async Task SaveResourceSettingsAndRestart()
{
await _resourceSettingsManager.SaveSettings(Resources.ToDictionary(r => r.Name, r =>
new ResourceSettingsManager.ResourceSetting()
{
MaxTasks = r.MaxTasks,
MaxThroughput = r.MaxThroughput
}));
var proc = new Process()
{
StartInfo = new ProcessStartInfo()
{
FileName = Process.GetCurrentProcess().MainModule!.FileName
}
};
proc.Start();
Environment.Exit(0);
}
}

View File

@ -198,16 +198,9 @@ public class StandardInstallationViewModel : ViewModelBase
_logger.LogInformation("Installer created, starting the installation process");
try
{
if (!string.IsNullOrWhiteSpace(_config.ModList.Readme))
OSUtil.OpenWebsite(new Uri(_config.ModList.Readme));
var result = await Task.Run(async () => await _installer.Begin(CancellationToken.None));
if (!result) throw new Exception("Installation failed");
if (!string.IsNullOrWhiteSpace(_config.ModList.Readme))
OSUtil.OpenWebsite(new Uri(_config.ModList.Readme));
if (result) await SaveConfigAndContinue(_config);
}
catch (Exception ex)
@ -226,15 +219,13 @@ public class StandardInstallationViewModel : ViewModelBase
await image.CopyToAsync(os);
}
await _installStateManager.SetLastState(new InstallationConfigurationSetting
{
Downloads = config.Downloads,
Install = config.Install,
Metadata = config.Metadata,
ModList = config.ModlistArchive,
Image = path,
StrippedModListData = config.ModList.Strip()
Image = path
});
MessageBus.Current.SendMessage(new ConfigureLauncher(config.Install));

View File

@ -93,6 +93,17 @@ public static class ServiceExtensions
CachePath = KnownFolders.WabbajackAppLocal.Combine("cef_cache").ToString()
});
services.AddSingleton(s => new Configuration
{
EncryptedDataLocation = KnownFolders.WabbajackAppLocal.Combine("encrypted"),
ModListsDownloadLocation = KnownFolders.EntryPoint.Combine("downloaded_mod_lists"),
SavedSettingsLocation = KnownFolders.WabbajackAppLocal.Combine("saved_settings"),
LogLocation = KnownFolders.EntryPoint.Combine("logs"),
ImageCacheLocation = KnownFolders.WabbajackAppLocal.Combine("image_cache")
});
services.AddSingleton<SettingsManager>();
services.AddSingleton(s =>
{
App.FrameworkInitialized += App_FrameworkInitialized;

View File

@ -10,7 +10,6 @@ using DynamicData;
using Microsoft.Extensions.Logging;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.Services.OSIntegrated;
namespace Wabbajack.App.Utilities;

View File

@ -1,38 +0,0 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis;
using Wabbajack.Common;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
namespace Wabbajack.App.Utilities;
public static class OSUtil
{
public static void OpenWebsite(Uri uri)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var helper = new ProcessHelper()
{
Path = "cmd.exe".ToRelativePath().RelativeTo(KnownFolders.WindowsSystem32),
Arguments = new[] {"/C", $"rundll32 url.dll,FileProtocolHandler {uri}"}
};
helper.Start().FireAndForget();
}
}
public static void OpenFolder(AbsolutePath path)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var helper = new ProcessHelper()
{
Path = "explorer.exe".ToRelativePath().RelativeTo(KnownFolders.Windows),
Arguments = new object[] {path}
};
helper.Start().FireAndForget();
}
}
}

View File

@ -20,7 +20,6 @@ using Wabbajack.DTOs.SavedSettings;
using Wabbajack.Installer;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.Services.OSIntegrated;
namespace Wabbajack.App.ViewModels;
@ -125,8 +124,7 @@ public class InstallConfigurationViewModel : ViewModelBase, IActivatableViewMode
ModList = ModListPath,
Downloads = Download,
Install = Install,
Metadata = metadata,
StrippedModListData = ModList?.Strip()
Metadata = metadata
});
await _settingsManager.Save("last-install-path", ModListPath);

View File

@ -97,7 +97,5 @@ public class NexusLoginViewModel : GuidedWebViewModel
Cookies = cookies,
ApiKey = key
});
MessageBus.Current.SendMessage(new NavigateBack());
}
}

View File

@ -9,11 +9,8 @@ using System.Web;
using CefNet;
using Microsoft.Extensions.Logging;
using Wabbajack.App.Extensions;
using Wabbajack.App.Messages;
using Wabbajack.DTOs.Logins;
using Wabbajack.Services.OSIntegrated;
using Xunit.Sdk;
using MessageBus = ReactiveUI.MessageBus;
namespace Wabbajack.App.ViewModels;
@ -90,8 +87,6 @@ public abstract class OAuthLoginViewModel<TLoginType> : GuidedWebViewModel
Cookies = cookies,
ResultState = data!
});
MessageBus.Current.SendMessage(new NavigateBack());
}
private class AsyncSchemeHandler : CefSchemeHandlerFactory

View File

@ -46,6 +46,7 @@ internal class Program
services.AddSingleton(new ParallelOptions {MaxDegreeOfParallelism = Environment.ProcessorCount});
services.AddSingleton<Client>();
services.AddSingleton<Networking.WabbajackClientApi.Client>();
services.AddSingleton<Configuration>();
services.AddSingleton(s => new GitHubClient(new ProductHeaderValue("wabbajack")));
services.AddOSIntegrated();

View File

@ -4,7 +4,6 @@ using Wabbajack.Networking.WabbajackClientApi;
using Wabbajack.Services.OSIntegrated;
using Xunit.DependencyInjection;
using Xunit.DependencyInjection.Logging;
using Configuration = Wabbajack.Services.OSIntegrated.Configuration;
namespace Wabbajack.Compiler.Test;

View File

@ -66,20 +66,4 @@ public class ModList
/// Whether the Modlist is NSFW or not
/// </summary>
public bool IsNSFW { get; set; }
public ModList Strip()
{
return new ModList
{
Author = Author,
Description = Description,
GameType = GameType,
Name = Name,
Readme = Readme,
WabbajackVersion = WabbajackVersion,
Website = Website,
Version = Version,
IsNSFW = IsNSFW,
};
}
}

View File

@ -20,5 +20,5 @@ public class InstallationConfigurationSetting
public ModlistMetadata? Metadata { get; set; }
public AbsolutePath Image { get; set; }
public ModList? StrippedModListData { get; set; }
}

View File

@ -4,7 +4,6 @@ using Wabbajack.Downloaders.IPS4OAuth2Downloader;
using Wabbajack.Downloaders.MediaFire;
using Wabbajack.Downloaders.ModDB;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Networking.WabbajackClientApi;
namespace Wabbajack.Downloaders;
@ -24,7 +23,6 @@ public static class ServiceExtensions
.AddIPS4OAuth2Downloaders()
.AddWabbajackCDNDownloader()
.AddGameFileDownloader()
.AddWabbajackClient()
.AddSingleton<DownloadDispatcher>();
}
}

View File

@ -4,10 +4,9 @@ namespace Wabbajack.Networking.WabbajackClientApi;
public static class ServiceExtensions
{
public static IServiceCollection AddWabbajackClient(this IServiceCollection services)
public static void AddWabbajackClient(this IServiceCollection services)
{
services.AddSingleton<Configuration>();
services.AddSingleton<Client>();
return services;
}
}

View File

@ -11,9 +11,6 @@ public static class KnownFolders
public static AbsolutePath AppDataLocal =>
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).ToAbsolutePath();
public static AbsolutePath WindowsSystem32 => Environment.GetFolderPath(Environment.SpecialFolder.System).ToAbsolutePath();
public static AbsolutePath WabbajackAppLocal => AppDataLocal.Combine("Wabbajack");
public static AbsolutePath CurrentDirectory => Directory.GetCurrentDirectory().ToAbsolutePath();
public static AbsolutePath Windows => Environment.GetFolderPath(Environment.SpecialFolder.Windows).ToAbsolutePath();
}

View File

@ -2,7 +2,6 @@ using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
@ -11,9 +10,9 @@ namespace Wabbajack.RateLimiter;
public class Resource<T> : IResource<T>
{
private Channel<PendingReport> _channel;
private SemaphoreSlim _semaphore;
private ConcurrentDictionary<ulong, Job<T>> _tasks;
private readonly Channel<PendingReport> _channel;
private readonly SemaphoreSlim _semaphore;
private readonly ConcurrentDictionary<ulong, Job<T>> _tasks;
private ulong _nextId;
private long _totalUsed;
@ -23,6 +22,7 @@ public class Resource<T> : IResource<T>
Name = humanName ?? "<unknown>";
MaxTasks = maxTasks ?? Environment.ProcessorCount;
MaxThroughput = maxThroughput;
_semaphore = new SemaphoreSlim(MaxTasks);
_channel = Channel.CreateBounded<PendingReport>(10);
_tasks = new ConcurrentDictionary<ulong, Job<T>>();
@ -30,23 +30,6 @@ public class Resource<T> : IResource<T>
var tsk = StartTask(CancellationToken.None);
}
public Resource(string humanName, Func<Task<(int MaxTasks, long MaxThroughput)>> settingGetter)
{
Name = humanName;
_tasks = new ConcurrentDictionary<ulong, Job<T>>();
Task.Run(async () =>
{
var (maxTasks, maxThroughput) = await settingGetter();
MaxTasks = maxTasks;
MaxThroughput = maxThroughput;
_semaphore = new SemaphoreSlim(MaxTasks);
_channel = Channel.CreateBounded<PendingReport>(10);
await StartTask(CancellationToken.None);
});
}
public int MaxTasks { get; set; }
public long MaxThroughput { get; set; }
public string Name { get; }
@ -104,7 +87,7 @@ public class Resource<T> : IResource<T>
await foreach (var item in _channel.Reader.ReadAllAsync(token))
{
Interlocked.Add(ref _totalUsed, item.Size);
if (MaxThroughput is long.MaxValue or 0)
if (MaxThroughput == long.MaxValue)
{
item.Result.TrySetResult();
sw.Restart();

View File

@ -1,62 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Wabbajack.RateLimiter;
using Wabbajack.Services.OSIntegrated;
namespace Wabbajack.App.Models;
public class ResourceSettingsManager
{
private readonly SettingsManager _manager;
private Dictionary<string,ResourceSetting>? _settings;
public ResourceSettingsManager(SettingsManager manager)
{
_manager = manager;
}
private SemaphoreSlim _lock = new(1);
public async Task<ResourceSetting> GetSettings(string name)
{
await _lock.WaitAsync();
try
{
_settings ??= await _manager.Load<Dictionary<string, ResourceSetting>>("resource_settings");
if (_settings.TryGetValue(name, out var found)) return found;
var newSetting = new ResourceSetting
{
MaxTasks = Environment.ProcessorCount,
MaxThroughput = 0
};
_settings.Add(name, newSetting);
await _manager.Save("resource_settings", _settings);
return _settings[name];
}
finally
{
_lock.Release();
}
}
public class ResourceSetting
{
public long MaxTasks { get; set; }
public long MaxThroughput { get; set; }
}
public async Task SaveSettings(Dictionary<string, ResourceSetting> settings)
{
await _manager.Save("resource_settings", settings);
}
}

View File

@ -4,7 +4,6 @@ using System.Net.Http;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Wabbajack.App.Models;
using Wabbajack.Compiler;
using Wabbajack.Downloaders;
using Wabbajack.Downloaders.GameFile;
@ -55,28 +54,17 @@ public static class ServiceExtensions
: new BinaryPatchCache(KnownFolders.EntryPoint.Combine("patchCache.sqlite")));
service.AddSingleton(new ParallelOptions {MaxDegreeOfParallelism = Environment.ProcessorCount});
Func<Task<(int MaxTasks, long MaxThroughput)>> GetSettings(IServiceProvider provider, string name)
{
return async () =>
{
var s = await provider.GetService<ResourceSettingsManager>()!.GetSettings(name);
return ((int) s.MaxTasks, s.MaxThroughput);
};
}
service.AddAllSingleton<IResource, IResource<DownloadDispatcher>>(s =>
new Resource<DownloadDispatcher>("Downloads", GetSettings(s, "Downloads")));
service.AddAllSingleton<IResource, IResource<HttpClient>>(s => new Resource<HttpClient>("Web Requests", GetSettings(s, "Web Requests")));
service.AddAllSingleton<IResource, IResource<Context>>(s => new Resource<Context>("VFS", GetSettings(s, "VFS")));
new Resource<DownloadDispatcher>("Downloads", 12));
service.AddAllSingleton<IResource, IResource<HttpClient>>(s => new Resource<HttpClient>("Web Requests", 12));
service.AddAllSingleton<IResource, IResource<Context>>(s => new Resource<Context>("VFS", 12));
service.AddAllSingleton<IResource, IResource<FileHashCache>>(s =>
new Resource<FileHashCache>("File Hashing", GetSettings(s, "File Hashing")));
new Resource<FileHashCache>("File Hashing", 12));
service.AddAllSingleton<IResource, IResource<FileExtractor.FileExtractor>>(s =>
new Resource<FileExtractor.FileExtractor>("File Extractor", GetSettings(s, "File Extractor")));
new Resource<FileExtractor.FileExtractor>("File Extractor", 12));
service.AddAllSingleton<IResource, IResource<ACompiler>>(s =>
new Resource<ACompiler>("Compiler", GetSettings(s, "Compiler")));
new Resource<ACompiler>("Compiler", 12));
service.AddSingleton<LoggingRateLimiterReporter>();
@ -134,21 +122,6 @@ public static class ServiceExtensions
OSVersion = Environment.OSVersion.VersionString,
Version = version
});
// Settings
service.AddSingleton(s => new Configuration
{
EncryptedDataLocation = KnownFolders.WabbajackAppLocal.Combine("encrypted"),
ModListsDownloadLocation = KnownFolders.EntryPoint.Combine("downloaded_mod_lists"),
SavedSettingsLocation = KnownFolders.WabbajackAppLocal.Combine("saved_settings"),
LogLocation = KnownFolders.EntryPoint.Combine("logs"),
ImageCacheLocation = KnownFolders.WabbajackAppLocal.Combine("image_cache")
});
service.AddSingleton<SettingsManager>();
service.AddSingleton<ResourceSettingsManager>();
return service;
}