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