From 569113f2f8cad38a13454ace2001ba4ac591b3fc Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 21 Feb 2017 18:23:02 -0600 Subject: [PATCH] fix #741, maybe, by removing MOTW from external cores before interrogating them. Will it still trigger when running them, if that's done somehow before interrogating them? (untested) --- .../Classes/ExternalToolManager.cs | 3 ++- BizHawk.Client.EmuHawk/Program.cs | 13 ++++--------- BizHawk.Client.MultiHawk/Program.cs | 4 ++-- BizHawk.Common/Win32Hacks.cs | 10 ++++++++++ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/BizHawk.Client.ApiHawk/Classes/ExternalToolManager.cs b/BizHawk.Client.ApiHawk/Classes/ExternalToolManager.cs index dc6ac9e114..3dfa1e3d26 100644 --- a/BizHawk.Client.ApiHawk/Classes/ExternalToolManager.cs +++ b/BizHawk.Client.ApiHawk/Classes/ExternalToolManager.cs @@ -83,7 +83,8 @@ namespace BizHawk.Client.ApiHawk ToolStripMenuItem item = null; try - { + { + BizHawk.Common.Win32Hacks.RemoveMOTW(fileName); externalToolFile = Assembly.LoadFrom(fileName); object[] attributes = externalToolFile.GetCustomAttributes(typeof(BizHawkExternalToolAttribute), false); if (attributes != null && attributes.Count() == 1) diff --git a/BizHawk.Client.EmuHawk/Program.cs b/BizHawk.Client.EmuHawk/Program.cs index ddbf633830..1c6624d55c 100644 --- a/BizHawk.Client.EmuHawk/Program.cs +++ b/BizHawk.Client.EmuHawk/Program.cs @@ -65,6 +65,8 @@ namespace BizHawk.Client.EmuHawk //some people are getting MOTW through a combination of browser used to download bizhawk, and program used to dearchive it WhackAllMOTW(dllDir); + //We need to do it here too... otherwise people get exceptions when externaltools we distribute try to startup + //in case assembly resolution fails, such as if we moved them into the dll subdiretory, this event handler can reroute to them AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); @@ -318,13 +320,6 @@ namespace BizHawk.Client.EmuHawk [DllImport("kernel32.dll", SetLastError = true)] static extern uint SetDllDirectory(string lpPathName); - [DllImport("kernel32.dll", EntryPoint = "DeleteFileW", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)] - static extern bool DeleteFileW([MarshalAs(UnmanagedType.LPWStr)]string lpFileName); - static void RemoveMOTW(string path) - { - DeleteFileW(path + ":Zone.Identifier"); - } - static void WhackAllMOTW(string dllDir) { var todo = new Queue(new[] { new DirectoryInfo(dllDir) }); @@ -333,9 +328,9 @@ namespace BizHawk.Client.EmuHawk var di = todo.Dequeue(); foreach (var disub in di.GetDirectories()) todo.Enqueue(disub); foreach (var fi in di.GetFiles("*.dll")) - RemoveMOTW(fi.FullName); + Win32Hacks.RemoveMOTW(fi.FullName); foreach (var fi in di.GetFiles("*.exe")) - RemoveMOTW(fi.FullName); + Win32Hacks.RemoveMOTW(fi.FullName); } } diff --git a/BizHawk.Client.MultiHawk/Program.cs b/BizHawk.Client.MultiHawk/Program.cs index 11837a5cde..395ab0f0d2 100644 --- a/BizHawk.Client.MultiHawk/Program.cs +++ b/BizHawk.Client.MultiHawk/Program.cs @@ -166,9 +166,9 @@ namespace BizHawk.Client.MultiHawk var di = todo.Dequeue(); foreach (var disub in di.GetDirectories()) todo.Enqueue(disub); foreach (var fi in di.GetFiles("*.dll")) - RemoveMOTW(fi.FullName); + Win32Hacks.RemoveMOTW(fi.FullName); foreach (var fi in di.GetFiles("*.exe")) - RemoveMOTW(fi.FullName); + Win32Hacks.RemoveMOTW(fi.FullName); } } diff --git a/BizHawk.Common/Win32Hacks.cs b/BizHawk.Common/Win32Hacks.cs index 88313cb295..ff91447ffa 100644 --- a/BizHawk.Common/Win32Hacks.cs +++ b/BizHawk.Common/Win32Hacks.cs @@ -259,4 +259,14 @@ namespace BizHawk.Common } + public static class Win32Hacks + { + [DllImport("kernel32.dll", EntryPoint = "DeleteFileW", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)] + static extern bool DeleteFileW([MarshalAs(UnmanagedType.LPWStr)]string lpFileName); + + public static void RemoveMOTW(string path) + { + DeleteFileW(path + ":Zone.Identifier"); + } + } } \ No newline at end of file