mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Move config code into OSIntegrated
This commit is contained in:
parent
3d92b44f9f
commit
5fc070e5d3
@ -9,6 +9,7 @@
|
||||
<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" />
|
||||
|
@ -21,6 +21,7 @@ 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;
|
||||
|
@ -5,6 +5,7 @@ using System.Timers;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.App.ViewModels;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.RateLimiter;
|
||||
|
||||
namespace Wabbajack.App.Controls;
|
||||
@ -18,7 +19,7 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab
|
||||
{
|
||||
Activator = new ViewModelActivator();
|
||||
_resource = resource;
|
||||
_timer = new Timer(1.0);
|
||||
_timer = new Timer(250);
|
||||
|
||||
Name = resource.Name;
|
||||
|
||||
@ -50,6 +51,8 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab
|
||||
[Reactive] public long CurrentThroughput { get; set; }
|
||||
|
||||
[Reactive] public string Name { get; set; }
|
||||
|
||||
[Reactive] public string ThroughputHumanFriendly { get; set; }
|
||||
|
||||
|
||||
public void Dispose()
|
||||
@ -62,5 +65,6 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab
|
||||
MaxTasks = _resource.MaxTasks;
|
||||
MaxThroughput = _resource.MaxThroughput;
|
||||
CurrentThroughput = _resource.StatusReport.Transferred;
|
||||
ThroughputHumanFriendly = _resource.StatusReport.Transferred.ToFileSizeString();
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ 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;
|
||||
|
@ -31,7 +31,7 @@ namespace Wabbajack.App.Screens;
|
||||
|
||||
public class BrowseViewModel : ViewModelBase, IActivatableViewModel
|
||||
{
|
||||
private readonly Configuration _configuration;
|
||||
private readonly Wabbajack.Services.OSIntegrated.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, Configuration configuration)
|
||||
DTOSerializer dtos, Wabbajack.Services.OSIntegrated.Configuration configuration)
|
||||
{
|
||||
LoadingLock = new LoadingLock();
|
||||
Activator = new ViewModelActivator();
|
||||
|
@ -18,6 +18,7 @@ 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;
|
||||
|
@ -38,18 +38,26 @@
|
||||
<Grid RowDefinitions="Auto, Auto">
|
||||
<TextBlock FontSize="20" Grid.ColumnSpan="4">Resource Limits</TextBlock>
|
||||
|
||||
<ItemsControl Grid.Row="1" x:Name="ResourceList">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Vertical" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<controls:ResourceView />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<DataGrid Grid.Row="1" AutoGenerateColumns="False" x:Name="ResourcesList">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTemplateColumn Header="Resource">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}" FontWeight="Bold"></TextBlock>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Header="Maximum Tasks" Binding="{Binding MaxTasks}"></DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Maximum Throughput" Binding="{Binding MaxThroughput}"></DataGridTextColumn>
|
||||
<DataGridTemplateColumn Header="Transferred">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding TransferredHumanFriendly}"></TextBlock>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
</Grid>
|
||||
</Border>
|
||||
|
@ -28,8 +28,9 @@ public partial class SettingsView : ScreenBase<SettingsViewModel>
|
||||
.DisposeWith(disposables);
|
||||
|
||||
|
||||
this.OneWayBind(ViewModel, vm => vm.Resources, view => view.ResourceList.Items)
|
||||
this.OneWayBind(ViewModel, vm => vm.Resources, view => view.ResourcesList.Items)
|
||||
.DisposeWith(disposables);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ using Wabbajack.App.ViewModels;
|
||||
using Wabbajack.Paths;
|
||||
using Wabbajack.Paths.IO;
|
||||
using Wabbajack.RateLimiter;
|
||||
using Wabbajack.Services.OSIntegrated;
|
||||
using Wabbajack.Services.OSIntegrated.TokenProviders;
|
||||
|
||||
namespace Wabbajack.App.Screens;
|
||||
@ -27,11 +28,18 @@ public class SettingsViewModel : ViewModelBase
|
||||
NexusApiTokenProvider nexusProvider, IEnumerable<IResource> resources, LoversLabTokenProvider llProvider, VectorPlexusTokenProvider vpProvider)
|
||||
{
|
||||
_logger = logger;
|
||||
Resources = resources.Select(r => new ResourceViewModel(r)).ToArray();
|
||||
Resources = resources.Select(r => new ResourceViewModel(r))
|
||||
.OrderBy(o => o.Name)
|
||||
.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);
|
||||
|
@ -93,17 +93,6 @@ 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;
|
||||
|
@ -10,6 +10,7 @@ using DynamicData;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Wabbajack.Paths;
|
||||
using Wabbajack.Paths.IO;
|
||||
using Wabbajack.Services.OSIntegrated;
|
||||
|
||||
namespace Wabbajack.App.Utilities;
|
||||
|
||||
|
@ -20,6 +20,7 @@ using Wabbajack.DTOs.SavedSettings;
|
||||
using Wabbajack.Installer;
|
||||
using Wabbajack.Paths;
|
||||
using Wabbajack.Paths.IO;
|
||||
using Wabbajack.Services.OSIntegrated;
|
||||
|
||||
namespace Wabbajack.App.ViewModels;
|
||||
|
||||
|
@ -46,7 +46,6 @@ 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();
|
||||
|
@ -4,6 +4,7 @@ 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;
|
||||
|
||||
|
@ -4,6 +4,7 @@ using Wabbajack.Downloaders.IPS4OAuth2Downloader;
|
||||
using Wabbajack.Downloaders.MediaFire;
|
||||
using Wabbajack.Downloaders.ModDB;
|
||||
using Wabbajack.DTOs.JsonConverters;
|
||||
using Wabbajack.Networking.WabbajackClientApi;
|
||||
|
||||
namespace Wabbajack.Downloaders;
|
||||
|
||||
@ -23,6 +24,7 @@ public static class ServiceExtensions
|
||||
.AddIPS4OAuth2Downloaders()
|
||||
.AddWabbajackCDNDownloader()
|
||||
.AddGameFileDownloader()
|
||||
.AddWabbajackClient()
|
||||
.AddSingleton<DownloadDispatcher>();
|
||||
}
|
||||
}
|
@ -4,9 +4,10 @@ namespace Wabbajack.Networking.WabbajackClientApi;
|
||||
|
||||
public static class ServiceExtensions
|
||||
{
|
||||
public static void AddWabbajackClient(this IServiceCollection services)
|
||||
public static IServiceCollection AddWabbajackClient(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<Configuration>();
|
||||
services.AddSingleton<Client>();
|
||||
return services;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using Wabbajack.Paths;
|
||||
|
||||
namespace Wabbajack.App;
|
||||
namespace Wabbajack.Services.OSIntegrated;
|
||||
|
||||
public class Configuration
|
||||
{
|
55
Wabbajack.Services.OSIntegrated/ResourceSettingsManager.cs
Normal file
55
Wabbajack.Services.OSIntegrated/ResourceSettingsManager.cs
Normal file
@ -0,0 +1,55 @@
|
||||
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;
|
||||
}
|
||||
|
||||
public async Task<ResourceSetting> GetSettings(string name)
|
||||
{
|
||||
Monitor.Enter(_manager);
|
||||
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 = long.MaxValue
|
||||
};
|
||||
|
||||
_settings.Add(name, newSetting);
|
||||
|
||||
await _manager.Save("resource-settings", _settings);
|
||||
|
||||
return _settings[name];
|
||||
}
|
||||
finally
|
||||
{
|
||||
Monitor.Exit(_manager);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ResourceSetting
|
||||
{
|
||||
public long MaxTasks { get; set; }
|
||||
public long MaxThroughput { get; set; }
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ 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;
|
||||
@ -122,6 +123,21 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ using Wabbajack.DTOs.JsonConverters;
|
||||
using Wabbajack.Paths;
|
||||
using Wabbajack.Paths.IO;
|
||||
|
||||
namespace Wabbajack.App.Models;
|
||||
namespace Wabbajack.Services.OSIntegrated;
|
||||
|
||||
public class SettingsManager
|
||||
{
|
Loading…
Reference in New Issue
Block a user