From 40aaeca874ae19ac0573f863fe29705ac732e97c Mon Sep 17 00:00:00 2001 From: Preston Corless Date: Sat, 12 Nov 2022 23:04:23 -0700 Subject: [PATCH 1/2] Suggested edit from issues/136 It seems to me that when the emulator gives the ".desktop" file a new GUID in its filename every time it runs, it kind of makes things a hassle for people who manually organize or manage their desktop shortcuts on Linux. See https://github.com/NovaSquirrel/Mesen-X/issues/136 for an example of this. (But there's probably someone who knows more about this than I do who can confirm or deny what I'm saying.) I am not the most familiar with the code for this emulator, but it almost looks like if this proposal is implemented, it could also be helpful to move line 170 of /GUI.NET/Config/PreferenceInfo.cs to after line 72 in GUI.NET/Forms/frmConfigWizard.cs so that it only creates the .desktop file once upon setup and not each time the app is run. --- GUI.NET/Config/FileAssociationHelper.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/GUI.NET/Config/FileAssociationHelper.cs b/GUI.NET/Config/FileAssociationHelper.cs index 6fa756c66..a920ada21 100644 --- a/GUI.NET/Config/FileAssociationHelper.cs +++ b/GUI.NET/Config/FileAssociationHelper.cs @@ -59,18 +59,7 @@ static public void ConfigureLinuxMimeTypes() } - //Use a GUID to get a unique filename and then delete old files to force a reset of file associations - //Otherwise they are sometimes not refreshed properly - string desktopFilename = "mesen." + Guid.NewGuid().ToString() + ".desktop"; - string desktopFile = Path.Combine(desktopFolder, desktopFilename); - - foreach(string file in Directory.GetFiles(desktopFolder, "mesen.*.desktop")) { - if(File.Exists(file)) { - try { - File.Delete(file); - } catch { } - } - } + string desktopFile = Path.Combine(desktopFolder, "mesen.desktop"); List mimeTypes = new List(); CreateMimeType("x-mesen-nes", "nes", "NES ROM", mimeTypes, preferenceInfo.AssociateNesFiles); @@ -137,4 +126,4 @@ static public void UpdateFileAssociation(string extension, bool associate) } } } -} \ No newline at end of file +} From 37c46a125c9092e3b8b1d8b8bb482e6e93004a80 Mon Sep 17 00:00:00 2001 From: pgattic Date: Sat, 12 Nov 2022 23:16:42 -0700 Subject: [PATCH 2/2] Additional possible changes to linux's shortcut --- GUI.NET/Config/PreferenceInfo.cs | 4 +--- GUI.NET/Forms/frmConfigWizard.cs | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/GUI.NET/Config/PreferenceInfo.cs b/GUI.NET/Config/PreferenceInfo.cs index 245465afd..9e0ad297d 100644 --- a/GUI.NET/Config/PreferenceInfo.cs +++ b/GUI.NET/Config/PreferenceInfo.cs @@ -166,9 +166,7 @@ static public void ApplyConfig() { PreferenceInfo preferenceInfo = ConfigManager.Config.PreferenceInfo; - if(Program.IsMono) { - FileAssociationHelper.ConfigureLinuxMimeTypes(); - } else { + if(!Program.IsMono) { FileAssociationHelper.UpdateFileAssociation("nes", preferenceInfo.AssociateNesFiles); FileAssociationHelper.UpdateFileAssociation("fds", preferenceInfo.AssociateFdsFiles); FileAssociationHelper.UpdateFileAssociation("mmo", preferenceInfo.AssociateMmoFiles); diff --git a/GUI.NET/Forms/frmConfigWizard.cs b/GUI.NET/Forms/frmConfigWizard.cs index 863644ad0..8c90ce32c 100644 --- a/GUI.NET/Forms/frmConfigWizard.cs +++ b/GUI.NET/Forms/frmConfigWizard.cs @@ -70,6 +70,7 @@ private void CreateShortcut() string shortcutFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "mesen.desktop"); FileAssociationHelper.CreateShortcutFile(shortcutFile); Process.Start("chmod", "775 " + shortcutFile); + FileAssociationHelper.ConfigureLinuxMimeTypes(); } else { Type t = Type.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8")); dynamic shell = Activator.CreateInstance(t);