Skip to content

Commit

Permalink
Added MSVC++ Installer Script
Browse files Browse the repository at this point in the history
Needs more testing.
  • Loading branch information
thesupersonic16 committed Aug 30, 2020
1 parent 40c458a commit 7fa95d2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
2 changes: 2 additions & 0 deletions HedgeModManager/Languages/en-AU.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
<system:String x:Key="MainUIMissingLoaderHeader" >Mod Loader Not Yet Installed!</system:String>
<system:String xml:space="preserve" x:Key="MainUIMissingLoaderDesc">In order for {0} to start loading mods, the mod loader needs to be installed.&#x0a;Would you like to install it now?</system:String>
<system:String x:Key="MainUISelectModsDBTitle" >Select where to load mods from...</system:String>
<system:String x:Key="MainUIRuntimeMissingTitle" >Missing Runtime Detected!</system:String>
<system:String x:Key="MainUIRuntimeMissingMsg" xml:space="preserve">{0} requires {1} to be installed for mods &#x0a;to function properly, would you like HMM to install this runtime?</system:String>

<!-- OptionsWindow UI Strings -->
<system:String x:Key="OptionsWindowUIError" >Please select an option!</system:String>
Expand Down
49 changes: 47 additions & 2 deletions HedgeModManager/UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -637,14 +679,16 @@ 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
{
await SaveModsDB();
Dispatcher.Invoke(Refresh);
UpdateStatus(Localise("StatusUIModsDBSaved"));
await StartGame();
if (startGame)
await StartGame();
}
catch(Exception ex)
{
Expand All @@ -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)
Expand Down

0 comments on commit 7fa95d2

Please sign in to comment.