mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-11 00:48:12 +08:00
auto install vcruntime
This commit is contained in:
12
res/App.Designer.cs
generated
12
res/App.Designer.cs
generated
@@ -374,20 +374,20 @@ namespace YaeAchievement.res {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to -.
|
||||
/// Looks up a localized string similar to Downloading Visual C++ Redistributable....
|
||||
/// </summary>
|
||||
internal static string VcRuntimeAfterInstall {
|
||||
internal static string VcRuntimeDownload {
|
||||
get {
|
||||
return ResourceManager.GetString("VcRuntimeAfterInstall", resourceCulture);
|
||||
return ResourceManager.GetString("VcRuntimeDownload", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You need install Visual C++ Redistributable 2015-2022(latest) before run this application..
|
||||
/// Looks up a localized string similar to Installing Visual C++ Redistributable....
|
||||
/// </summary>
|
||||
internal static string VcRuntimeNotInstalled {
|
||||
internal static string VcRuntimeInstalling {
|
||||
get {
|
||||
return ResourceManager.GetString("VcRuntimeNotInstalled", resourceCulture);
|
||||
return ResourceManager.GetString("VcRuntimeInstalling", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
res/App.resx
12
res/App.resx
@@ -73,15 +73,9 @@ Input a number (0-5): </value>
|
||||
<data name="ConfigInitPathConfirm" xml:space="preserve">
|
||||
<value>If correct, input Y; otherwise input N</value>
|
||||
</data>
|
||||
<data name="VcRuntimeNotInstalled" xml:space="preserve">
|
||||
<value>You need install Visual C++ Redistributable 2015-2022(latest) before run this application.</value>
|
||||
</data>
|
||||
<data name="DownloadLink" xml:space="preserve">
|
||||
<value>Download: {0}</value>
|
||||
</data>
|
||||
<data name="VcRuntimeAfterInstall" xml:space="preserve">
|
||||
<value>-</value>
|
||||
</data>
|
||||
<data name="GameProcessExit" xml:space="preserve">
|
||||
<value>Game exited.</value>
|
||||
</data>
|
||||
@@ -134,4 +128,10 @@ Input a number (0-5): </value>
|
||||
<data name="NetworkError" xml:space="preserve">
|
||||
<value>Network error:</value>
|
||||
</data>
|
||||
<data name="VcRuntimeDownload" xml:space="preserve">
|
||||
<value>Downloading Visual C++ Redistributable...</value>
|
||||
</data>
|
||||
<data name="VcRuntimeInstalling" xml:space="preserve">
|
||||
<value>Installing Visual C++ Redistributable...</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -67,15 +67,9 @@
|
||||
<data name="ConfigInitPathConfirm" xml:space="preserve">
|
||||
<value>如果确认路径无误,请按 Y ;若有误或需要自行选择,请按 N </value>
|
||||
</data>
|
||||
<data name="VcRuntimeNotInstalled" xml:space="preserve">
|
||||
<value>未安装 VcRuntime</value>
|
||||
</data>
|
||||
<data name="DownloadLink" xml:space="preserve">
|
||||
<value>下载地址: {0}</value>
|
||||
</data>
|
||||
<data name="VcRuntimeAfterInstall" xml:space="preserve">
|
||||
<value>安装完成后,重新打开 YaeAchievement</value>
|
||||
</data>
|
||||
<data name="GameProcessExit" xml:space="preserve">
|
||||
<value>游戏进程异常退出</value>
|
||||
</data>
|
||||
@@ -128,4 +122,10 @@
|
||||
<data name="NetworkError" xml:space="preserve">
|
||||
<value>网络错误: {0}</value>
|
||||
</data>
|
||||
<data name="VcRuntimeDownload" xml:space="preserve">
|
||||
<value>正在下载 Visual C++ Redistributable...</value>
|
||||
</data>
|
||||
<data name="VcRuntimeInstalling" xml:space="preserve">
|
||||
<value>正在安装 Visual C++ Redistributable...</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -6,7 +6,7 @@ using static YaeAchievement.Utils;
|
||||
|
||||
InstallExitHook();
|
||||
|
||||
CheckVcRuntime();
|
||||
await CheckVcRuntime();
|
||||
CheckSelfIsRunning();
|
||||
TryDisableQuickEdit();
|
||||
InstallExceptionHook();
|
||||
|
||||
20
src/Utils.cs
20
src/Utils.cs
@@ -285,7 +285,7 @@ public static class Utils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void CheckVcRuntime() {
|
||||
public static async Task CheckVcRuntime() {
|
||||
using var root = Registry.LocalMachine;
|
||||
using var sub = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")!;
|
||||
var installed = sub.GetSubKeyNames()
|
||||
@@ -293,12 +293,18 @@ public static class Utils {
|
||||
.Select(item => item?.GetValue("DisplayName") as string ?? string.Empty)
|
||||
.Any(name => name.Contains("Microsoft Visual C++ 2022 X64 "));
|
||||
if (!installed) {
|
||||
const string vcDownloadUrl = "https://aka.ms/vs/17/release/vc_redist.x64.exe";
|
||||
Console.WriteLine(App.VcRuntimeNotInstalled);
|
||||
Console.WriteLine(App.DownloadLink, vcDownloadUrl);
|
||||
Console.WriteLine(App.VcRuntimeAfterInstall);
|
||||
ShellOpen(vcDownloadUrl);
|
||||
Environment.Exit(303);
|
||||
Console.WriteLine(App.VcRuntimeDownload);
|
||||
var pkgPath = Path.Combine(GlobalVars.AppPath, "vc_redist.x64.exe");
|
||||
await using var stream = await CHttpClient.Value.GetStreamAsync("https://aka.ms/vs/17/release/vc_redist.x64.exe");
|
||||
await using var output = File.OpenWrite(pkgPath);
|
||||
await stream.CopyToAsync(output);
|
||||
Console.WriteLine(App.VcRuntimeInstalling);
|
||||
_ = new Process {
|
||||
StartInfo = {
|
||||
FileName = pkgPath,
|
||||
Arguments = "/install /passive /norestart"
|
||||
}
|
||||
}.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user