From 7fa95d2b923e4c73b0a145c74b23eb480f380581 Mon Sep 17 00:00:00 2001 From: thesupersonic16 Date: Sun, 30 Aug 2020 21:09:25 +1000 Subject: [PATCH] Added MSVC++ Installer Script Needs more testing. --- HedgeModManager/Languages/en-AU.xaml | 2 ++ HedgeModManager/UI/MainWindow.xaml.cs | 49 +++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/HedgeModManager/Languages/en-AU.xaml b/HedgeModManager/Languages/en-AU.xaml index dbd05daa..50ce5870 100644 --- a/HedgeModManager/Languages/en-AU.xaml +++ b/HedgeModManager/Languages/en-AU.xaml @@ -77,6 +77,8 @@ Mod Loader Not Yet Installed! In order for {0} to start loading mods, the mod loader needs to be installed. Would you like to install it now? Select where to load mods from... + Missing Runtime Detected! + {0} requires {1} to be installed for mods to function properly, would you like HMM to install this runtime? Please select an option! diff --git a/HedgeModManager/UI/MainWindow.xaml.cs b/HedgeModManager/UI/MainWindow.xaml.cs index 8ef1d4d7..697290eb 100644 --- a/HedgeModManager/UI/MainWindow.xaml.cs +++ b/HedgeModManager/UI/MainWindow.xaml.cs @@ -569,6 +569,48 @@ public void ShowMissingOtherLoaderWarning() }); } + public bool CheckDepends() + { + bool abort = false; + if (!abort) + abort = CheckDepend("637100", "system32\\vcruntime140.dll", "MSVC++ Redist 2019 (64 bit)", "https://aka.ms/vs/16/release/vc_redist.x64.exe", "vc_redist.x64.exe"); + if (!abort) + abort = CheckDepend("71340" , "SysWOW64\\vcruntime140.dll", "MSVC++ Redist 2019 (32 bit)", "https://aka.ms/vs/16/release/vc_redist.x86.exe", "vc_redist.x86.exe"); + if (!abort) + abort = CheckDepend("329440", "SysWOW64\\vcruntime140.dll", "MSVC++ Redist 2019 (32 bit)", "https://aka.ms/vs/16/release/vc_redist.x86.exe", "vc_redist.x86.exe"); + return !abort; + } + + public bool CheckDepend(string id, string filePath, string dependName, string downloadURL, string fileName) + { + bool abort = false; + if (HedgeApp.CurrentGame.AppID == id && !File.Exists(Path.Combine(Environment.GetEnvironmentVariable("windir"), filePath))) + { + var dialog = new HedgeMessageBox(Localise("MainUIRuntimeMissingTitle"), string.Format(Localise("MainUIRuntimeMissingMsg"), HedgeApp.CurrentGame.GameName, dependName)); + + dialog.AddButton(Localise("CommonUINo"), () => + { + abort = true; + dialog.Close(); + }); + dialog.AddButton(Localise("CommonUIYes"), () => + { + DownloadWindow window = new DownloadWindow($"Downloading {dependName}...", downloadURL, fileName); + window.Start(); + if (File.Exists(fileName)) + { + // For VC++ + Process.Start(fileName, "/passive /norestart").WaitForExit(30000); + File.Delete(fileName); + } + dialog.Close(); + }); + + dialog.ShowDialog(); + } + return abort; + } + private void Window_Loaded(object sender, RoutedEventArgs e) { StatusTimer = new Timer((state) => UpdateStatus(string.Empty)); @@ -637,6 +679,7 @@ private void UI_Save_Click(object sender, RoutedEventArgs e) private void UI_SaveAndPlay_Click(object sender, RoutedEventArgs e) { ShowMissingOtherLoaderWarning(); + bool startGame = CheckDepends(); Task.Factory.StartNew(async () => { try @@ -644,7 +687,8 @@ private void UI_SaveAndPlay_Click(object sender, RoutedEventArgs e) await SaveModsDB(); Dispatcher.Invoke(Refresh); UpdateStatus(Localise("StatusUIModsDBSaved")); - await StartGame(); + if (startGame) + await StartGame(); } catch(Exception ex) { @@ -655,7 +699,8 @@ private void UI_SaveAndPlay_Click(object sender, RoutedEventArgs e) private void UI_Play_Click(object sender, RoutedEventArgs e) { - StartGame(); + if (CheckDepends()) + StartGame(); } private void UI_CPKREDIR_Click(object sender, RoutedEventArgs e)