Browse Source

First run now makes sure permissions are workable

pull/13/head
Anairkoen Schno 5 years ago
parent
commit
e42f85183e
5 changed files with 69 additions and 0 deletions
  1. +1
    -0
      IPA.Injector/IPA.Injector.csproj
  2. +3
    -0
      IPA.Injector/Injector.cs
  3. +65
    -0
      IPA.Injector/PermissionFix.cs
  4. BIN
      Refs/Assembly-CSharp.dll
  5. BIN
      Refs/Unity.TextMeshPro.dll

+ 1
- 0
IPA.Injector/IPA.Injector.csproj View File

@ -56,6 +56,7 @@
<Compile Include="Backups\BackupUnit.cs" />
<Compile Include="Bootstrapper.cs" />
<Compile Include="Injector.cs" />
<Compile Include="PermissionFix.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Updates.cs" />
<Compile Include="Virtualizer.cs" />


+ 3
- 0
IPA.Injector/Injector.cs View File

@ -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();


+ 65
- 0
IPA.Injector/PermissionFix.cs View File

@ -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);
}
});
}
}
}

BIN
Refs/Assembly-CSharp.dll View File


BIN
Refs/Unity.TextMeshPro.dll View File


Loading…
Cancel
Save