Merge pull request #488 from wabbajack-tools/launcher-first-spike

Launcher first spike
This commit is contained in:
Timothy Baldridge 2020-02-07 18:23:01 -07:00 committed by GitHub
commit 6703b4090e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 1457 additions and 10 deletions

View File

@ -100,5 +100,7 @@ namespace Wabbajack.Common
public static int WabbajackCachePort = 80; public static int WabbajackCachePort = 80;
public static int MaxHTTPRetries = 4; public static int MaxHTTPRetries = 4;
public const string MO2ModFolderName = "mods"; public const string MO2ModFolderName = "mods";
public static string PatchCacheFolder => Path.Combine(LocalAppDataPath, "patch_cache");
} }
} }

View File

@ -824,9 +824,9 @@ namespace Wabbajack.Common
{ {
var dataA = a.xxHash().FromBase64().ToHex(); var dataA = a.xxHash().FromBase64().ToHex();
var dataB = b.xxHash().FromBase64().ToHex(); var dataB = b.xxHash().FromBase64().ToHex();
var cacheFile = Path.Combine("patch_cache", $"{dataA}_{dataB}.patch"); var cacheFile = Path.Combine(Consts.PatchCacheFolder, $"{dataA}_{dataB}.patch");
if (!Directory.Exists("patch_cache")) if (!Directory.Exists(Consts.PatchCacheFolder))
Directory.CreateDirectory("patch_cache"); Directory.CreateDirectory(Consts.PatchCacheFolder);
while (true) while (true)
{ {
@ -837,7 +837,7 @@ namespace Wabbajack.Common
} }
else else
{ {
var tmpName = Path.Combine("patch_cache", Guid.NewGuid() + ".tmp"); var tmpName = Path.Combine(Consts.PatchCacheFolder, Guid.NewGuid() + ".tmp");
await using (var f = File.Open(tmpName, System.IO.FileMode.Create)) await using (var f = File.Open(tmpName, System.IO.FileMode.Create))
{ {
@ -867,7 +867,7 @@ namespace Wabbajack.Common
public static bool TryGetPatch(string foundHash, string fileHash, out byte[] ePatch) public static bool TryGetPatch(string foundHash, string fileHash, out byte[] ePatch)
{ {
var patchName = Path.Combine("patch_cache", var patchName = Path.Combine(Consts.PatchCacheFolder,
$"{foundHash.FromBase64().ToHex()}_{fileHash.FromBase64().ToHex()}.patch"); $"{foundHash.FromBase64().ToHex()}_{fileHash.FromBase64().ToHex()}.patch");
if (File.Exists(patchName)) if (File.Exists(patchName))
{ {

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
<Application x:Class="Wabbajack.Launcher.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace Wabbajack.Launcher
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

View File

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@ -0,0 +1,23 @@
<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

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Wabbajack.Launcher
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
DataContext = new MainWindowVM();
InitializeComponent();
}
}
}

View File

@ -0,0 +1,155 @@
using System;
using System.ComponentModel;
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 Newtonsoft.Json;
using Wabbajack.Launcher.Annotations;
namespace Wabbajack.Launcher
{
public class MainWindowVM : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private WebClient _client = new WebClient();
public Uri GITHUB_REPO = new Uri("https://api.github.com/repos/wabbajack-tools/temp-releases/releases");
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string _status = "Checking for Updates";
private Release _version;
public string Status
{
set
{
_status = value;
OnPropertyChanged("Status");
}
get
{
return _status;
}
}
public MainWindowVM()
{
Task.Run(CheckForUpdates);
}
private async Task CheckForUpdates()
{
_client.Headers.Add ("user-agent", "Wabbajack Launcher");
Status = "Selecting Release";
try
{
var releases = await GetReleases();
_version = releases.OrderByDescending(r =>
{
if (Version.TryParse(r.Tag, out var v))
return v;
return new Version(0, 0, 0, 0);
}).FirstOrDefault();
}
catch (Exception)
{
FinishAndExit();
}
if (_version == null)
FinishAndExit();
Status = "Looking for Updates";
var base_folder = Path.Combine(Directory.GetCurrentDirectory(), _version.Tag);
if (File.Exists(Path.Combine(base_folder, "Wabbajack.exe")))
FinishAndExit();
var asset = _version.Assets.FirstOrDefault(a => a.Name == _version.Tag + ".zip");
if (asset == null)
FinishAndExit();
var wc = new WebClient();
wc.DownloadProgressChanged += UpdateProgress;
Status = $"Downloading {_version.Tag} ...";
var data = await wc.DownloadDataTaskAsync(asset.BrowserDownloadUrl);
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);
}
}
FinishAndExit();
}
private void FinishAndExit()
{
Status = "Launching...";
var wjFolder = Directory.EnumerateDirectories(Directory.GetCurrentDirectory())
.OrderByDescending(v =>
Version.TryParse(Path.GetFileName(v), out var ver) ? ver : new Version(0, 0, 0, 0))
.FirstOrDefault();
var info = new ProcessStartInfo
{
FileName = Path.Combine(wjFolder, "Wabbajack.exe"),
WorkingDirectory = wjFolder,
};
Process.Start(info);
Environment.Exit(0);
}
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 JsonConvert.DeserializeObject<Release[]>(data);
}
class Release
{
[JsonProperty("tag_name")]
public string Tag { get; set; }
[JsonProperty("assets")]
public Asset[] Assets { get; set; }
}
class Asset
{
[JsonProperty("browser_download_url")]
public Uri BrowserDownloadUrl { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<AssemblyName>Wabbajack</AssemblyName>
<RootNamespace>Wabbajack</RootNamespace>
</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="Newtonsoft.Json" Version="9.0.1" />
</ItemGroup>
</Project>

View File

@ -22,7 +22,7 @@ namespace Wabbajack.Lib
public bool ReadmeIsWebsite; public bool ReadmeIsWebsite;
public string WabbajackVersion; public string WabbajackVersion;
protected static string _vfsCacheName = "vfs_compile_cache.bin"; protected static string _vfsCacheName => Path.Combine(Consts.LocalAppDataPath, "vfs_compile_cache.bin");
/// <summary> /// <summary>
/// A stream of tuples of ("Update Title", 0.25) which represent the name of the current task /// A stream of tuples of ("Update Title", 0.25) which represent the name of the current task
/// and the current progress. /// and the current progress.

View File

@ -88,7 +88,7 @@ namespace Wabbajack.Lib.LibCefHelpers
if (Inited) return; if (Inited) return;
Inited = true; Inited = true;
CefSettings settings = new CefSettings(); CefSettings settings = new CefSettings();
settings.CachePath = Path.Combine(Directory.GetCurrentDirectory() + @"\CEF"); settings.CachePath = Path.Combine(Consts.LocalAppDataPath + @"\CEF");
Cef.Initialize(settings); Cef.Initialize(settings);
} }

View File

@ -38,6 +38,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wabbajack.Test", "Wabbajack
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wabbajack.CLI", "Wabbajack.CLI\Wabbajack.CLI.csproj", "{685D8BB1-D178-4D2C-85C7-C54A36FB7454}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wabbajack.CLI", "Wabbajack.CLI\Wabbajack.CLI.csproj", "{685D8BB1-D178-4D2C-85C7-C54A36FB7454}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Launcher", "Wabbajack.Launcher\Wabbajack.Launcher.csproj", "{D6856DBF-C959-4867-A8A8-343DA2D2715E}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -118,6 +120,14 @@ Global
{685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Release|Any CPU.ActiveCfg = Release|x64 {685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Release|Any CPU.ActiveCfg = Release|x64
{685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Release|x64.ActiveCfg = Release|x64 {685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Release|x64.ActiveCfg = Release|x64
{685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Release|x64.Build.0 = Release|x64 {685D8BB1-D178-4D2C-85C7-C54A36FB7454}.Release|x64.Build.0 = Release|x64
{D6856DBF-C959-4867-A8A8-343DA2D2715E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6856DBF-C959-4867-A8A8-343DA2D2715E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6856DBF-C959-4867-A8A8-343DA2D2715E}.Debug|x64.ActiveCfg = Debug|Any CPU
{D6856DBF-C959-4867-A8A8-343DA2D2715E}.Debug|x64.Build.0 = Debug|Any CPU
{D6856DBF-C959-4867-A8A8-343DA2D2715E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6856DBF-C959-4867-A8A8-343DA2D2715E}.Release|Any CPU.Build.0 = Release|Any CPU
{D6856DBF-C959-4867-A8A8-343DA2D2715E}.Release|x64.ActiveCfg = Release|Any CPU
{D6856DBF-C959-4867-A8A8-343DA2D2715E}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=Wabbajack_002ELauncher_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -14,9 +14,9 @@
<StartupObject></StartupObject> <StartupObject></StartupObject>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<ApplicationIcon>Resources\Icons\wabbajack.ico</ApplicationIcon> <ApplicationIcon>Resources\Icons\wabbajack.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>