2011-01-11 02:55:51 +00:00
using System ;
using System.Windows.Forms ;
using SlimDX.Direct3D9 ;
using SlimDX.DirectSound ;
2011-05-23 00:33:05 +00:00
using Microsoft.VisualBasic.ApplicationServices ;
2011-01-11 02:55:51 +00:00
namespace BizHawk.MultiClient
{
2011-06-19 23:39:25 +00:00
static class Program
{
[STAThread]
static void Main ( string [ ] args )
{
Application . EnableVisualStyles ( ) ;
Application . SetCompatibleTextRenderingDefault ( false ) ;
2011-01-11 02:55:51 +00:00
2011-06-11 22:15:08 +00:00
Global . Config = ConfigService . Load < Config > ( PathManager . DefaultIniPath ) ;
2011-03-21 00:54:30 +00:00
2011-06-19 23:39:25 +00:00
try { Global . DSound = new DirectSound ( ) ; }
catch
{
2011-08-21 00:07:00 +00:00
MessageBox . Show ( "Couldn't initialize DirectSound!" , "Initialization Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
2011-06-19 23:39:25 +00:00
return ;
}
2011-01-11 02:55:51 +00:00
2011-03-21 00:54:30 +00:00
try { Global . Direct3D = new Direct3D ( ) ; }
catch
{
2011-08-21 01:07:58 +00:00
//fallback to GDI rendering
if ( ! Global . Config . DisplayGDI )
DisplayDirect3DError ( ) ;
2011-03-21 00:54:30 +00:00
}
2011-01-11 02:55:51 +00:00
2011-06-19 23:39:25 +00:00
try
{
if ( Global . Config . SingleInstanceMode )
{
SingleInstanceController controller = new SingleInstanceController ( args ) ;
controller . Run ( args ) ;
}
else
{
var mf = new MainForm ( args ) ;
2011-09-17 05:35:41 +00:00
var title = mf . Text ;
mf . Show ( ) ;
mf . Text = title ;
2011-06-19 23:39:25 +00:00
mf . ProgramRunLoop ( ) ;
}
}
catch ( Exception e )
{
2011-03-02 06:18:26 +00:00
MessageBox . Show ( e . ToString ( ) , "Oh, no, a terrible thing happened!\n\n" + e . ToString ( ) ) ;
2011-06-19 23:39:25 +00:00
}
finally
{
if ( Global . DSound ! = null & & Global . DSound . Disposed = = false )
Global . DSound . Dispose ( ) ;
if ( Global . Direct3D ! = null & & Global . Direct3D . Disposed = = false )
Global . Direct3D . Dispose ( ) ;
}
2011-05-23 00:33:05 +00:00
2011-06-19 23:39:25 +00:00
}
2011-05-23 00:33:05 +00:00
2011-06-19 23:39:25 +00:00
public class SingleInstanceController : WindowsFormsApplicationBase
{
MainForm mf ;
string [ ] cmdArgs ;
public SingleInstanceController ( string [ ] args )
{
cmdArgs = args ;
IsSingleInstance = true ;
StartupNextInstance + = this_StartupNextInstance ;
}
void this_StartupNextInstance ( object sender , StartupNextInstanceEventArgs e )
{
mf . LoadRom ( e . CommandLine [ 0 ] ) ;
}
2011-05-23 00:33:05 +00:00
2011-06-19 23:39:25 +00:00
protected override void OnCreateMainForm ( )
{
MainForm = new RamWatch ( ) ;
2011-05-23 00:33:05 +00:00
2011-06-19 23:39:25 +00:00
mf = new MainForm ( cmdArgs ) ;
MainForm = mf ;
mf . Show ( ) ;
mf . ProgramRunLoop ( ) ;
}
}
2011-08-21 01:07:58 +00:00
public static void DisplayDirect3DError ( )
{
MessageBox . Show ( "Failure to initialize Direct3D, reverting to GDI+ display method. Change the option in Config > GUI or install DirectX web update." , "Initialization Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
2011-06-19 23:39:25 +00:00
}
2011-01-11 02:55:51 +00:00
}