Allow MotW remover to fail silently

This commit is contained in:
YoshiRulz 2021-06-21 11:08:56 +10:00
parent 9143f8abcd
commit 27547178a3
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 18 additions and 11 deletions

View File

@ -54,18 +54,25 @@ namespace BizHawk.Client.EmuHawk
//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 += CurrentDomain_AssemblyResolve;
//but before we even try doing that, whack the MOTW from everything in that directory (that's a dll)
//otherwise, some people will have crashes at boot-up due to .net security disliking MOTW.
//some people are getting MOTW through a combination of browser used to download bizhawk, and program used to dearchive it
//We need to do it here too... otherwise people get exceptions when externaltools we distribute try to startup
static void RemoveMOTW(string path) => DeleteFileW($"{path}:Zone.Identifier");
var todo = new Queue<DirectoryInfo>(new[] { new DirectoryInfo(dllDir) });
while (todo.Count != 0)
try
{
var di = todo.Dequeue();
foreach (var disub in di.GetDirectories()) todo.Enqueue(disub);
foreach (var fi in di.GetFiles("*.dll")) RemoveMOTW(fi.FullName);
foreach (var fi in di.GetFiles("*.exe")) RemoveMOTW(fi.FullName);
// but before we even try doing that, whack the MOTW from everything in that directory (that's a dll)
// otherwise, some people will have crashes at boot-up due to .net security disliking MOTW.
// some people are getting MOTW through a combination of browser used to download bizhawk, and program used to dearchive it
// We need to do it here too... otherwise people get exceptions when externaltools we distribute try to startup
static void RemoveMOTW(string path) => DeleteFileW($"{path}:Zone.Identifier");
var todo = new Queue<DirectoryInfo>(new[] { new DirectoryInfo(dllDir) });
while (todo.Count != 0)
{
var di = todo.Dequeue();
foreach (var disub in di.GetDirectories()) todo.Enqueue(disub);
foreach (var fi in di.GetFiles("*.dll")) RemoveMOTW(fi.FullName);
foreach (var fi in di.GetFiles("*.exe")) RemoveMOTW(fi.FullName);
}
}
catch (Exception e)
{
Console.WriteLine($"MotW remover failed: {e}");
}
}