2016-01-16 19:33:10 -05:00
using System ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.IO ;
using System.Linq ;
using System.Net ;
using System.Text ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
using Mesen.GUI.Forms ;
namespace Mesen.GUI
{
class RuntimeChecker
{
public static bool TestDll ( )
{
try {
return InteropEmu . TestDll ( ) ;
} catch { }
if ( ! File . Exists ( "WinMesen.dll" ) ) {
MessageBox . Show ( "Mesen was unable to start due to missing files." + Environment . NewLine + Environment . NewLine + "Error: WinMesen.dll is missing." , "Mesen" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
} else {
2016-01-17 19:10:01 -05:00
if ( MessageBox . Show ( "Mesen was unable to start due to missing dependencies." + Environment . NewLine + Environment . NewLine + "Mesen requires the Visual Studio 2015 runtime. Would you like to download the runtime from Microsoft's website and install it?" , "Mesen" , MessageBoxButtons . YesNo , MessageBoxIcon . Question ) = = DialogResult . Yes ) {
2016-01-16 19:33:10 -05:00
if ( ! RuntimeChecker . DownloadRuntime ( ) ) {
MessageBox . Show ( "The Visual Studio Runtime could not be installed properly." , "Mesen" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
} else {
Process . Start ( Process . GetCurrentProcess ( ) . MainModule . FileName ) ;
}
}
}
return false ;
}
private static bool DownloadRuntime ( )
{
string link = string . Empty ;
if ( IntPtr . Size = = 4 ) {
//x86
2016-01-17 19:10:01 -05:00
link = "http://download.microsoft.com/download/C/E/5/CE514EAE-78A8-4381-86E8-29108D78DBD4/VC_redist.x86.exe" ;
2016-01-16 19:33:10 -05:00
} else {
//x64
2016-01-17 19:10:01 -05:00
link = "http://download.microsoft.com/download/C/E/5/CE514EAE-78A8-4381-86E8-29108D78DBD4/VC_redist.x64.exe" ;
2016-01-16 19:33:10 -05:00
}
2016-01-17 19:10:01 -05:00
string tempFilename = Path . GetTempPath ( ) + "Mesen_VsRuntime2015.exe" ;
2016-01-16 19:33:10 -05:00
try {
frmDownloadProgress frm = new frmDownloadProgress ( link , tempFilename ) ;
if ( frm . ShowDialog ( ) = = DialogResult . OK ) {
Process installer = Process . Start ( tempFilename , "/passive /norestart" ) ;
installer . WaitForExit ( ) ;
if ( installer . ExitCode ! = 0 ) {
MessageBox . Show ( "Unexpected error: " + installer . ExitCode , "Mesen" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
return false ;
} else {
//Runtime should now be installed, try to launch Mesen again
return true ;
}
}
} catch ( Exception e ) {
MessageBox . Show ( "Unexpected error: " + Environment . NewLine + e . Message , "Mesen" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
} finally {
try {
File . Delete ( tempFilename ) ;
} catch { }
}
return false ;
}
}
}