Merge pull request #1364 from wabbajack-tools/launcher-updater

Launcher updater
This commit is contained in:
Timothy Baldridge 2021-03-11 09:29:33 -07:00 committed by GitHub
commit 47ba907c4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 155 additions and 21 deletions

View File

@ -18,7 +18,7 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.0-preview1" />
<PackageReference Include="F23.StringSimilarity" Version="3.1.0" />
<PackageReference Include="F23.StringSimilarity" Version="4.0.0" />
<PackageReference Include="Markdig" Version="0.23.0" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="System.Reactive.Linq" Version="5.0.0" />

View File

@ -59,6 +59,8 @@ namespace Wabbajack.Common
public static string DOWNLOAD_PATH_MAGIC_BACK = "{--||DOWNLOAD_PATH_MAGIC_BACK||--}";
public static string DOWNLOAD_PATH_MAGIC_DOUBLE_BACK = "{--||DOWNLOAD_PATH_MAGIC_DOUBLE_BACK||--}";
public static string DOWNLOAD_PATH_MAGIC_FORWARD = "{--||DOWNLOAD_PATH_MAGIC_FORWARD||--}";
public static Uri GITHUB_REPO_RELEASES = new Uri("https://api.github.com/repos/wabbajack-tools/wabbajack/releases");
public static string AppName = "Wabbajack";

View File

@ -49,7 +49,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Genbox.AlphaFS" Version="2.2.2.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.30" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.31" />
<PackageReference Include="ini-parser-netstandard" Version="2.5.2" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />

View File

@ -158,5 +158,19 @@ namespace Wabbajack.Lib.Http
{
Cookies.AddRange(cookies.Select(c => new Cookie {Domain = c.Domain, Name = c.Name, Value = c.Value, Path = c.Path}));
}
public void UseChromeUserAgent()
{
Headers.Add(("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36"));
}
public async Task DownloadAsync(Uri url, AbsolutePath path)
{
using var response = await GetAsync(url);
await using var content = await response.Content.ReadAsStreamAsync();
path.Parent.CreateDirectory();
await using var of = await path.Create();
await content.CopyToAsync(of);
}
}
}

View File

@ -0,0 +1,114 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Wabbajack.Common;
using Wabbajack.Lib.Http;
namespace Wabbajack.Lib
{
public class LauncherUpdater
{
public static async Task Run()
{
var entryPoint = AbsolutePath.EntryPoint;
// If we're not in a folder that looks like a version, abort
if (!Version.TryParse(entryPoint.FileName.ToString(), out var version))
{
Utils.Log($"Not in a version folder, not attempting update. Got {entryPoint.Parent}");
return;
}
// If we're not in a folder that has Wabbajack.exe in the parent folder, abort
if (!entryPoint.Parent.Parent.Combine(Consts.AppName).WithExtension(new Extension(".exe")).IsFile)
{
Utils.Log("Parent folder does not contain launcher, not updating");
return;
}
var oldVersions = entryPoint.Parent
.EnumerateDirectories()
.Select(f => Version.TryParse(f.FileName.ToString(), out var ver) ? (ver, f) : default)
.Where(f => f != default)
.Where(f => f.ver < version)
.Select(f => f!)
.OrderByDescending(f => f)
.Skip(2)
.ToArray();
foreach (var (_, path) in oldVersions)
{
Utils.Log($"Deleting old Wabbajack version at: {path}");
await path.DeleteDirectory();
}
var release = (await GetReleases())
.Select(release => Version.TryParse(release.Tag, out version) ? (version, release) : default)
.Where(r => r != default)
.OrderByDescending(r => r.version)
.Select(r =>
{
var (version, release) = r;
var asset = release.Assets.FirstOrDefault(a => a.Name == "Wabbajack.exe");
return asset != default ? (version, release, asset) : default;
})
.FirstOrDefault();
var launcherFolder = AbsolutePath.EntryPoint.Parent;
var exePath = launcherFolder.Combine("Wabbajack.exe");
var launcherVersion = FileVersionInfo.GetVersionInfo(exePath.ToString());
if (release != default && launcherVersion != null && release.version > Version.Parse(launcherVersion.FileVersion!))
{
Utils.Log($"Updating Launcher from {launcherVersion} to {release.version}");
var tempPath = launcherFolder.Combine("Wabbajack.exe.temp");
var client = new Client();
client.UseChromeUserAgent();
await client.DownloadAsync(release.asset.BrowserDownloadUrl!, tempPath);
if (tempPath.Size != release.asset.Size)
{
Utils.Log(
$"Downloaded launcher did not match expected size: {tempPath.Size} expected {release.asset.Size}");
return;
}
if (exePath.Exists)
await exePath.DeleteAsync();
await tempPath.MoveToAsync(exePath);
Utils.Log("Finished updating wabbajack");
}
}
private static async Task<Release[]> GetReleases()
{
Utils.Log("Getting new Wabbajack version list");
var client = new Client();
client.UseChromeUserAgent();
return await client.GetJsonAsync<Release[]>(Consts.GITHUB_REPO_RELEASES.ToString());
}
class Release
{
[JsonProperty("tag_name")] public string Tag { get; set; } = "";
[JsonProperty("assets")] public Asset[] Assets { get; set; } = Array.Empty<Asset>();
}
class Asset
{
[JsonProperty("browser_download_url")]
public Uri? BrowserDownloadUrl { get; set; }
[JsonProperty("name")] public string Name { get; set; } = "";
[JsonProperty("size")] public long Size { get; set; } = 0;
}
}
}

