Add reworked launcher

This commit is contained in:
Timothy Baldridge 2021-10-08 07:16:51 -06:00
parent 03b3ec498d
commit 282327e81d
21 changed files with 251 additions and 1315 deletions

8
Wabbajack.Launcher/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
.idea/
.vscode/
.vs/
bin/
obj/
*.user

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Wabbajack.Launcher"
x:Class="Wabbajack.Launcher.App">
<Application.DataTemplates>
<local:ViewLocator/>
</Application.DataTemplates>
<Application.Styles>
<FluentTheme Mode="Light"/>
</Application.Styles>
</Application>

View File

@ -0,0 +1,29 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Wabbajack.Launcher.ViewModels;
using Wabbajack.Launcher.Views;
namespace Wabbajack.Launcher
{
public class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
};
}
base.OnFrameworkInitializationCompleted();
}
}
}

View File

@ -1,8 +0,0 @@
<Application x:Class="Wabbajack.Launcher.App"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Wabbajack.Launcher"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@ -1,11 +0,0 @@
using Avalonia;
namespace Wabbajack.Launcher
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

View File

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

View File

Before

Width:  |  Height:  |  Size: 139 KiB

After

Width:  |  Height:  |  Size: 139 KiB

View File

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ReactiveUI />
</Weavers>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ReactiveUI" minOccurs="0" maxOccurs="1" type="xs:anyType" />
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@ -1,23 +0,0 @@
<Window x:Class="Wabbajack.Launcher.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Wabbajack.Launcher"
mc:Ignorable="d"
Title="Wabbajack Launcher" Height="320" Width="600"
WindowStyle="None"
Background="#121212"
BorderThickness="0"
AllowsTransparency="False"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="275"></RowDefinition>
<RowDefinition Height="45"></RowDefinition>
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="Wabba_Mouth_Small.png"></Image>
<Label Grid.Row="1" Foreground="White" FontSize="20" Content="{Binding Status}"></Label>
</Grid>
</Window>

View File

@ -1,25 +0,0 @@
using System;
using Avalonia.Controls;
namespace Wabbajack.Launcher
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
try
{
DataContext = new MainWindowVM();
}
catch(Exception ex)
{
System.Console.Error.WriteLine("Error creating datacontext.");
System.Console.Error.WriteLine(ex);
throw;
}
}
}
}

View File

@ -0,0 +1,25 @@
using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;
namespace Wabbajack.Launcher
{
// To Build : dotnet publish -r win-x64 -c Release -p:PublishReadyToRun=true --self-contained -o c:\tmp\publish -p:PublishSingleFile=true -p:DebugType=embedded -p:IncludeAllContentForSelfExtract=true
class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
}
}

View File

@ -0,0 +1,32 @@
using System;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Wabbajack.Launcher.ViewModels;
namespace Wabbajack.Launcher
{
public class ViewLocator : IDataTemplate
{
public bool SupportsRecycling => false;
public IControl Build(object data)
{
var name = data.GetType().FullName!.Replace("ViewModel", "View");
var type = Type.GetType(name);
if (type != null)
{
return (Control)Activator.CreateInstance(type)!;
}
else
{
return new TextBlock { Text = "Not Found: " + name };
}
}
public bool Match(object data)
{
return data is ViewModelBase;
}
}
}

View File

@ -1,51 +1,36 @@
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.ComponentModel;
using System.Threading.Tasks;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
namespace Wabbajack.Launcher
namespace Wabbajack.Launcher.ViewModels
{
public class MainWindowVM : INotifyPropertyChanged
public class MainWindowViewModel : ViewModelBase
{
public event PropertyChangedEventHandler PropertyChanged;
[Reactive]
public string Status { get; set; }
public MainWindowViewModel()
{
Status = "Checking for new versions";
var tsk = CheckForUpdates();
}
private WebClient _client = new();
public Uri GITHUB_REPO = new("https://api.github.com/repos/wabbajack-tools/wabbajack/releases");
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string _status = "Checking for Updates";
private Release _version;
private List<string> _errors = new List<string>();
public string Status
{
set
{
_status = value;
OnPropertyChanged("Status");
}
get
{
return _status;
}
}
public MainWindowVM()
{
Task.Run(CheckForUpdates);
}
private List<string> _errors = new();
private async Task CheckForUpdates()
{
@ -149,18 +134,18 @@ namespace Wabbajack.Launcher
try
{
Status = "Launching...";
var wjFolder = Directory.EnumerateDirectories(Directory.GetCurrentDirectory())
var wjFolder = KnownFolders.CurrentDirectory.EnumerateDirectories()
.OrderByDescending(v =>
Version.TryParse(Path.GetFileName(v), out var ver) ? ver : new Version(0, 0, 0, 0))
Version.TryParse(v.FileName.ToString(), out var ver) ? ver : new Version(0, 0, 0, 0))
.FirstOrDefault();
var filename = Path.Combine(wjFolder, "Wabbajack.exe");
var filename = wjFolder.Combine("Wabbajack.exe");
await CreateBatchFile(filename);
var info = new ProcessStartInfo
{
FileName = filename,
FileName = filename.ToString(),
Arguments = string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Select(s => s.Contains(' ') ? '\"' + s + '\"' : s)),
WorkingDirectory = wjFolder,
WorkingDirectory = wjFolder.ToString(),
};
Process.Start(info);
}
@ -183,9 +168,9 @@ namespace Wabbajack.Launcher
}
}
private async Task CreateBatchFile(string filename)
private async Task CreateBatchFile(AbsolutePath filename)
{
filename = Path.Combine(Path.GetDirectoryName(filename), "wabbajack-cli.exe");
filename = filename.Parent.Combine("wabbajack-cli.exe");
var data = $"\"{filename}\" %*";
var file = Path.Combine(Directory.GetCurrentDirectory(), "wabbajack-cli.bat");
if (File.Exists(file) && await File.ReadAllTextAsync(file) == data) return;
@ -224,5 +209,6 @@ namespace Wabbajack.Launcher
[JsonPropertyName("name")]
public string Name { get; set; }
}
}
}

