From 0bbddbcecb6bee4251e9cebf5c82fc63bde43c8a Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Tue, 4 Jun 2019 08:27:55 -0500 Subject: [PATCH] First run now makes sure permissions are workable --- IPA.Injector/IPA.Injector.csproj | 1 + IPA.Injector/Injector.cs | 3 ++ IPA.Injector/PermissionFix.cs | 65 +++++++++++++++++++++++++++++++ Refs/Unity.TextMeshPro.dll | Bin 84480 -> 84480 bytes 4 files changed, 69 insertions(+) create mode 100644 IPA.Injector/PermissionFix.cs diff --git a/IPA.Injector/IPA.Injector.csproj b/IPA.Injector/IPA.Injector.csproj index 4ce26d0b..12dfc25d 100644 --- a/IPA.Injector/IPA.Injector.csproj +++ b/IPA.Injector/IPA.Injector.csproj @@ -56,6 +56,7 @@ + diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index f9a55974..8a8bb50b 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -19,6 +19,7 @@ namespace IPA.Injector public static class Injector { private static Task pluginAsyncLoadTask; + private static Task permissionFixTask; // ReSharper disable once UnusedParameter.Global public static void Main(string[] args) @@ -62,6 +63,7 @@ namespace IPA.Injector LibLoader.SetupAssemblyFilenames(true); pluginAsyncLoadTask = PluginLoader.LoadTask(); + permissionFixTask = PermissionFix.FixPermissions(new DirectoryInfo(Environment.CurrentDirectory)); } catch (Exception e) { @@ -264,6 +266,7 @@ namespace IPA.Injector { // wait for plugins to finish loading pluginAsyncLoadTask.Wait(); + permissionFixTask.Wait(); log.Debug("Plugins loaded"); log.Debug(string.Join(", ", PluginLoader.PluginsMetadata)); PluginComponent.Create(); diff --git a/IPA.Injector/PermissionFix.cs b/IPA.Injector/PermissionFix.cs new file mode 100644 index 00000000..bd8c4723 --- /dev/null +++ b/IPA.Injector/PermissionFix.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.AccessControl; +using System.Security.Principal; +using System.Text; +using System.Threading.Tasks; + +namespace IPA.Injector +{ + internal static class PermissionFix + { + public static Task FixPermissions(DirectoryInfo root) + { + if (!root.Exists) return Task.CompletedTask; + + return Task.Run(() => + { + try + { + var acl = root.GetAccessControl(); + + var rules = acl.GetAccessRules(true, true, typeof(SecurityIdentifier)); + + var requestedRights = FileSystemRights.Modify; + var requestedInheritance = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit; + var requestedPropagation = PropagationFlags.InheritOnly; + + bool hasRule = false; + for (var i = 0; i < rules.Count; i++) + { + var rule = rules[i]; + + if (rule is FileSystemAccessRule fsrule + && fsrule.AccessControlType == AccessControlType.Allow + && fsrule.InheritanceFlags.HasFlag(requestedInheritance) + && fsrule.PropagationFlags == requestedPropagation + && fsrule.FileSystemRights.HasFlag(requestedRights)) + { hasRule = true; break; } + } + + if (!hasRule) + { // this is *sooo* fucking slow on first run + acl.AddAccessRule( + new FileSystemAccessRule( + new SecurityIdentifier(WellKnownSidType.WorldSid, null), + requestedRights, + requestedInheritance, + requestedPropagation, + AccessControlType.Allow + ) + ); + root.SetAccessControl(acl); + } + } + catch (Exception e) + { + Logging.Logger.log.Warn("Error configuring permissions in the game install dir"); + Logging.Logger.log.Warn(e); + } + }); + } + } +} diff --git a/Refs/Unity.TextMeshPro.dll b/Refs/Unity.TextMeshPro.dll index 8a8bce24e0d0ea4c0681970eaa2588777ab114f6..8cbb46063a7aef5ea9626382bf1d7d90d0f1aee1 100644 GIT binary patch delta 41 xcmZpe!rCx}bwUS|*ZIb-tzC?EY6A1V%4I8_J>lGc>`AR+#y+O)H`Ew4lmTrC5jp?> delta 41 xcmZpe!rCx}bwUSI!}7+itzC?EY634qSd26m6*){uZLne9mN