Skip to content

Commit

Permalink
Revert "Revert "Fix login logout buttons""
Browse files Browse the repository at this point in the history
This reverts commit e1b753e.
  • Loading branch information
halgari committed Nov 10, 2021
1 parent 81d775d commit 2661450
Show file tree
Hide file tree
Showing 28 changed files with 342 additions and 53 deletions.
1 change: 1 addition & 0 deletions Wabbajack.App/Controls/BrowseItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
using Wabbajack.Services.OSIntegrated;
using Wabbajack.VFS;

namespace Wabbajack.App.Controls;
Expand Down
1 change: 1 addition & 0 deletions Wabbajack.App/Models/ImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.RateLimiter;
using Wabbajack.Services.OSIntegrated;
using Wabbajack.VFS;

namespace Wabbajack.App.Models;
Expand Down
4 changes: 2 additions & 2 deletions Wabbajack.App/Screens/BrowseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,7 +54,7 @@ public BrowseViewModel(ILogger<BrowseViewModel> logger, Client wjClient, HttpCli
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();
Expand Down
1 change: 1 addition & 0 deletions Wabbajack.App/Screens/CompilerConfigurationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Wabbajack.Installer;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.Services.OSIntegrated;
using Consts = Wabbajack.Compiler.Consts;

namespace Wabbajack.App.Screens;
Expand Down
6 changes: 3 additions & 3 deletions Wabbajack.App/Screens/LauncherView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">Website</Button>
<Button Grid.Column="1" x:Name="ReadmeButton">Readme</Button>
<Button Grid.Column="2" x:Name="LocalFilesButton">Local Files</Button>
<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>
</Grid>

<controls:LargeIconButton x:Name="PlayGame" Margin="40, 0, 0, 0" Grid.Row="0" Grid.Column="2"
Expand Down
19 changes: 19 additions & 0 deletions Wabbajack.App/Screens/LauncherView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
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;

Expand All @@ -25,4 +29,19 @@ public LauncherView() : base("Launch Modlist")
.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);
}
}
34 changes: 20 additions & 14 deletions Wabbajack.App/Screens/SettingsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,28 @@
</Grid>
</Border>

<Border x:Name="ResourcesBorder" Margin="5" BorderThickness="1" Classes="Settings">
<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>
<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>

<ItemsRepeater Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" x:Name="ResourcesList" Margin="0, 4">
<ItemsRepeater.Layout>
<StackLayout></StackLayout>
</ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<controls:ResourceView />
<controls:ResourceView></controls:ResourceView>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</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>

</Grid>
</Border>
Expand Down
23 changes: 22 additions & 1 deletion Wabbajack.App/Screens/SettingsView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Reactive.Disposables;
using Avalonia.Interactivity;
using ReactiveUI;
using Wabbajack.App.Views;
using Wabbajack.Common;

namespace Wabbajack.App.Screens;

Expand All @@ -15,8 +17,27 @@ public SettingsView() : base("Settings")
.DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.NexusLogout, view => view.NexusLogOut)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.Resources, view => view.ResourceList.Items)

this.BindCommand(ViewModel, vm => vm.LoversLabLogin, view => view.LoversLabLogIn)
.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();
}
}
66 changes: 64 additions & 2 deletions Wabbajack.App/Screens/SettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
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;
Expand All @@ -22,16 +29,26 @@ 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,
NexusApiTokenProvider nexusProvider, IEnumerable<IResource> resources)
ResourceSettingsManager resourceSettingsManager,
NexusApiTokenProvider nexusProvider, IEnumerable<IResource> resources, LoversLabTokenProvider llProvider, VectorPlexusTokenProvider vpProvider)
{
_resourceSettingsManager = resourceSettingsManager;
_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);
Expand All @@ -50,16 +67,61 @@ public SettingsViewModel(ILogger<SettingsViewModel> logger, Configuration config
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);
}
}
11 changes: 10 additions & 1 deletion Wabbajack.App/Screens/StandardInstallationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,15 @@ private async Task Install(StartInstallation msg)
_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);
}
Expand All @@ -219,13 +226,15 @@ private async Task SaveConfigAndContinue(InstallerConfiguration config)
await image.CopyToAsync(os);
}


await _installStateManager.SetLastState(new InstallationConfigurationSetting
{
Downloads = config.Downloads,
Install = config.Install,
Metadata = config.Metadata,
ModList = config.ModlistArchive,
Image = path
Image = path,
StrippedModListData = config.ModList.Strip()
});

MessageBus.Current.SendMessage(new ConfigureLauncher(config.Install));
Expand Down
11 changes: 0 additions & 11 deletions Wabbajack.App/ServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,6 @@ public static IServiceCollection AddAppServices(this IServiceCollection services
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;
Expand Down
1 change: 1 addition & 0 deletions Wabbajack.App/Utilities/LoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Extensions.Logging;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
using Wabbajack.Services.OSIntegrated;

namespace Wabbajack.App.Utilities;

Expand Down
38 changes: 38 additions & 0 deletions Wabbajack.App/Utilities/OSUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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();
}
}
}
Loading

0 comments on commit 2661450

Please sign in to comment.