mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-12 01:18:15 +08:00
improve update
This commit is contained in:
@@ -30,6 +30,10 @@
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>App.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Remove="res\Updater.exe" />
|
||||
<EmbeddedResource Include="res\Updater.exe">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
21
res/App.Designer.cs
generated
21
res/App.Designer.cs
generated
@@ -18,7 +18,7 @@ namespace YaeAchievement.res {
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class App {
|
||||
@@ -301,15 +301,6 @@ namespace YaeAchievement.res {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Unzip the package to update application..
|
||||
/// </summary>
|
||||
internal static string UpdateDownloadFinish {
|
||||
get {
|
||||
return ResourceManager.GetString("UpdateDownloadFinish", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Downloading update package....
|
||||
/// </summary>
|
||||
@@ -328,6 +319,16 @@ namespace YaeAchievement.res {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
internal static byte[] Updater {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("Updater", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Upload error to appcenter....
|
||||
/// </summary>
|
||||
|
||||
@@ -101,9 +101,6 @@ Input a number (0-5): </value>
|
||||
<data name="UpdateDownloading" xml:space="preserve">
|
||||
<value>Downloading update package...</value>
|
||||
</data>
|
||||
<data name="UpdateDownloadFinish" xml:space="preserve">
|
||||
<value>Unzip the package to update application.</value>
|
||||
</data>
|
||||
<data name="AppBanner" xml:space="preserve">
|
||||
<value>YaeAchievement ({0})</value>
|
||||
</data>
|
||||
@@ -125,4 +122,8 @@ Input a number (0-5): </value>
|
||||
<data name="ExceptionNetwork" xml:space="preserve">
|
||||
<value>Network error ({0}: {1})</value>
|
||||
</data>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="Updater" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>Updater.exe;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -95,9 +95,6 @@
|
||||
<data name="UpdateDownloading" xml:space="preserve">
|
||||
<value>正在下载更新包...</value>
|
||||
</data>
|
||||
<data name="UpdateDownloadFinish" xml:space="preserve">
|
||||
<value>关闭程序后, 将压缩包解压至当前目录即可完成更新.</value>
|
||||
</data>
|
||||
<data name="AppBanner" xml:space="preserve">
|
||||
<value>YaeAchievement - 原神成就导出工具 ({0})</value>
|
||||
</data>
|
||||
|
||||
BIN
res/Updater.exe
Normal file
BIN
res/Updater.exe
Normal file
Binary file not shown.
@@ -44,7 +44,7 @@ public static class Export {
|
||||
RequestUri = new Uri($"https://77.cocogoat.work/v1/memo?source={App.AllAchievement}"),
|
||||
Content = new StringContent(result, Encoding.UTF8, "application/json")
|
||||
};
|
||||
using var response = Utils.CHttpClient.Value.Send(request);
|
||||
using var response = Utils.CHttpClient.Send(request);
|
||||
if (response.StatusCode != HttpStatusCode.Created) {
|
||||
Console.WriteLine(App.ExportToCocogoatFail);
|
||||
return;
|
||||
@@ -60,14 +60,14 @@ public static class Export {
|
||||
var id = Guid.NewGuid().ToString("N").Substring(20, 8);
|
||||
var result = JsonSerializer.Serialize(new Dictionary<string, object> {
|
||||
{ "key", id },
|
||||
{ "data", data.List.Where(a => a.Status is Status.Finished or Status.RewardTaken) }
|
||||
{ "data", ExportToUIAFApp(data) }
|
||||
});
|
||||
using var request = new HttpRequestMessage {
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri("https://api.qyinter.com/achievementRedis"),
|
||||
Content = new StringContent(result, Encoding.UTF8, "application/json")
|
||||
};
|
||||
using var response = Utils.CHttpClient.Value.Send(request);
|
||||
using var response = Utils.CHttpClient.Send(request);
|
||||
Console.WriteLine(App.ExportToWxApp1Success, id);
|
||||
}
|
||||
|
||||
|
||||
41
src/Utils.cs
41
src/Utils.cs
@@ -14,8 +14,7 @@ namespace YaeAchievement;
|
||||
|
||||
public static class Utils {
|
||||
|
||||
public static readonly Lazy<HttpClient> CHttpClient = new (() => {
|
||||
var c = new HttpClient(new HttpClientHandler {
|
||||
public static readonly HttpClient CHttpClient = new (new HttpClientHandler {
|
||||
Proxy = GlobalVars.DebugProxy ? new WebProxy("http://127.0.0.1:8888") : null,
|
||||
AutomaticDecompression = DecompressionMethods.Brotli | DecompressionMethods.GZip
|
||||
}) {
|
||||
@@ -25,8 +24,6 @@ public static class Utils {
|
||||
}
|
||||
}
|
||||
};
|
||||
return c;
|
||||
});
|
||||
|
||||
public static byte[] GetBucketFileAsByteArray(string path, bool cache = true) {
|
||||
try {
|
||||
@@ -38,7 +35,7 @@ public static class Utils {
|
||||
if (cache && cacheFile.Exists()) {
|
||||
msg.Headers.TryAddWithoutValidation("If-None-Match", $"{cacheFile.Read().Etag}");
|
||||
}
|
||||
using var response = CHttpClient.Value.Send(msg);
|
||||
using var response = CHttpClient.Send(msg);
|
||||
if (cache && response.StatusCode == HttpStatusCode.NotModified) {
|
||||
return cacheFile.Read().Content.ToByteArray();
|
||||
}
|
||||
@@ -90,10 +87,16 @@ public static class Utils {
|
||||
Console.WriteLine(App.UpdateDescription, info.Description);
|
||||
if (info.EnableAutoDownload) {
|
||||
Console.WriteLine(App.UpdateDownloading);
|
||||
var fullPath = Path.GetFullPath($"update.{Path.GetExtension(info.PackageLink)}");
|
||||
File.WriteAllBytes(fullPath, GetBucketFileAsByteArray(info.PackageLink));
|
||||
Console.WriteLine(App.UpdateDownloadFinish);
|
||||
ShellOpen(fullPath);
|
||||
var tmpPath = Path.GetTempFileName();
|
||||
File.WriteAllBytes(tmpPath, GetBucketFileAsByteArray(info.PackageLink));
|
||||
var updaterArgs = $"{Environment.ProcessId}|{Environment.ProcessPath}|{tmpPath}";
|
||||
var updaterPath = Path.Combine(GlobalVars.DataPath, "update.exe");
|
||||
var updaterHash = App.Updater.MD5Hash();
|
||||
if (!File.Exists(updaterPath) || File.ReadAllBytes(updaterPath).MD5Hash() != updaterHash) {
|
||||
File.WriteAllBytes(updaterPath, App.Updater);
|
||||
}
|
||||
ShellOpen(updaterPath, updaterArgs.ToBytes().ToBase64());
|
||||
GlobalVars.PauseOnExit = false;
|
||||
Environment.Exit(0);
|
||||
}
|
||||
Console.WriteLine(App.DownloadLink, info.PackageLink);
|
||||
@@ -109,7 +112,6 @@ public static class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void CheckSelfIsRunning() {
|
||||
Process.EnterDebugMode();
|
||||
var cur = Process.GetCurrentProcess();
|
||||
@@ -123,13 +125,17 @@ public static class Utils {
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMethodReturnValue.Global
|
||||
public static bool ShellOpen(string path) {
|
||||
public static bool ShellOpen(string path, string? args = null) {
|
||||
try {
|
||||
return new Process {
|
||||
StartInfo = {
|
||||
var startInfo = new ProcessStartInfo {
|
||||
FileName = path,
|
||||
UseShellExecute = true
|
||||
};
|
||||
if (args != null) {
|
||||
startInfo.Arguments = args;
|
||||
}
|
||||
return new Process {
|
||||
StartInfo = startInfo
|
||||
}.Start();
|
||||
} catch (Exception) {
|
||||
return false;
|
||||
@@ -162,8 +168,10 @@ public static class Utils {
|
||||
public static void InstallExitHook() {
|
||||
AppDomain.CurrentDomain.ProcessExit += (_, _) => {
|
||||
proc?.Kill();
|
||||
if (GlobalVars.PauseOnExit) {
|
||||
Console.WriteLine(App.PressKeyToExit);
|
||||
Console.ReadKey();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -258,11 +266,8 @@ public static class Utils {
|
||||
if (!installed) {
|
||||
Console.WriteLine(App.VcRuntimeDownload);
|
||||
var pkgPath = Path.Combine(GlobalVars.DataPath, "vc_redist.x64.exe");
|
||||
var stream = await CHttpClient.Value.GetStreamAsync("https://aka.ms/vs/17/release/vc_redist.x64.exe");
|
||||
var output = File.OpenWrite(pkgPath);
|
||||
await stream.CopyToAsync(output);
|
||||
stream.Close();
|
||||
output.Close();
|
||||
var bytes = await CHttpClient.GetByteArrayAsync("https://aka.ms/vs/17/release/vc_redist.x64.exe");
|
||||
await File.WriteAllBytesAsync(pkgPath, bytes);
|
||||
Console.WriteLine(App.VcRuntimeInstalling);
|
||||
using var process = new Process {
|
||||
StartInfo = {
|
||||
|
||||
Reference in New Issue
Block a user