View File

@ -8,16 +8,16 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CefSharp.Common">
<Version>87.1.132</Version>
<Version>88.2.90</Version>
</PackageReference>
<PackageReference Include="CefSharp.OffScreen">
<Version>87.1.132</Version>
<Version>88.2.90</Version>
</PackageReference>
<PackageReference Include="F23.StringSimilarity">
<Version>3.1.0</Version>
<Version>4.0.0</Version>
</PackageReference>
<PackageReference Include="Fody">
<Version>6.3.0</Version>
<Version>6.4.0</Version>
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
@ -25,7 +25,7 @@
<Version>2.2.2.1</Version>
</PackageReference>
<PackageReference Include="HtmlAgilityPack">
<Version>1.11.30</Version>
<Version>1.11.31</Version>
</PackageReference>
<PackageReference Include="MegaApiClient">
<Version>1.8.2</Version>
@ -37,10 +37,10 @@
<Version>2.1.1</Version>
</PackageReference>
<PackageReference Include="ReactiveUI">
<Version>13.1.1</Version>
<Version>13.2.2</Version>
</PackageReference>
<PackageReference Include="ReactiveUI.Fody">
<Version>13.1.1</Version>
<Version>13.2.2</Version>
</PackageReference>
<PackageReference Include="SharpCompress">
<Version>0.28.1</Version>
@ -49,7 +49,7 @@
<Version>5.0.0</Version>
</PackageReference>
<PackageReference Include="System.Drawing.Common">
<Version>5.0.1</Version>
<Version>5.0.2</Version>
</PackageReference>
<PackageReference Include="System.Net.Http">
<Version>4.3.4</Version>

View File

@ -15,10 +15,10 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.78" />
<PackageReference Include="Discord.Net.WebSocket" Version="2.3.0" />
<PackageReference Include="Discord.Net.WebSocket" Version="2.3.1" />
<PackageReference Include="FluentFTP" Version="33.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Core" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.4" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Nettle" Version="1.3.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />

View File

@ -28,8 +28,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CefSharp.Common" Version="87.1.132" />
<PackageReference Include="CefSharp.OffScreen" Version="87.1.132" />
<PackageReference Include="CefSharp.Common" Version="88.2.90" />
<PackageReference Include="CefSharp.OffScreen" Version="88.2.90" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />

View File

@ -16,7 +16,7 @@
<ItemGroup>
<PackageReference Include="Genbox.AlphaFS" Version="2.2.2.1" />
<PackageReference Include="K4os.Hash.Crc" Version="1.1.4" />
<PackageReference Include="OMODFramework" Version="2.1.0.2" />
<PackageReference Include="OMODFramework" Version="2.2.0" />
<PackageReference Include="SharpCompress" Version="0.28.1" />
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
</ItemGroup>

View File

@ -1,6 +1,7 @@
using System;
using System.Windows;
using Wabbajack.Common;
using Wabbajack.Lib;
namespace Wabbajack
{

View File

@ -7,6 +7,7 @@ using MahApps.Metro.Controls;
using Newtonsoft.Json;
using Wabbajack.Common;
using Wabbajack.Common.StoreHandlers;
using Wabbajack.Lib;
using Wabbajack.Lib.LibCefHelpers;
using Wabbajack.Util;
using Application = System.Windows.Application;
@ -55,6 +56,8 @@ namespace Wabbajack
Utils.Log("Pagefile below recommended! Consider increasing to 20000MB. A suboptimal pagefile can cause crashes and poor in-game performance.");
Warmup();
var _ = LauncherUpdater.Run();
var (settings, loadedSettings) = MainSettings.TryLoadTypicalSettings().AsTask().Result;
// Load settings

View File

@ -55,10 +55,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CefSharp.Wpf" Version="87.1.132" />
<PackageReference Include="CefSharp.Wpf" Version="88.2.90" />
<PackageReference Include="DynamicData" Version="7.1.1" />
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.0.2" />
<PackageReference Include="Fody" Version="6.3.0">
<PackageReference Include="Fody" Version="6.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
@ -67,13 +67,13 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MahApps.Metro" Version="2.4.3" />
<PackageReference Include="MahApps.Metro" Version="2.4.4" />
<PackageReference Include="MahApps.Metro.IconPacks" Version="4.8.0" />
<PackageReference Include="PInvoke.Gdi32" Version="0.7.104" />
<PackageReference Include="PInvoke.User32" Version="0.7.104" />
<PackageReference Include="ReactiveUI" Version="13.1.1" />
<PackageReference Include="ReactiveUI.Fody" Version="13.1.1" />
<PackageReference Include="ReactiveUI.WPF" Version="13.1.1" />
<PackageReference Include="ReactiveUI" Version="13.2.2" />
<PackageReference Include="ReactiveUI.Fody" Version="13.2.2" />
<PackageReference Include="ReactiveUI.WPF" Version="13.2.2" />
<PackageReference Include="SharpDX.DXGI" Version="4.2.0" />
<PackageReference Include="WindowsAPICodePack-Shell" Version="1.1.1" />
<PackageReference Include="WPFThemes.DarkBlend" Version="1.0.8" />