View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
using ReactiveUI;
namespace Wabbajack.Launcher.ViewModels
{
public class ViewModelBase : ReactiveObject
{
}
}

View File

@ -0,0 +1,27 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:Wabbajack.Launcher.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.Launcher.Views.MainWindow"
Icon="/Assets/wabbajack.ico"
Title="Wabbajack Launcher" Height="320" Width="600"
Background="#121212"
BorderThickness="0"
WindowStartupLocation="CenterScreen"
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaChromeHints="NoChrome"
ExtendClientAreaTitleBarHeightHint="-1"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="275"></RowDefinition>
<RowDefinition Height="45"></RowDefinition>
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="/Assets/Wabba_Mouth_Small.png"></Image>
<Label Grid.Row="1" Margin="4" Foreground="White" FontSize="20" Content="{Binding Status}"></Label>
</Grid>
</Window>

View File

@ -0,0 +1,22 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Wabbajack.Launcher.Views
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}

View File

@ -1,40 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework Condition=" '$(OS)' == 'Windows_NT'">net6.0-windows</TargetFramework>
<TargetFramework Condition=" '$(OS)' != 'Windows_NT'">net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<AssemblyVersion>2.5.3.1</AssemblyVersion>
<FileVersion>2.5.3.1</FileVersion>
<Copyright>Copyright © 2019-2020</Copyright>
<Description>Wabbajack Application Launcher</Description>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
<AssemblyName>Wabbajack</AssemblyName>
<RootNamespace>Wabbajack</RootNamespace>
<IncludeSymbolsInSingleFile>false</IncludeSymbolsInSingleFile>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<TrimMode>Link</TrimMode>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\Icons\wabbajack.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<None Remove="Wabba_Mouth_Small.png" />
<Resource Include="Wabba_Mouth_Small.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.7" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.7" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
</ItemGroup>
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework Condition=" '$(OS)' == 'Windows_NT'">net6.0-windows</TargetFramework>
<TargetFramework Condition=" '$(OS)' != 'Windows_NT'">net6.0</TargetFramework>
<Nullable>enable</Nullable>
<TargetName>Wabbajack.exe</TargetName>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\" />
<AvaloniaResource Include="Assets\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.3" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.3" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.3" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.3" />
<PackageReference Include="ReactiveUI.Fody" Version="16.2.6" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Wabbajack.Paths.IO\Wabbajack.Paths.IO.csproj" />
<ProjectReference Include="..\Wabbajack.Paths\Wabbajack.Paths.csproj" />
</ItemGroup>
</Project>

View File

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Reflection;
namespace Wabbajack.Paths.IO
@ -11,6 +12,6 @@ namespace Wabbajack.Paths.IO
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).ToAbsolutePath();
public static AbsolutePath WabbajackAppLocal => AppDataLocal.Combine("Wabbajack");
public static AbsolutePath CurrentDirectory => Directory.GetCurrentDirectory().ToAbsolutePath();
}
}

View File

@ -112,7 +112,7 @@ ProjectSection(SolutionItems) = preProject
nuget.config = nuget.config
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Launcher", "Wabbajack.Launcher\Wabbajack.Launcher.csproj", "{8A4B3B2F-01EC-4C47-9470-FC06DF162D4D}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Launcher", "Wabbajack.Launcher\Wabbajack.Launcher.csproj", "{23D49FCC-A6CB-4873-879B-F90DA1871AA3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -312,10 +312,10 @@ Global
{DEB4B073-4EAA-49FD-9D43-F0F8CB930E7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DEB4B073-4EAA-49FD-9D43-F0F8CB930E7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DEB4B073-4EAA-49FD-9D43-F0F8CB930E7A}.Release|Any CPU.Build.0 = Release|Any CPU
{8A4B3B2F-01EC-4C47-9470-FC06DF162D4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A4B3B2F-01EC-4C47-9470-FC06DF162D4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A4B3B2F-01EC-4C47-9470-FC06DF162D4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A4B3B2F-01EC-4C47-9470-FC06DF162D4D}.Release|Any CPU.Build.0 = Release|Any CPU
{23D49FCC-A6CB-4873-879B-F90DA1871AA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23D49FCC-A6CB-4873-879B-F90DA1871AA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23D49FCC-A6CB-4873-879B-F90DA1871AA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23D49FCC-A6CB-4873-879B-F90DA1871AA3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4057B668-8595-44FE-9805-007B284A838F} = {98B731EE-4FC0-4482-A069-BCBA25497871}