diff --git a/Core/EmulationSettings.h b/Core/EmulationSettings.h index f173e4c7..da14640d 100644 --- a/Core/EmulationSettings.h +++ b/Core/EmulationSettings.h @@ -323,6 +323,7 @@ enum class Language Spanish = 5, Ukrainian = 6, Portuguese = 7, + Catalan = 8 }; enum class StereoFilter diff --git a/GUI.NET/Config/ConfigManager.cs b/GUI.NET/Config/ConfigManager.cs index d2331ac4..cdced57e 100644 --- a/GUI.NET/Config/ConfigManager.cs +++ b/GUI.NET/Config/ConfigManager.cs @@ -73,18 +73,23 @@ namespace Mesen.GUI.Config LoadConfig(); } - + + private static object _initLock = new object(); private static void LoadConfig() { if(_config == null) { - if(File.Exists(ConfigFile)) { - _config = Configuration.Deserialize(ConfigFile); - _dirtyConfig = Configuration.Deserialize(ConfigFile); - } else { - //Create new config file and save it to disk - _config = new Configuration(); - _dirtyConfig = new Configuration(); - _config.Save(); + lock(_initLock) { + if(_config == null) { + if(File.Exists(ConfigFile)) { + _config = Configuration.Deserialize(ConfigFile); + _dirtyConfig = Configuration.Deserialize(ConfigFile); + } else { + //Create new config file and save it to disk + _config = new Configuration(); + _dirtyConfig = new Configuration(); + _config.Save(); + } + } } } } @@ -229,12 +234,17 @@ namespace Mesen.GUI.Config } } + private static DateTime _lastSaveTime = DateTime.MinValue; public static void ApplyChanges() { _config.NeedToSave = false; _config = _dirtyConfig.Clone(); _config.NeedToSave = true; - _config.Save(); + + if((DateTime.Now - _lastSaveTime).Seconds > 1) { + ConfigManager.SaveConfig(); + _lastSaveTime = DateTime.Now; + } } public static void RejectChanges() diff --git a/GUI.NET/Controls/ctrlNsfPlayer.cs b/GUI.NET/Controls/ctrlNsfPlayer.cs index 575c6835..bbfff10f 100644 --- a/GUI.NET/Controls/ctrlNsfPlayer.cs +++ b/GUI.NET/Controls/ctrlNsfPlayer.cs @@ -286,9 +286,11 @@ namespace Mesen.GUI.Controls private void ctrlNsfPlayer_VisibleChanged(object sender, EventArgs e) { - this.Repeat = this.Repeat; - this.Shuffle = this.Shuffle; - btnPause.Focus(); + if(!this.DesignMode && this.Visible) { + this.Repeat = this.Repeat; + this.Shuffle = this.Shuffle; + btnPause.Focus(); + } } private void btnNext_MouseDown(object sender, MouseEventArgs e) diff --git a/GUI.NET/Controls/ctrlRecentGames.cs b/GUI.NET/Controls/ctrlRecentGames.cs index f21c6a10..36f9cecd 100644 --- a/GUI.NET/Controls/ctrlRecentGames.cs +++ b/GUI.NET/Controls/ctrlRecentGames.cs @@ -55,9 +55,6 @@ namespace Mesen.GUI.Controls lblSaveDate.Font = new Font(_fonts.Families[0], 10); picPrevGame.Image.RotateFlip(RotateFlipType.RotateNoneFlipX); - if(!ConfigManager.Config.PreferenceInfo.DisableGameSelectionScreen) { - Initialize(); - } } } @@ -66,7 +63,7 @@ namespace Mesen.GUI.Controls get { return base.Visible; } set { - if((_initialized && _recentGames.Count == 0) || ConfigManager.Config.PreferenceInfo.DisableGameSelectionScreen) { + if(value && ((_initialized && _recentGames.Count == 0) || ConfigManager.Config.PreferenceInfo.DisableGameSelectionScreen)) { value = false; } diff --git a/GUI.NET/Forms/frmConfigWizard.cs b/GUI.NET/Forms/frmConfigWizard.cs index 3852411c..216b3099 100644 --- a/GUI.NET/Forms/frmConfigWizard.cs +++ b/GUI.NET/Forms/frmConfigWizard.cs @@ -47,7 +47,9 @@ namespace Mesen.GUI.Forms } ConfigManager.Config.InputInfo.DefaultMapping = mappingType; + ConfigManager.Config.InitializeDefaults(); ConfigManager.ApplyChanges(); + ConfigManager.SaveConfig(); if(chkCreateShortcut.Checked) { this.CreateShortcut(); diff --git a/GUI.NET/Forms/frmMain.Designer.cs b/GUI.NET/Forms/frmMain.Designer.cs index 5cf7424b..2356afc3 100644 --- a/GUI.NET/Forms/frmMain.Designer.cs +++ b/GUI.NET/Forms/frmMain.Designer.cs @@ -305,7 +305,6 @@ namespace Mesen.GUI.Forms this.menuStrip.Size = new System.Drawing.Size(430, 24); this.menuStrip.TabIndex = 0; this.menuStrip.Text = "menuStrip1"; - this.menuStrip.VisibleChanged += new System.EventHandler(this.menuStrip_VisibleChanged); // // mnuFile // diff --git a/GUI.NET/Forms/frmMain.Options.cs b/GUI.NET/Forms/frmMain.Options.cs index da934675..e11d741f 100644 --- a/GUI.NET/Forms/frmMain.Options.cs +++ b/GUI.NET/Forms/frmMain.Options.cs @@ -121,6 +121,7 @@ namespace Mesen.GUI.Forms ResourceHelper.UpdateEmuLanguage(); ResourceHelper.ApplyResources(this); UpdateMenus(); + UpdateRecentFiles(); InitializeFdsDiskMenu(); InitializeNsfMode(true); ctrlRecentGames.UpdateGameInfo(); diff --git a/GUI.NET/Forms/frmMain.cs b/GUI.NET/Forms/frmMain.cs index e53f2f28..8a8bc567 100644 --- a/GUI.NET/Forms/frmMain.cs +++ b/GUI.NET/Forms/frmMain.cs @@ -58,14 +58,6 @@ namespace Mesen.GUI.Forms { InitializeComponent(); - if(ConfigManager.Config.WindowLocation.HasValue) { - this.StartPosition = FormStartPosition.Manual; - this.Location = ConfigManager.Config.WindowLocation.Value; - } else { - //First launch - this.StartPosition = FormStartPosition.CenterScreen; - } - Version currentVersion = new Version(InteropEmu.GetMesenVersion()); lblVersion.Text = currentVersion.ToString(); @@ -129,6 +121,9 @@ namespace Mesen.GUI.Forms protected override void OnLoad(EventArgs e) { + ResourceHelper.LoadResources(ConfigManager.Config.PreferenceInfo.DisplayLanguage); + ResourceHelper.UpdateEmuLanguage(); + base.OnLoad(e); #if HIDETESTMENU @@ -157,6 +152,14 @@ namespace Mesen.GUI.Forms UpdateRecentFiles(); UpdateViewerSize(); + + if(ConfigManager.Config.WindowLocation.HasValue) { + this.StartPosition = FormStartPosition.Manual; + this.Location = ConfigManager.Config.WindowLocation.Value; + } else { + //First launch + this.StartPosition = FormStartPosition.CenterScreen; + } if(ConfigManager.Config.PreferenceInfo.CloudSaveIntegration) { Task.Run(() => CloudSyncHelper.Sync()); @@ -198,7 +201,10 @@ namespace Mesen.GUI.Forms this.Size = ConfigManager.Config.WindowSize.Value; } - this.LoadGameFromCommandLine(_commandLineArgs); + this.LoadGameFromCommandLine(_commandLineArgs); + + this.menuStrip.VisibleChanged += new System.EventHandler(this.menuStrip_VisibleChanged); + this.UpdateRendererLocation(); } protected override void OnClosing(CancelEventArgs e) @@ -772,6 +778,11 @@ namespace Mesen.GUI.Forms } private void menuStrip_VisibleChanged(object sender, EventArgs e) + { + this.UpdateRendererLocation(); + } + + private void UpdateRendererLocation() { if(this.HideMenuStrip) { IntPtr handle = this.Handle; diff --git a/GUI.NET/Program.cs b/GUI.NET/Program.cs index 1cc5610e..abe27293 100644 --- a/GUI.NET/Program.cs +++ b/GUI.NET/Program.cs @@ -9,6 +9,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using System.Xml.Serialization; using Mesen.GUI.Config; using Mesen.GUI.Forms; @@ -61,6 +62,12 @@ namespace Mesen.GUI private static void Main(string[] args) { try { + Task.Run(() => { + //Cache deserializers in another thread + XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration)); + xmlSerializer = new XmlSerializer(typeof(DebugWorkspace)); + }); + if(Type.GetType("Mono.Runtime") != null) { Program.IsMono = true; } @@ -90,7 +97,6 @@ namespace Mesen.GUI Directory.CreateDirectory(ConfigManager.HomeFolder); Directory.SetCurrentDirectory(ConfigManager.HomeFolder); try { - ResourceHelper.LoadResources(ConfigManager.Config.PreferenceInfo.DisplayLanguage); if(!ResourceManager.ExtractResources()) { return; } @@ -123,21 +129,17 @@ namespace Mesen.GUI return; } - ResourceHelper.UpdateEmuLanguage(); - using(SingleInstance singleInstance = new SingleInstance()) { - if(singleInstance.FirstInstance || !Config.ConfigManager.Config.PreferenceInfo.SingleInstance) { + if(singleInstance.FirstInstance || !ConfigManager.Config.PreferenceInfo.SingleInstance) { frmMain frmMain = new frmMain(args); - if(Config.ConfigManager.Config.PreferenceInfo.SingleInstance) { - singleInstance.ListenForArgumentsFromSuccessiveInstances(); - singleInstance.ArgumentsReceived += (object sender, ArgumentsReceivedEventArgs e) => { - frmMain.BeginInvoke((MethodInvoker)(() => { - frmMain.ProcessCommandLineArguments(e.Args, false); - frmMain.LoadGameFromCommandLine(e.Args); - })); - }; - } + singleInstance.ListenForArgumentsFromSuccessiveInstances(); + singleInstance.ArgumentsReceived += (object sender, ArgumentsReceivedEventArgs e) => { + frmMain.BeginInvoke((MethodInvoker)(() => { + frmMain.ProcessCommandLineArguments(e.Args, false); + frmMain.LoadGameFromCommandLine(e.Args); + })); + }; Application.Run(frmMain); } else { diff --git a/GUI.NET/ResourceManager.cs b/GUI.NET/ResourceManager.cs index b42895ec..734763cc 100644 --- a/GUI.NET/ResourceManager.cs +++ b/GUI.NET/ResourceManager.cs @@ -12,32 +12,10 @@ namespace Mesen.GUI { class ResourceManager { - private static void ExtractResource(string resourceName, string filename) - { - if(File.Exists(filename)) { - try { - File.Delete(filename); - } catch { } - } - Assembly a = Assembly.GetExecutingAssembly(); - using(Stream s = a.GetManifestResourceStream(resourceName)) { - byte[] buffer = new byte[s.Length]; - s.Read(buffer, 0, (int)s.Length); - try { - File.WriteAllBytes(Path.Combine(ConfigManager.HomeFolder, filename), buffer); - } catch { } - } - } - private static void ExtractFile(ZipArchiveEntry entry, string outputFilename) { - if(File.Exists(outputFilename)) { - try { - File.Delete(outputFilename); - } catch { } - } try { - entry.ExtractToFile(outputFilename); + entry.ExtractToFile(outputFilename, true); } catch { } } @@ -55,10 +33,6 @@ namespace Mesen.GUI private static void CleanupOldFiles() { try { - if(Directory.Exists(Path.Combine(ConfigManager.HomeFolder, "Resources"))) { - Directory.Delete(Path.Combine(ConfigManager.HomeFolder, "Resources"), true); - } - if(Directory.Exists(Path.Combine(ConfigManager.HomeFolder, "WinMesen"))) { Directory.Delete(Path.Combine(ConfigManager.HomeFolder, "WinMesen"), true); } diff --git a/Windows/WindowsKeyManager.cpp b/Windows/WindowsKeyManager.cpp index 8611d9dc..4e6a6f90 100644 --- a/Windows/WindowsKeyManager.cpp +++ b/Windows/WindowsKeyManager.cpp @@ -238,9 +238,6 @@ WindowsKeyManager::WindowsKeyManager(HWND hWnd) } } - _xInput.reset(new XInputManager()); - _directInput.reset(new DirectInputManager(hWnd)); - StartUpdateDeviceThread(); } @@ -253,6 +250,9 @@ WindowsKeyManager::~WindowsKeyManager() void WindowsKeyManager::StartUpdateDeviceThread() { _updateDeviceThread = std::thread([=]() { + _xInput.reset(new XInputManager()); + _directInput.reset(new DirectInputManager(_hWnd)); + while(!_stopUpdateDeviceThread) { //Check for newly plugged in controllers every 5 secs (this takes ~60-70ms when no new controllers are found) if(_xInput->NeedToUpdate()) { @@ -272,6 +272,10 @@ void WindowsKeyManager::StartUpdateDeviceThread() void WindowsKeyManager::RefreshState() { + if(!_xInput || !_directInput) { + return; + } + _xInput->RefreshState(); _directInput->RefreshState(); } @@ -279,6 +283,10 @@ void WindowsKeyManager::RefreshState() bool WindowsKeyManager::IsKeyPressed(uint32_t key) { if(key >= 0x10000) { + if(!_xInput || !_directInput) { + return false; + } + if(key >= 0x11000) { //Directinput key uint8_t gamepadPort = (key - 0x11000) / 0x100; @@ -309,6 +317,10 @@ bool WindowsKeyManager::IsMouseButtonPressed(MouseButton button) uint32_t WindowsKeyManager::GetPressedKey() { + if(!_xInput || !_directInput) { + return 0; + } + _xInput->RefreshState(); for(int i = 0; i < XUSER_MAX_COUNT; i++) { for(int j = 1; j <= 26; j++) { @@ -357,6 +369,10 @@ uint32_t WindowsKeyManager::GetKeyCode(string keyName) void WindowsKeyManager::UpdateDevices() { + if(!_xInput || !_directInput) { + return; + } + Console::Pause(); _xInput->UpdateDeviceList(); _directInput->UpdateDeviceList();