Browse Source

Finished backport to Net3

pull/32/head
Anairkoen Schno 5 years ago
parent
commit
3a676e63dd
13 changed files with 82 additions and 14 deletions
  1. +6
    -0
      IPA.Injector/GameVersionEarly.cs
  2. +7
    -2
      IPA.Injector/Injector.cs
  3. +5
    -5
      IPA.Injector/PermissionFix.cs
  4. +7
    -1
      IPA.Injector/Updates.cs
  5. +5
    -4
      IPA.Loader/Loader/PluginLoader.cs
  6. +2
    -1
      IPA.Loader/Loader/PluginManager.cs
  7. +1
    -1
      IPA.Loader/Logging/StandardLogger.cs
  8. +10
    -0
      IPA.Loader/Utilities/Utils.cs
  9. +29
    -0
      Net3-Proxy/Directory.cs
  10. +7
    -0
      Net3-Proxy/Extensions.cs
  11. +1
    -0
      Net3-Proxy/File.cs
  12. +1
    -0
      Net3-Proxy/Net3-Proxy.csproj
  13. +1
    -0
      Net3-Proxy/Path.cs

+ 6
- 0
IPA.Injector/GameVersionEarly.cs View File

@ -3,6 +3,12 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
#if NET3
using Net3_Proxy;
using Path = Net3_Proxy.Path;
using File = Net3_Proxy.File;
using Directory = Net3_Proxy.Directory;
#endif
namespace IPA.Injector namespace IPA.Injector
{ {


+ 7
- 2
IPA.Injector/Injector.cs View File

@ -2,17 +2,22 @@
using IPA.Injector.Backups; using IPA.Injector.Backups;
using IPA.Loader; using IPA.Loader;
using IPA.Logging; using IPA.Logging;
using IPA.Utilities;
using Mono.Cecil; using Mono.Cecil;
using Mono.Cecil.Cil; using Mono.Cecil.Cil;
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using static IPA.Logging.Logger; using static IPA.Logging.Logger;
using MethodAttributes = Mono.Cecil.MethodAttributes; using MethodAttributes = Mono.Cecil.MethodAttributes;
#if NET3
using Net3_Proxy;
using Path = Net3_Proxy.Path;
using Directory = Net3_Proxy.Directory;
#endif
namespace IPA.Injector namespace IPA.Injector
{ {
@ -276,7 +281,7 @@ namespace IPA.Injector
pluginAsyncLoadTask.Wait(); pluginAsyncLoadTask.Wait();
permissionFixTask.Wait(); permissionFixTask.Wait();
log.Debug("Plugins loaded"); log.Debug("Plugins loaded");
log.Debug(string.Join(", ", PluginLoader.PluginsMetadata));
log.Debug(string.Join(", ", PluginLoader.PluginsMetadata.StrJP()));
PluginComponent.Create(); PluginComponent.Create();
} }
} }

+ 5
- 5
IPA.Injector/PermissionFix.cs View File

