mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge branch 'main' into compiler-screens
This commit is contained in:
commit
53461f0183
8
Wabbajack.Launcher/.gitignore
vendored
Normal file
8
Wabbajack.Launcher/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
.idea/
|
||||
.vscode/
|
||||
.vs/
|
||||
|
||||
bin/
|
||||
obj/
|
||||
|
||||
*.user
|
12
Wabbajack.Launcher/App.axaml
Normal file
12
Wabbajack.Launcher/App.axaml
Normal 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>
|
29
Wabbajack.Launcher/App.axaml.cs
Normal file
29
Wabbajack.Launcher/App.axaml.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
BIN
Wabbajack.Launcher/Assets/Wabba_Mouth_Small.png
Normal file
BIN
Wabbajack.Launcher/Assets/Wabba_Mouth_Small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 58 KiB |
BIN
Wabbajack.Launcher/Assets/wabbajack.ico
Normal file
BIN
Wabbajack.Launcher/Assets/wabbajack.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 139 KiB |
3
Wabbajack.Launcher/FodyWeavers.xml
Normal file
3
Wabbajack.Launcher/FodyWeavers.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<ReactiveUI />
|
||||
</Weavers>
|
26
Wabbajack.Launcher/FodyWeavers.xsd
Normal file
26
Wabbajack.Launcher/FodyWeavers.xsd
Normal 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>
|
25
Wabbajack.Launcher/Program.cs
Normal file
25
Wabbajack.Launcher/Program.cs
Normal 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();
|
||||
}
|
||||
}
|
32
Wabbajack.Launcher/ViewLocator.cs
Normal file
32
Wabbajack.Launcher/ViewLocator.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
214
Wabbajack.Launcher/ViewModels/MainWindowViewModel.cs
Normal file
214
Wabbajack.Launcher/ViewModels/MainWindowViewModel.cs
Normal file
@ -0,0 +1,214 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Wabbajack.Paths;
|
||||
using Wabbajack.Paths.IO;
|
||||
|
||||
namespace Wabbajack.Launcher.ViewModels
|
||||
{
|
||||
public class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
[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");
|
||||
|
||||
private Release _version;
|
||||
private List<string> _errors = new();
|
||||
|
||||
private async Task CheckForUpdates()
|
||||
{
|
||||
_client.Headers.Add ("user-agent", "Wabbajack Launcher");
|
||||
Status = "Selecting Release";
|
||||
|
||||
try
|
||||
{
|
||||
var releases = await GetReleases();
|
||||
_version = releases.OrderByDescending(r =>
|
||||
{
|
||||
if (r.Tag.Split(".").Length == 4 && Version.TryParse(r.Tag, out var v))
|
||||
return v;
|
||||
return new Version(0, 0, 0, 0);
|
||||
}).FirstOrDefault();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_errors.Add(ex.Message);
|
||||
await FinishAndExit();
|
||||
}
|
||||
|
||||
if (_version == null)
|
||||
{
|
||||
_errors.Add("Unable to parse Github releases");
|
||||
await FinishAndExit();
|
||||
}
|
||||
|
||||
Status = "Looking for Updates";
|
||||
|
||||
var base_folder = Path.Combine(Directory.GetCurrentDirectory(), _version.Tag);
|
||||
|
||||
if (File.Exists(Path.Combine(base_folder, "Wabbajack.exe")))
|
||||
{
|
||||
await FinishAndExit();
|
||||
}
|
||||
|
||||
var asset = _version.Assets.FirstOrDefault(a => a.Name == _version.Tag + ".zip");
|
||||
if (asset == null)
|
||||
{
|
||||
_errors.Add("No zip file for release " + _version.Tag);
|
||||
await FinishAndExit();
|
||||
}
|
||||
|
||||
var wc = new WebClient();
|
||||
wc.DownloadProgressChanged += UpdateProgress;
|
||||
Status = $"Downloading {_version.Tag} ...";
|
||||
byte[] data;
|
||||
try
|
||||
{
|
||||
data = await wc.DownloadDataTaskAsync(asset.BrowserDownloadUrl);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_errors.Add(ex.Message);
|
||||
// Something went wrong so fallback to original URL
|
||||
try
|
||||
{
|
||||
data = await wc.DownloadDataTaskAsync(asset.BrowserDownloadUrl);
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
_errors.Add(ex2.Message);
|
||||
await FinishAndExit();
|
||||
throw; // avoid unsigned variable 'data'
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var zip = new ZipArchive(new MemoryStream(data), ZipArchiveMode.Read))
|
||||
{
|
||||
foreach (var entry in zip.Entries)
|
||||
{
|
||||
Status = $"Extracting: {entry.Name}";
|
||||
var outPath = Path.Combine(base_folder, entry.FullName);
|
||||
if (!Directory.Exists(Path.GetDirectoryName(outPath)))
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(outPath));
|
||||
|
||||
if (entry.FullName.EndsWith("/") || entry.FullName.EndsWith("\\"))
|
||||
continue;
|
||||
await using var o = entry.Open();
|
||||
await using var of = File.Create(outPath);
|
||||
await o.CopyToAsync(of);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_errors.Add(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await FinishAndExit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task FinishAndExit()
|
||||
{
|
||||
try
|
||||
{
|
||||
Status = "Launching...";
|
||||
var wjFolder = KnownFolders.CurrentDirectory.EnumerateDirectories()
|
||||
.OrderByDescending(v =>
|
||||
Version.TryParse(v.FileName.ToString(), out var ver) ? ver : new Version(0, 0, 0, 0))
|
||||
.FirstOrDefault();
|
||||
|
||||
var filename = wjFolder.Combine("Wabbajack.exe");
|
||||
await CreateBatchFile(filename);
|
||||
var info = new ProcessStartInfo
|
||||
{
|
||||
FileName = filename.ToString(),
|
||||
Arguments = string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Select(s => s.Contains(' ') ? '\"' + s + '\"' : s)),
|
||||
WorkingDirectory = wjFolder.ToString(),
|
||||
};
|
||||
Process.Start(info);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (_errors.Count == 0)
|
||||
{
|
||||
Status = "Failed: Unknown error";
|
||||
await Task.Delay(10000);
|
||||
}
|
||||
foreach (var error in _errors)
|
||||
{
|
||||
Status = "Failed: " + error;
|
||||
await Task.Delay(10000);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CreateBatchFile(AbsolutePath filename)
|
||||
{
|
||||
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;
|
||||
await File.WriteAllTextAsync(file, data);
|
||||
}
|
||||
|
||||
private void UpdateProgress(object sender, DownloadProgressChangedEventArgs e)
|
||||
{
|
||||
Status = $"Downloading {_version.Tag} ({e.ProgressPercentage}%)...";
|
||||
}
|
||||
|
||||
private async Task<Release[]> GetReleases()
|
||||
{
|
||||
Status = "Checking GitHub Repository";
|
||||
var data = await _client.DownloadStringTaskAsync(GITHUB_REPO);
|
||||
Status = "Parsing Response";
|
||||
return JsonSerializer.Deserialize<Release[]>(data)!;
|
||||
}
|
||||
|
||||
|
||||
class Release
|
||||
{
|
||||
[JsonPropertyName("tag_name")]
|
||||
public string Tag { get; set; }
|
||||
|
||||
[JsonPropertyName("assets")]
|
||||
public Asset[] Assets { get; set; }
|
||||
|
||||
}
|
||||
|
||||
class Asset
|
||||
{
|
||||
[JsonPropertyName("browser_download_url")]
|
||||
public Uri BrowserDownloadUrl { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Wabbajack.Launcher/ViewModels/ViewModelBase.cs
Normal file
11
Wabbajack.Launcher/ViewModels/ViewModelBase.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Wabbajack.Launcher.ViewModels
|
||||
{
|
||||
public class ViewModelBase : ReactiveObject
|
||||
{
|
||||
}
|
||||
}
|
27
Wabbajack.Launcher/Views/MainWindow.axaml
Normal file
27
Wabbajack.Launcher/Views/MainWindow.axaml
Normal 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>
|
22
Wabbajack.Launcher/Views/MainWindow.axaml.cs
Normal file
22
Wabbajack.Launcher/Views/MainWindow.axaml.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
24
Wabbajack.Launcher/Wabbajack.Launcher.csproj
Normal file
24
Wabbajack.Launcher/Wabbajack.Launcher.csproj
Normal file
@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<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>
|
@ -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();
|
||||
}
|
||||
}
|
@ -114,6 +114,8 @@ EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Downloaders.GameFile", "Wabbajack.Downloaders.GameFile\Wabbajack.Downloaders.GameFile.csproj", "{4F252332-CA77-41DE-95A8-9DF38A81D675}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Launcher", "Wabbajack.Launcher\Wabbajack.Launcher.csproj", "{23D49FCC-A6CB-4873-879B-F90DA1871AA3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -316,6 +318,10 @@ Global
|
||||
{4F252332-CA77-41DE-95A8-9DF38A81D675}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4F252332-CA77-41DE-95A8-9DF38A81D675}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4F252332-CA77-41DE-95A8-9DF38A81D675}.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}
|
||||
|
Loading…
Reference in New Issue
Block a user