From b47736fae1f3d2f7593142f4512cda9b64a86da6 Mon Sep 17 00:00:00 2001 From: Souryo Date: Sat, 16 Jan 2016 22:40:41 -0500 Subject: [PATCH] Merged all components into a stand-alone exe --- GUI.NET/Forms/frmMain.cs | 13 +------------ GUI.NET/GUI.NET.csproj | 22 +++++++++++++++++++++ GUI.NET/Program.cs | 14 ++++++++++++- GUI.NET/ResourceManager.cs | 40 ++++++++++++++++++++++++++++++++++++++ NES.sln | 7 ++++++- Windows/Windows.vcxproj | 14 ------------- 6 files changed, 82 insertions(+), 28 deletions(-) create mode 100644 GUI.NET/ResourceManager.cs diff --git a/GUI.NET/Forms/frmMain.cs b/GUI.NET/Forms/frmMain.cs index 0ea7a6ed..96e33c38 100644 --- a/GUI.NET/Forms/frmMain.cs +++ b/GUI.NET/Forms/frmMain.cs @@ -19,7 +19,7 @@ using Mesen.GUI.Forms.NetPlay; namespace Mesen.GUI.Forms { - public partial class frmMain : Form + public partial class frmMain : BaseForm { private InteropEmu.NotificationListener _notifListener; private Thread _emuThread; @@ -32,8 +32,6 @@ namespace Mesen.GUI.Forms _romToLoad = args[0]; } - Application.ThreadException += Application_ThreadException; - Directory.SetCurrentDirectory(Path.GetDirectoryName(Application.ExecutablePath)); InitializeComponent(); } @@ -62,10 +60,6 @@ namespace Mesen.GUI.Forms UpdateMenus(); UpdateRecentFiles(); - if(!DesignMode) { - Icon = Properties.Resources.MesenIcon; - } - if(_romToLoad != null) { LoadROM(this._romToLoad); } @@ -190,11 +184,6 @@ namespace Mesen.GUI.Forms dxViewer.Size = new Size(size.Width, size.Height); } - private void Application_ThreadException(object sender, ThreadExceptionEventArgs e) - { - MessageBox.Show(e.Exception.ToString(), "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - private void _notifListener_OnNotification(InteropEmu.NotificationEventArgs e) { if(e.NotificationType == InteropEmu.ConsoleNotificationType.GameLoaded) { diff --git a/GUI.NET/GUI.NET.csproj b/GUI.NET/GUI.NET.csproj index fcc14d08..36137e02 100644 --- a/GUI.NET/GUI.NET.csproj +++ b/GUI.NET/GUI.NET.csproj @@ -309,6 +309,7 @@ + @@ -423,6 +424,15 @@ Resources.resx True + + Dependencies\Roboto.12.spritefont + + + Dependencies\Roboto.9.spritefont + + + Dependencies\Toast.dds + SettingsSingleFileGenerator Settings.Designer.cs @@ -437,6 +447,18 @@ + + Dependencies\BlipBuffer.dll + + + Dependencies\NesNtsc.dll + + + Dependencies\WinMesen.dll + + + Dependencies\MesenIcon.bmp + diff --git a/GUI.NET/Program.cs b/GUI.NET/Program.cs index 0a171285..80fa08e4 100644 --- a/GUI.NET/Program.cs +++ b/GUI.NET/Program.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using Mesen.GUI.Config; namespace Mesen.GUI { @@ -15,12 +17,22 @@ namespace Mesen.GUI [return: MarshalAs(UnmanagedType.Bool)] private static extern bool SetForegroundWindow(IntPtr hWnd); + private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) + { + MessageBox.Show(e.Exception.ToString(), "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + /// /// The main entry point for the application. /// [STAThread] - static void Main(string[] args) + private static void Main(string[] args) { + Application.ThreadException += Application_ThreadException; + + Directory.SetCurrentDirectory(ConfigManager.HomeFolder); + ResourceManager.ExtractResources(); + if(!RuntimeChecker.TestDll()) { return; } diff --git a/GUI.NET/ResourceManager.cs b/GUI.NET/ResourceManager.cs new file mode 100644 index 00000000..54229425 --- /dev/null +++ b/GUI.NET/ResourceManager.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Mesen.GUI.Config; + +namespace Mesen.GUI +{ + class ResourceManager + { + private static void ExtractResource(string resourceName, string filename) + { + if(!System.IO.File.Exists(filename)) { + System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly(); + using(Stream s = a.GetManifestResourceStream(resourceName)) { + byte[] buffer = new byte[s.Length]; + s.Read(buffer, 0, (int)s.Length); + File.WriteAllBytes(Path.Combine(ConfigManager.HomeFolder, filename), buffer); + } + } + } + + public static void ExtractResources() + { + Directory.CreateDirectory(Path.Combine(ConfigManager.HomeFolder, "Resources")); + + //Extract all needed files + ExtractResource("Mesen.GUI.Dependencies.WinMesen.dll", "WinMesen.dll"); + ExtractResource("Mesen.GUI.Dependencies.BlipBuffer.dll", "BlipBuffer.dll"); + ExtractResource("Mesen.GUI.Dependencies.NesNtsc.dll", "NesNtsc.dll"); + + ExtractResource("Mesen.GUI.Dependencies.MesenIcon.bmp", Path.Combine("Resources", "MesenIcon.bmp")); + ExtractResource("Mesen.GUI.Dependencies.Roboto.12.spritefont", Path.Combine("Resources", "Roboto.12.spritefont")); + ExtractResource("Mesen.GUI.Dependencies.Roboto.9.spritefont", Path.Combine("Resources", "Roboto.9.spritefont")); + ExtractResource("Mesen.GUI.Dependencies.Toast.dds", Path.Combine("Resources", "Toast.dds")); + } + } +} diff --git a/NES.sln b/NES.sln index 8b894de6..694a681b 100644 --- a/NES.sln +++ b/NES.sln @@ -7,7 +7,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Core", "Core\Core.vcxproj", ProjectSection(ProjectDependencies) = postProject {B5330148-E8C7-46BA-B54E-69BE59EA337D} = {B5330148-E8C7-46BA-B54E-69BE59EA337D} {CF35D78C-F710-41D2-968F-C46ACCFF6F07} = {CF35D78C-F710-41D2-968F-C46ACCFF6F07} - {7761E790-B42C-4179-8550-8365FF9EB23E} = {7761E790-B42C-4179-8550-8365FF9EB23E} {65DB72B1-A45A-4475-90C1-60596B3ABEB3} = {65DB72B1-A45A-4475-90C1-60596B3ABEB3} EndProjectSection EndProject @@ -19,9 +18,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GUI.NET", "GUI.NET\GUI.NET. EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Windows", "Windows\Windows.vcxproj", "{7761E790-B42C-4179-8550-8365FF9EB23E}" + ProjectSection(ProjectDependencies) = postProject + {B5330148-E8C7-46BA-B54E-69BE59EA337D} = {B5330148-E8C7-46BA-B54E-69BE59EA337D} + {78FEF1A1-6DF1-4CBB-A373-AE6FA7CE5CE0} = {78FEF1A1-6DF1-4CBB-A373-AE6FA7CE5CE0} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InteropDLL", "InteropDLL\InteropDLL.vcxproj", "{37749BB2-FA78-4EC9-8990-5628FC0BBA19}" ProjectSection(ProjectDependencies) = postProject + {B5330148-E8C7-46BA-B54E-69BE59EA337D} = {B5330148-E8C7-46BA-B54E-69BE59EA337D} {7761E790-B42C-4179-8550-8365FF9EB23E} = {7761E790-B42C-4179-8550-8365FF9EB23E} {78FEF1A1-6DF1-4CBB-A373-AE6FA7CE5CE0} = {78FEF1A1-6DF1-4CBB-A373-AE6FA7CE5CE0} EndProjectSection @@ -101,6 +105,7 @@ Global {CF35D78C-F710-41D2-968F-C46ACCFF6F07}.Debug|x86.ActiveCfg = Debug|Win32 {CF35D78C-F710-41D2-968F-C46ACCFF6F07}.Debug|x86.Build.0 = Debug|Win32 {CF35D78C-F710-41D2-968F-C46ACCFF6F07}.Release|x64.ActiveCfg = Release|x64 + {CF35D78C-F710-41D2-968F-C46ACCFF6F07}.Release|x64.Build.0 = Release|x64 {CF35D78C-F710-41D2-968F-C46ACCFF6F07}.Release|x86.ActiveCfg = Release|Win32 {CF35D78C-F710-41D2-968F-C46ACCFF6F07}.Release|x86.Build.0 = Release|Win32 {2A607369-8B5D-494A-9E40-C5DC8D821AA3}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/Windows/Windows.vcxproj b/Windows/Windows.vcxproj index 91024fe9..8adbd8e5 100644 --- a/Windows/Windows.vcxproj +++ b/Windows/Windows.vcxproj @@ -264,20 +264,6 @@ false - - - Always - - - Always - - - Always - - - Always - -