@ -1,11 +1,11 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Security.AccessControl; using System.Security.AccessControl;
using System.Security.Principal; using System.Security.Principal;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
#if NET3
using Net3_Proxy;
#endif
namespace IPA.Injector namespace IPA.Injector
{ {
@ -13,9 +13,9 @@ namespace IPA.Injector
{ {
public static Task FixPermissions(DirectoryInfo root) public static Task FixPermissions(DirectoryInfo root)
{ {
if (!root.Exists) return Task.CompletedTask;
if (!root.Exists) return new Task(() => { });
return Task.Run(() =>
return Task.Factory.StartNew(() =>
{ {
try try
{ {


+ 7
- 1
IPA.Injector/Updates.cs View File

@ -6,6 +6,12 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using static IPA.Logging.Logger; using static IPA.Logging.Logger;
#if NET3
using Net3_Proxy;
using Path = Net3_Proxy.Path;
using File = Net3_Proxy.File;
using Directory = Net3_Proxy.Directory;
#endif
namespace IPA.Injector namespace IPA.Injector
{ {
@ -33,7 +39,7 @@ namespace IPA.Injector
{ {
// will never actually be null // will never actually be null
FileName = path, FileName = path,
Arguments = $"\"-nw={Process.GetCurrentProcess().Id},s={string.Join(" ", Environment.GetCommandLineArgs().Skip(1)).Replace("\\", "\\\\").Replace(",", "\\,")}\"",
Arguments = $"\"-nw={Process.GetCurrentProcess().Id},s={string.Join(" ", Environment.GetCommandLineArgs().Skip(1).StrJP()).Replace("\\", "\\\\").Replace(",", "\\,")}\"",
UseShellExecute = false UseShellExecute = false
}); });


+ 5
- 4
IPA.Loader/Loader/PluginLoader.cs View File

@ -15,6 +15,7 @@ using Version = SemVer.Version;
using Net3_Proxy; using Net3_Proxy;
using Path = Net3_Proxy.Path; using Path = Net3_Proxy.Path;
using File = Net3_Proxy.File; using File = Net3_Proxy.File;
using Directory = Net3_Proxy.Directory;
#endif #endif
namespace IPA.Loader namespace IPA.Loader
@ -276,7 +277,7 @@ namespace IPA.Loader
if (meta.IsBare) if (meta.IsBare)
{ {
Logger.loader.Warn($"Bare manifest cannot specify description file"); Logger.loader.Warn($"Bare manifest cannot specify description file");
meta.Manifest.Description = string.Join("\n", lines.Skip(1)); // ignore first line
meta.Manifest.Description = string.Join("\n", lines.Skip(1).StrJP()); // ignore first line
continue; continue;
} }
@ -290,7 +291,7 @@ namespace IPA.Loader
if (resc == null) if (resc == null)
{ {
Logger.loader.Warn($"Could not find description file for plugin {meta.Name} ({name}); ignoring include"); Logger.loader.Warn($"Could not find description file for plugin {meta.Name} ({name}); ignoring include");
meta.Manifest.Description = string.Join("\n", lines.Skip(1)); // ignore first line
meta.Manifest.Description = string.Join("\n", lines.Skip(1).StrJP()); // ignore first line
continue; continue;
} }
@ -398,7 +399,7 @@ namespace IPA.Loader
internal static void ComputeLoadOrder() internal static void ComputeLoadOrder()
{ {
#if DEBUG #if DEBUG
Logger.loader.Debug(string.Join(", ", PluginsMetadata.Select(p => p.ToString())));
Logger.loader.Debug(string.Join(", ", PluginsMetadata.Select(p => p.ToString()).StrJP()));
#endif #endif
bool InsertInto(HashSet<PluginMetadata> root, PluginMetadata meta, bool isRoot = false) bool InsertInto(HashSet<PluginMetadata> root, PluginMetadata meta, bool isRoot = false)
@ -454,7 +455,7 @@ namespace IPA.Loader
DeTree(PluginsMetadata, pluginTree); DeTree(PluginsMetadata, pluginTree);
#if DEBUG #if DEBUG
Logger.loader.Debug(string.Join(", ", PluginsMetadata.Select(p => p.ToString())));
Logger.loader.Debug(string.Join(", ", PluginsMetadata.Select(p => p.ToString()).StrJP()));
#endif #endif
} }


+ 2
- 1
IPA.Loader/Loader/PluginManager.cs View File

@ -17,6 +17,7 @@ using static IPA.Loader.PluginLoader;
using Net3_Proxy; using Net3_Proxy;
using Path = Net3_Proxy.Path; using Path = Net3_Proxy.Path;
using File = Net3_Proxy.File; using File = Net3_Proxy.File;
using Directory = Net3_Proxy.Directory;
#endif #endif
namespace IPA.Loader namespace IPA.Loader
@ -472,7 +473,7 @@ namespace IPA.Loader
catch (ReflectionTypeLoadException e) catch (ReflectionTypeLoadException e)
{ {
Logger.loader.Error($"Could not load the following types from {Path.GetFileName(file)}:"); Logger.loader.Error($"Could not load the following types from {Path.GetFileName(file)}:");
Logger.loader.Error($" {string.Join("\n ", e.LoaderExceptions?.Select(e1 => e1?.Message) ?? new string[0])}");
Logger.loader.Error($" {string.Join("\n ", e.LoaderExceptions?.Select(e1 => e1?.Message).StrJP() ?? new string[0])}");
} }
catch (Exception e) catch (Exception e)
{ {


+ 1
- 1
IPA.Loader/Logging/StandardLogger.cs View File

@ -215,7 +215,7 @@ namespace IPA.Logging
if (lineNo == 0) if (lineNo == 0)
{ // no debug info { // no debug info
var method = stackFrame.GetMethod(); var method = stackFrame.GetMethod();
var paramString = string.Join(", ", method.GetParameters().Select(p => p.ParameterType.FullName));
var paramString = string.Join(", ", method.GetParameters().Select(p => p.ParameterType.FullName).StrJP());
message = $"{{{method.DeclaringType?.FullName}::{method.Name}({paramString})}} {message}"; message = $"{{{method.DeclaringType?.FullName}::{method.Name}({paramString})}} {message}";
} }


+ 10
- 0
IPA.Loader/Utilities/Utils.cs View File

@ -1,6 +1,8 @@
using System; using System;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Linq;
using System.Collections.Generic;
#if NET3 #if NET3
using File = Net3_Proxy.File; using File = Net3_Proxy.File;
#endif #endif
@ -185,5 +187,13 @@ namespace IPA.Utilities
cmpVal = l.Patch - r.Patch; cmpVal = l.Patch - r.Patch;
return cmpVal; return cmpVal;
} }
#if NET4
internal static IEnumerable<string> StrJP(this IEnumerable<string> a) => a;
#endif
#if NET3
internal static string[] StrJP(this IEnumerable<string> a) => a.ToArray();
internal static string[] StrJP<T>(this IEnumerable<T> a) => a.Select(o => $"{o}" /* safer than .ToString() */).ToArray();
#endif
} }
} }

+ 29
- 0
Net3-Proxy/Directory.cs View File

@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.IO;
using System.Security.AccessControl;
using OgDir = System.IO.Directory;
namespace Net3_Proxy
{
public static class Directory
{
public static void Move(string f, string t) => OgDir.Move(f, t);
public static string[] GetFiles(string d) => OgDir.GetFiles(d);
public static string[] GetFiles(string d, string s) => OgDir.GetFiles(d, s);
public static string[] GetFiles(string d, string s, SearchOption o) => OgDir.GetFiles(d, s, o);
public static string[] GetDirectories(string d) => OgDir.GetDirectories(d);
public static string[] GetDirectories(string d, string s) => OgDir.GetDirectories(d, s);
public static string[] GetDirectories(string d, string s, SearchOption o) => OgDir.GetDirectories(d, s, o);
public static bool Exists(string d) => OgDir.Exists(d);
public static void Delete(string d) => OgDir.Delete(d);
public static void Delete(string d, bool r) => OgDir.Delete(d, r);
public static void CreateDirectory(string d) => OgDir.CreateDirectory(d);
public static void CreateDirectory(string d, DirectorySecurity s) => OgDir.CreateDirectory(d, s);
public static IEnumerable<string> EnumerateFiles(string d) => GetFiles(d);
public static IEnumerable<string> EnumerateFiles(string d, string s) => GetFiles(d, s);
public static IEnumerable<string> EnumerateFiles(string d, string s, SearchOption o) => GetFiles(d, s, o);
public static IEnumerable<string> EnumerateDirectories(string d) => GetDirectories(d);
public static IEnumerable<string> EnumerateDirectories(string d, string s) => GetDirectories(d, s);
public static IEnumerable<string> EnumerateDirectories(string d, string s, SearchOption o) => GetDirectories(d, s, o);
}
}

+ 7
- 0
Net3-Proxy/Extensions.cs View File

@ -24,6 +24,13 @@ namespace Net3_Proxy
public static StringBuilder Clear(this StringBuilder sb) public static StringBuilder Clear(this StringBuilder sb)
=> sb.Remove(0, sb.Length); => sb.Remove(0, sb.Length);
public static bool HasFlag<E>(this E e, E o) where E : Enum
{
var ei = Convert.ToUInt64(e);
var oi = Convert.ToUInt64(o);
return (ei & oi) == oi;
}
} }
public static class DirectoryInfoExtensions public static class DirectoryInfoExtensions


+ 1
- 0
Net3-Proxy/File.cs View File

@ -23,5 +23,6 @@ namespace Net3_Proxy
textWriter.WriteLine(value); textWriter.WriteLine(value);
} }
public static string[] ReadAllLines(string p) => OgFile.ReadAllLines(p); public static string[] ReadAllLines(string p) => OgFile.ReadAllLines(p);
public static FileStream OpenRead(string p) => OgFile.OpenRead(p);
} }
} }

+ 1
- 0
Net3-Proxy/Net3-Proxy.csproj View File

@ -39,6 +39,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Directory.cs" />
<Compile Include="Extensions.cs" /> <Compile Include="Extensions.cs" />
<Compile Include="File.cs" /> <Compile Include="File.cs" />
<Compile Include="IReadOnlyList.cs" /> <Compile Include="IReadOnlyList.cs" />


+ 1
- 0
Net3-Proxy/Path.cs View File

@ -52,5 +52,6 @@ namespace Net3_Proxy
begin = Combine(begin, p); begin = Combine(begin, p);
return begin; return begin;
} }
public static char PathSeparator => OgPath.PathSeparator;
} }
} }

Loading…
Cancel
Save