Browse Source

Performed some cleanup

pull/46/head
Anairkoen Schno 6 years ago
parent
commit
eca52b742d
17 changed files with 126 additions and 61 deletions
  1. +4
    -0
      BSIPA.sln.DotSettings
  2. +26
    -19
      IPA.Injector/Injector.cs
  3. +1
    -1
      IPA.Injector/Properties/AssemblyInfo.cs
  4. +7
    -6
      IPA.Loader/Config/ConfigProviders/JsonConfigProvider.cs
  5. +5
    -3
      IPA.Loader/Config/SelfConfig.cs
  6. +1
    -0
      IPA.Loader/IPA.Loader.csproj
  7. +4
    -4
      IPA.Loader/Loader/PluginManifest.cs
  8. +4
    -1
      IPA.Loader/Logging/LogPrinter.cs
  9. +33
    -6
      IPA.Loader/Logging/Logger.cs
  10. +5
    -5
      IPA.Loader/Logging/Printers/GZFilePrinter.cs
  11. +1
    -1
      IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs
  12. +2
    -2
      IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs
  13. +1
    -1
      IPA.Loader/Logging/Printers/PluginSubLogPrinter.cs
  14. +23
    -3
      IPA.Loader/Logging/StandardLogger.cs
  15. +3
    -3
      IPA.Loader/Updating/SelfPlugin.cs
  16. +6
    -6
      IPA/Properties/AssemblyInfo.cs
  17. BIN
      Refs/UnityEngine.CoreModule.dll

+ 4
- 0
BSIPA.sln.DotSettings View File

@ -1,5 +1,9 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InconsistentNaming/@EntryIndexedValue">WARNING</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InconsistentNaming/@EntryIndexedValue">WARNING</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INT_ALIGN_BINARY_EXPRESSIONS/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INT_ALIGN_FIELDS/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INT_ALIGN_METHODS/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INT_ALIGN_PROPERTIES/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BS/@EntryIndexedValue">BS</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BS/@EntryIndexedValue">BS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IPA/@EntryIndexedValue">IPA</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IPA/@EntryIndexedValue">IPA</s:String>


+ 26
- 19
IPA.Injector/Injector.cs View File

@ -1,4 +1,5 @@
using IPA.Injector.Backups;
using IPA.Config;
using IPA.Injector.Backups;
using IPA.Loader; using IPA.Loader;
using IPA.Logging; using IPA.Logging;
using Mono.Cecil; using Mono.Cecil;
@ -8,7 +9,6 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using IPA.Config;
using UnityEngine; using UnityEngine;
using static IPA.Logging.Logger; using static IPA.Logging.Logger;
using MethodAttributes = Mono.Cecil.MethodAttributes; using MethodAttributes = Mono.Cecil.MethodAttributes;
@ -24,8 +24,8 @@ namespace IPA.Injector
public static void Main(string[] args) public static void Main(string[] args)
{ // entry point for doorstop { // entry point for doorstop
// At this point, literally nothing but mscorlib is loaded, // At this point, literally nothing but mscorlib is loaded,
// and since this class doesn't have any static fields that
// aren't defined in mscorlib, we can control exactly what
// and since this class doesn't have any static fields that
// aren't defined in mscorlib, we can control exactly what
// gets loaded. // gets loaded.
try try
@ -38,7 +38,7 @@ namespace IPA.Injector
SelfConfig.Set(); SelfConfig.Set();
loader.Debug("Prepping bootstrapper"); loader.Debug("Prepping bootstrapper");
InstallBootstrapPatch(); InstallBootstrapPatch();
Updates.InstallPendingUpdates(); Updates.InstallPendingUpdates();
@ -63,7 +63,7 @@ namespace IPA.Injector
var cAsmName = Assembly.GetExecutingAssembly().GetName(); var cAsmName = Assembly.GetExecutingAssembly().GetName();
loader.Debug("Finding backup"); loader.Debug("Finding backup");
var backupPath = Path.Combine(Environment.CurrentDirectory, "IPA","Backups","Beat Saber");
var backupPath = Path.Combine(Environment.CurrentDirectory, "IPA", "Backups", "Beat Saber");
var bkp = BackupManager.FindLatestBackup(backupPath); var bkp = BackupManager.FindLatestBackup(backupPath);
if (bkp == null) if (bkp == null)
loader.Warn("No backup found! Was BSIPA installed using the installer?"); loader.Warn("No backup found! Was BSIPA installed using the installer?");
@ -71,6 +71,7 @@ namespace IPA.Injector
loader.Debug("Ensuring patch on UnityEngine.CoreModule exists"); loader.Debug("Ensuring patch on UnityEngine.CoreModule exists");
#region Insert patch into UnityEngine.CoreModule.dll #region Insert patch into UnityEngine.CoreModule.dll
{ {
var unityPath = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data", "Managed", var unityPath = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data", "Managed",
"UnityEngine.CoreModule.dll"); "UnityEngine.CoreModule.dll");
@ -103,7 +104,7 @@ namespace IPA.Injector
if (m.IsRuntimeSpecialName && m.Name == ".cctor") if (m.IsRuntimeSpecialName && m.Name == ".cctor")
cctor = m; cctor = m;
var cbs = unityModDef.ImportReference(((Action) CreateBootstrapper).Method);
var cbs = unityModDef.ImportReference(((Action)CreateBootstrapper).Method);
if (cctor == null) if (cctor == null)
{ {
@ -129,17 +130,18 @@ namespace IPA.Injector
ilp.Replace(ins, ilp.Create(OpCodes.Call, cbs)); ilp.Replace(ins, ilp.Create(OpCodes.Call, cbs));
modified = true; modified = true;
break; break;
case 0: case 0:
{
var methodRef = ins.Operand as MethodReference;
if (methodRef?.FullName != cbs.FullName)
{ {
ilp.Replace(ins, ilp.Create(OpCodes.Call, cbs));
modified = true;
var methodRef = ins.Operand as MethodReference;
if (methodRef?.FullName != cbs.FullName)
{
ilp.Replace(ins, ilp.Create(OpCodes.Call, cbs));
modified = true;
}
break;
} }
break;
}
case 1 when ins.OpCode != OpCodes.Ret: case 1 when ins.OpCode != OpCodes.Ret:
ilp.Replace(ins, ilp.Create(OpCodes.Ret)); ilp.Replace(ins, ilp.Create(OpCodes.Ret));
modified = true; modified = true;
@ -154,11 +156,13 @@ namespace IPA.Injector
unityAsmDef.Write(unityPath); unityAsmDef.Write(unityPath);
} }
} }
#endregion
#endregion Insert patch into UnityEngine.CoreModule.dll
loader.Debug("Ensuring Assembly-CSharp is virtualized"); loader.Debug("Ensuring Assembly-CSharp is virtualized");
#region Virtualize Assembly-CSharp.dll #region Virtualize Assembly-CSharp.dll
{ {
var ascPath = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data", "Managed", var ascPath = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data", "Managed",
"Assembly-CSharp.dll"); "Assembly-CSharp.dll");
@ -166,10 +170,12 @@ namespace IPA.Injector
var ascModule = VirtualizedModule.Load(ascPath); var ascModule = VirtualizedModule.Load(ascPath);
ascModule.Virtualize(cAsmName, () => bkp?.Add(ascPath)); ascModule.Virtualize(cAsmName, () => bkp?.Add(ascPath));
} }
#endregion
#endregion Virtualize Assembly-CSharp.dll
} }
private static bool _bootstrapped; private static bool _bootstrapped;
private static void CreateBootstrapper() private static void CreateBootstrapper()
{ {
if (_bootstrapped) return; if (_bootstrapped) return;
@ -184,12 +190,13 @@ namespace IPA.Injector
// need to reinit streams singe Unity seems to redirect stdout // need to reinit streams singe Unity seems to redirect stdout
WinConsole.InitializeStreams(); WinConsole.InitializeStreams();
var bootstrapper = new GameObject("NonDestructiveBootstrapper").AddComponent<Bootstrapper>(); var bootstrapper = new GameObject("NonDestructiveBootstrapper").AddComponent<Bootstrapper>();
bootstrapper.Destroyed += Bootstrapper_Destroyed; bootstrapper.Destroyed += Bootstrapper_Destroyed;
} }
private static bool _loadingDone; private static bool _loadingDone;
private static void Bootstrapper_Destroyed() private static void Bootstrapper_Destroyed()
{ {
// wait for plugins to finish loading // wait for plugins to finish loading
@ -199,4 +206,4 @@ namespace IPA.Injector
PluginComponent.Create(); PluginComponent.Create();
} }
} }
}
}

+ 1
- 1
IPA.Injector/Properties/AssemblyInfo.cs View File

@ -34,4 +34,4 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.12.0")] [assembly: AssemblyVersion("3.12.0")]
[assembly: AssemblyFileVersion("3.12.0")]
[assembly: AssemblyFileVersion("3.12.0")]

+ 7
- 6
IPA.Loader/Config/ConfigProviders/JsonConfigProvider.cs View File

@ -1,10 +1,10 @@
using System;
using IPA.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using IPA.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace IPA.Config.ConfigProviders namespace IPA.Config.ConfigProviders
{ {
@ -20,13 +20,14 @@ namespace IPA.Config.ConfigProviders
// TODO: create a wrapper that allows empty object creation // TODO: create a wrapper that allows empty object creation
public dynamic Dynamic => jsonObj; public dynamic Dynamic => jsonObj;
public bool HasChanged { get; private set; } public bool HasChanged { get; private set; }
public bool InMemoryChanged { get; set; } public bool InMemoryChanged { get; set; }
public DateTime LastModified => File.GetLastWriteTime(Filename + ".json"); public DateTime LastModified => File.GetLastWriteTime(Filename + ".json");
private string _filename; private string _filename;
public string Filename public string Filename
{ {
get => _filename; get => _filename;
@ -115,4 +116,4 @@ namespace IPA.Config.ConfigProviders
InMemoryChanged = true; InMemoryChanged = true;
} }
} }
}
}

+ 5
- 3
IPA.Loader/Config/SelfConfig.cs View File

@ -1,6 +1,6 @@
using System.IO;
using IPA.Logging;
using IPA.Logging;
using IPA.Utilities; using IPA.Utilities;
using System.IO;
namespace IPA.Config namespace IPA.Config
{ {
@ -28,6 +28,7 @@ namespace IPA.Config
} }
public static Ref<SelfConfig> SelfConfigRef; public static Ref<SelfConfig> SelfConfigRef;
public static void Set() public static void Set()
{ {
LoaderConfig = Config.GetProviderFor(Path.Combine("UserData", IPA_Name), "toml", "json"); LoaderConfig = Config.GetProviderFor(Path.Combine("UserData", IPA_Name), "toml", "json");
@ -43,6 +44,7 @@ namespace IPA.Config
public bool ShowCallSource = false; public bool ShowCallSource = false;
public bool ShowDebug = false; public bool ShowDebug = false;
} }
public DebugObject Debug = new DebugObject(); public DebugObject Debug = new DebugObject();
} }
}
}

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

@ -61,6 +61,7 @@
<Compile Include="Config\IConfigProvider.cs" /> <Compile Include="Config\IConfigProvider.cs" />
<Compile Include="Config\SelfConfig.cs" /> <Compile Include="Config\SelfConfig.cs" />
<Compile Include="Loader\Composite\CompositeBSPlugin.cs" /> <Compile Include="Loader\Composite\CompositeBSPlugin.cs" />
<Compile Include="Loader\Features\Feature.cs" />
<Compile Include="Loader\PluginLoader.cs" /> <Compile Include="Loader\PluginLoader.cs" />
<Compile Include="Loader\PluginManifest.cs" /> <Compile Include="Loader\PluginManifest.cs" />
<Compile Include="Logging\Printers\PluginSubLogPrinter.cs" /> <Compile Include="Logging\Printers\PluginSubLogPrinter.cs" />


+ 4
- 4
IPA.Loader/Loader/PluginManifest.cs View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using IPA.JsonConverters;
using IPA.JsonConverters;
using Newtonsoft.Json; using Newtonsoft.Json;
using SemVer; using SemVer;
using System.Collections.Generic;
namespace IPA.Loader namespace IPA.Loader
{ {
@ -24,7 +24,7 @@ namespace IPA.Loader
[JsonProperty("author", Required = Required.Always)] [JsonProperty("author", Required = Required.Always)]
public string Author; public string Author;
[JsonProperty("dependsOn", Required = Required.DisallowNull, ItemConverterType = typeof(SemverRangeConverter))] [JsonProperty("dependsOn", Required = Required.DisallowNull, ItemConverterType = typeof(SemverRangeConverter))]
public Dictionary<string, Range> Dependencies = new Dictionary<string, Range>(); public Dictionary<string, Range> Dependencies = new Dictionary<string, Range>();
@ -40,4 +40,4 @@ namespace IPA.Loader
[JsonProperty("loadAfter", Required = Required.DisallowNull)] [JsonProperty("loadAfter", Required = Required.DisallowNull)]
public string[] LoadAfter = new string[0]; public string[] LoadAfter = new string[0];
} }
}
}

+ 4
- 1
IPA.Loader/Logging/LogPrinter.cs View File

@ -11,6 +11,7 @@ namespace IPA.Logging
/// Provides a filter for which log levels to allow through. /// Provides a filter for which log levels to allow through.
/// </summary> /// </summary>
public abstract Logger.LogLevel Filter { get; set; } public abstract Logger.LogLevel Filter { get; set; }
/// <summary> /// <summary>
/// Prints a provided message from a given log at the specified time. /// Prints a provided message from a given log at the specified time.
/// </summary> /// </summary>
@ -19,15 +20,17 @@ namespace IPA.Logging
/// <param name="logName">the name of the log that created this message</param> /// <param name="logName">the name of the log that created this message</param>
/// <param name="message">the message</param> /// <param name="message">the message</param>
public abstract void Print(Logger.Level level, DateTime time, string logName, string message); public abstract void Print(Logger.Level level, DateTime time, string logName, string message);
/// <summary> /// <summary>
/// Called before the first print in a group. May be called multiple times. /// Called before the first print in a group. May be called multiple times.
/// Use this to create file handles and the like. /// Use this to create file handles and the like.
/// </summary> /// </summary>
public virtual void StartPrint() { } public virtual void StartPrint() { }
/// <summary> /// <summary>
/// Called after the last print in a group. May be called multiple times. /// Called after the last print in a group. May be called multiple times.
/// Use this to dispose file handles and the like. /// Use this to dispose file handles and the like.
/// </summary> /// </summary>
public virtual void EndPrint() { } public virtual void EndPrint() { }
} }
}
}

+ 33
- 6
IPA.Loader/Logging/Logger.cs View File

@ -1,4 +1,5 @@
using System; using System;
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace IPA.Logging namespace IPA.Logging
@ -9,6 +10,7 @@ namespace IPA.Logging
public abstract class Logger public abstract class Logger
{ {
private static Logger _log; private static Logger _log;
internal static Logger log internal static Logger log
{ {
get get
@ -18,6 +20,7 @@ namespace IPA.Logging
return _log; return _log;
} }
} }
internal static Logger updater => log.GetChildLogger("Updater"); internal static Logger updater => log.GetChildLogger("Updater");
internal static Logger libLoader => log.GetChildLogger("LibraryLoader"); internal static Logger libLoader => log.GetChildLogger("LibraryLoader");
internal static Logger loader => log.GetChildLogger("Loader"); internal static Logger loader => log.GetChildLogger("Loader");
@ -38,22 +41,27 @@ namespace IPA.Logging
/// No associated level. These never get shown. /// No associated level. These never get shown.
/// </summary> /// </summary>
None = 0, None = 0,
/// <summary> /// <summary>
/// A debug message. /// A debug message.
/// </summary> /// </summary>
Debug = 1, Debug = 1,
/// <summary> /// <summary>
/// An informational message. /// An informational message.
/// </summary> /// </summary>
Info = 2, Info = 2,
/// <summary> /// <summary>
/// A warning message. /// A warning message.
/// </summary> /// </summary>
Warning = 4, Warning = 4,
/// <summary> /// <summary>
/// An error message. /// An error message.
/// </summary> /// </summary>
Error = 8, Error = 8,
/// <summary> /// <summary>
/// A critical error message. /// A critical error message.
/// </summary> /// </summary>
@ -70,22 +78,27 @@ namespace IPA.Logging
/// Allow no messages through. /// Allow no messages through.
/// </summary> /// </summary>
None = Level.None, None = Level.None,
/// <summary> /// <summary>
/// Only shows Debug messages. /// Only shows Debug messages.
/// </summary> /// </summary>
DebugOnly = Level.Debug, DebugOnly = Level.Debug,
/// <summary> /// <summary>
/// Only shows info messages. /// Only shows info messages.
/// </summary> /// </summary>
InfoOnly = Level.Info, InfoOnly = Level.Info,
/// <summary> /// <summary>
/// Only shows Warning messages. /// Only shows Warning messages.
/// </summary> /// </summary>
WarningOnly = Level.Warning, WarningOnly = Level.Warning,
/// <summary> /// <summary>
/// Only shows Error messages. /// Only shows Error messages.
/// </summary> /// </summary>
ErrorOnly = Level.Error, ErrorOnly = Level.Error,
/// <summary> /// <summary>
/// Only shows Critical messages. /// Only shows Critical messages.
/// </summary> /// </summary>
@ -95,14 +108,17 @@ namespace IPA.Logging
/// Shows all messages error and up. /// Shows all messages error and up.
/// </summary> /// </summary>
ErrorUp = ErrorOnly | CriticalOnly, ErrorUp = ErrorOnly | CriticalOnly,
/// <summary> /// <summary>
/// Shows all messages warning and up. /// Shows all messages warning and up.
/// </summary> /// </summary>
WarningUp = WarningOnly | ErrorUp, WarningUp = WarningOnly | ErrorUp,
/// <summary> /// <summary>
/// Shows all messages info and up. /// Shows all messages info and up.
/// </summary> /// </summary>
InfoUp = InfoOnly | WarningUp, InfoUp = InfoOnly | WarningUp,
/// <summary> /// <summary>
/// Shows all messages. /// Shows all messages.
/// </summary> /// </summary>
@ -120,19 +136,22 @@ namespace IPA.Logging
/// <param name="level">the level of the message</param> /// <param name="level">the level of the message</param>
/// <param name="message">the message to log</param> /// <param name="message">the message to log</param>
public abstract void Log(Level level, string message); public abstract void Log(Level level, string message);
/// <summary> /// <summary>
/// A basic log function taking an exception to log. /// A basic log function taking an exception to log.
/// </summary> /// </summary>
/// <param name="level">the level of the message</param> /// <param name="level">the level of the message</param>
/// <param name="e">the exception to log</param> /// <param name="e">the exception to log</param>
public virtual void Log(Level level, Exception e) => Log(level, e.ToString()); public virtual void Log(Level level, Exception e) => Log(level, e.ToString());
/// <summary> /// <summary>
/// Sends a debug message.
/// Sends a debug message.
/// Equivalent to Log(Level.Debug, message); /// Equivalent to Log(Level.Debug, message);
/// <see cref="Log(Level, string)"/> /// <see cref="Log(Level, string)"/>
/// </summary> /// </summary>
/// <param name="message">the message to log</param> /// <param name="message">the message to log</param>
public virtual void Debug(string message) => Log(Level.Debug, message); public virtual void Debug(string message) => Log(Level.Debug, message);
/// <summary> /// <summary>
/// Sends an exception as a debug message. /// Sends an exception as a debug message.
/// Equivalent to Log(Level.Debug, e); /// Equivalent to Log(Level.Debug, e);
@ -140,13 +159,15 @@ namespace IPA.Logging
/// </summary> /// </summary>
/// <param name="e">the exception to log</param> /// <param name="e">the exception to log</param>
public virtual void Debug(Exception e) => Log(Level.Debug, e); public virtual void Debug(Exception e) => Log(Level.Debug, e);
/// <summary> /// <summary>
/// Sends an info message.
/// Sends an info message.
/// Equivalent to Log(Level.Info, message). /// Equivalent to Log(Level.Info, message).
/// <see cref="Log(Level, string)"/> /// <see cref="Log(Level, string)"/>
/// </summary> /// </summary>
/// <param name="message">the message to log</param> /// <param name="message">the message to log</param>
public virtual void Info(string message) => Log(Level.Info, message); public virtual void Info(string message) => Log(Level.Info, message);
/// <summary> /// <summary>
/// Sends an exception as an info message. /// Sends an exception as an info message.
/// Equivalent to Log(Level.Info, e); /// Equivalent to Log(Level.Info, e);
@ -154,13 +175,15 @@ namespace IPA.Logging
/// </summary> /// </summary>
/// <param name="e">the exception to log</param> /// <param name="e">the exception to log</param>
public virtual void Info(Exception e) => Log(Level.Info, e); public virtual void Info(Exception e) => Log(Level.Info, e);
/// <summary> /// <summary>
/// Sends a warning message.
/// Sends a warning message.
/// Equivalent to Log(Level.Warning, message). /// Equivalent to Log(Level.Warning, message).
/// <see cref="Log(Level, string)"/> /// <see cref="Log(Level, string)"/>
/// </summary> /// </summary>
/// <param name="message">the message to log</param> /// <param name="message">the message to log</param>
public virtual void Warn(string message) => Log(Level.Warning, message); public virtual void Warn(string message) => Log(Level.Warning, message);
/// <summary> /// <summary>
/// Sends an exception as a warning message. /// Sends an exception as a warning message.
/// Equivalent to Log(Level.Warning, e); /// Equivalent to Log(Level.Warning, e);
@ -168,13 +191,15 @@ namespace IPA.Logging
/// </summary> /// </summary>
/// <param name="e">the exception to log</param> /// <param name="e">the exception to log</param>
public virtual void Warn(Exception e) => Log(Level.Warning, e); public virtual void Warn(Exception e) => Log(Level.Warning, e);
/// <summary> /// <summary>
/// Sends an error message.
/// Sends an error message.
/// Equivalent to Log(Level.Error, message). /// Equivalent to Log(Level.Error, message).
/// <see cref="Log(Level, string)"/> /// <see cref="Log(Level, string)"/>
/// </summary> /// </summary>
/// <param name="message">the message to log</param> /// <param name="message">the message to log</param>
public virtual void Error(string message) => Log(Level.Error, message); public virtual void Error(string message) => Log(Level.Error, message);
/// <summary> /// <summary>
/// Sends an exception as an error message. /// Sends an exception as an error message.
/// Equivalent to Log(Level.Error, e); /// Equivalent to Log(Level.Error, e);
@ -182,13 +207,15 @@ namespace IPA.Logging
/// </summary> /// </summary>
/// <param name="e">the exception to log</param> /// <param name="e">the exception to log</param>
public virtual void Error(Exception e) => Log(Level.Error, e); public virtual void Error(Exception e) => Log(Level.Error, e);
/// <summary> /// <summary>
/// Sends a critical message.
/// Sends a critical message.
/// Equivalent to Log(Level.Critical, message). /// Equivalent to Log(Level.Critical, message).
/// <see cref="Log(Level, string)"/> /// <see cref="Log(Level, string)"/>
/// </summary> /// </summary>
/// <param name="message">the message to log</param> /// <param name="message">the message to log</param>
public virtual void Critical(string message) => Log(Level.Critical, message); public virtual void Critical(string message) => Log(Level.Critical, message);
/// <summary> /// <summary>
/// Sends an exception as a critical message. /// Sends an exception as a critical message.
/// Equivalent to Log(Level.Critical, e); /// Equivalent to Log(Level.Critical, e);
@ -197,4 +224,4 @@ namespace IPA.Logging
/// <param name="e">the exception to log</param> /// <param name="e">the exception to log</param>
public virtual void Critical(Exception e) => Log(Level.Critical, e); public virtual void Critical(Exception e) => Log(Level.Critical, e);
} }
}
}

+ 5
- 5
IPA.Loader/Logging/Printers/GZFilePrinter.cs View File

@ -12,17 +12,19 @@ namespace IPA.Logging.Printers
public abstract class GZFilePrinter : LogPrinter, IDisposable public abstract class GZFilePrinter : LogPrinter, IDisposable
{ {
[DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern bool CreateHardLink(
private static extern bool CreateHardLink(
string lpFileName, string lpFileName,
string lpExistingFileName, string lpExistingFileName,
IntPtr lpSecurityAttributes IntPtr lpSecurityAttributes
); );
private FileInfo fileInfo; private FileInfo fileInfo;
/// <summary> /// <summary>
/// The <see cref="StreamWriter"/> that writes to the GZip file. /// The <see cref="StreamWriter"/> that writes to the GZip file.
/// </summary> /// </summary>
protected StreamWriter FileWriter; protected StreamWriter FileWriter;
private GZipStream zstream; private GZipStream zstream;
private FileStream fstream; private FileStream fstream;
@ -99,9 +101,7 @@ namespace IPA.Logging.Printers
fstream.Dispose(); fstream.Dispose();
} }
/// <summary>
/// Disposes the file printer.
/// </summary>
/// <inheritdoc />
public void Dispose() public void Dispose()
{ {
Dispose(true); Dispose(true);
@ -128,4 +128,4 @@ namespace IPA.Logging.Printers
} }
} }
} }
}
}

+ 1
- 1
IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs View File

@ -38,4 +38,4 @@ namespace IPA.Logging.Printers
return finfo; return finfo;
} }
} }
}
}

+ 2
- 2
IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs View File

@ -21,7 +21,7 @@ namespace IPA.Logging.Printers
/// <returns></returns> /// <returns></returns>
protected override FileInfo GetFileInfo() protected override FileInfo GetFileInfo()
{ {
var logsDir = new DirectoryInfo(Path.Combine("Logs",name));
var logsDir = new DirectoryInfo(Path.Combine("Logs", name));
logsDir.Create(); logsDir.Create();
var finfo = new FileInfo(Path.Combine(logsDir.FullName, $"{DateTime.Now:yyyy.MM.dd.HH.mm}.log")); var finfo = new FileInfo(Path.Combine(logsDir.FullName, $"{DateTime.Now:yyyy.MM.dd.HH.mm}.log"));
return finfo; return finfo;
@ -49,4 +49,4 @@ namespace IPA.Logging.Printers
FileWriter.WriteLine(Logger.LogFormat, line, logName, time, level.ToString().ToUpper()); FileWriter.WriteLine(Logger.LogFormat, line, logName, time, level.ToString().ToUpper());
} }
} }
}
}

+ 1
- 1
IPA.Loader/Logging/Printers/PluginSubLogPrinter.cs View File

@ -52,4 +52,4 @@ namespace IPA.Logging.Printers
FileWriter.WriteLine("[{2} @ {1:HH:mm:ss}] {0}", line, time, level.ToString().ToUpper()); FileWriter.WriteLine("[{2} @ {1:HH:mm:ss}] {0}", line, time, level.ToString().ToUpper());
} }
} }
}
}

+ 23
- 3
IPA.Loader/Logging/StandardLogger.cs View File

@ -51,6 +51,10 @@ namespace IPA.Logging
new GlobalLogFilePrinter() new GlobalLogFilePrinter()
}; };
/// <summary>
/// Adds to the default printer pool that all printers inherit from. Printers added this way will be passed every message from every logger.
/// </summary>
/// <param name="printer"></param>
internal static void AddDefaultPrinter(LogPrinter printer) internal static void AddDefaultPrinter(LogPrinter printer)
{ {
defaultPrinters.Add(printer); defaultPrinters.Add(printer);
@ -63,11 +67,16 @@ namespace IPA.Logging
/// All levels defined by this filter will be sent to loggers. All others will be ignored. /// All levels defined by this filter will be sent to loggers. All others will be ignored.
/// </summary> /// </summary>
public static LogLevel PrintFilter { get; set; } = LogLevel.All; public static LogLevel PrintFilter { get; set; } = LogLevel.All;
private readonly List<LogPrinter> printers = new List<LogPrinter>(); private readonly List<LogPrinter> printers = new List<LogPrinter>();
private readonly StandardLogger parent; private readonly StandardLogger parent;
private readonly Dictionary<string, StandardLogger> children = new Dictionary<string, StandardLogger>(); private readonly Dictionary<string, StandardLogger> children = new Dictionary<string, StandardLogger>();
/// <summary>
/// Configures internal debug settings based on the config passed in.
/// </summary>
/// <param name="cfg"></param>
internal static void Configure(SelfConfig cfg) internal static void Configure(SelfConfig cfg)
{ {
showSourceClass = cfg.Debug.ShowCallSource; showSourceClass = cfg.Debug.ShowCallSource;
@ -102,6 +111,11 @@ namespace IPA.Logging
} }
} }
/// <summary>
/// Gets a child printer with the given name, either constructing a new one or using one that was already made.
/// </summary>
/// <param name="name"></param>
/// <returns>a child <see cref="StandardLogger"/> with the given sub-name</returns>
internal StandardLogger GetChild(string name) internal StandardLogger GetChild(string name)
{ {
if (!children.TryGetValue(name, out var child)) if (!children.TryGetValue(name, out var child))
@ -140,7 +154,7 @@ namespace IPA.Logging
Time = DateTime.Now Time = DateTime.Now
}); });
} }
/// <inheritdoc /> /// <inheritdoc />
/// <summary> /// <summary>
/// An override to <see cref="M:IPA.Logging.Logger.Debug(System.String)" /> which shows the method that called it. /// An override to <see cref="M:IPA.Logging.Logger.Debug(System.String)" /> which shows the method that called it.
@ -169,6 +183,9 @@ namespace IPA.Logging
private static readonly BlockingCollection<LogMessage> logQueue = new BlockingCollection<LogMessage>(); private static readonly BlockingCollection<LogMessage> logQueue = new BlockingCollection<LogMessage>();
private static Thread logThread; private static Thread logThread;
/// <summary>
/// The log printer thread for <see cref="StandardLogger"/>.
/// </summary>
private static void LogThread() private static void LogThread()
{ {
var started = new HashSet<LogPrinter>(); var started = new HashSet<LogPrinter>();
@ -222,6 +239,9 @@ namespace IPA.Logging
} }
} }
/// <summary>
/// Stops and joins the log printer thread.
/// </summary>
internal static void StopLogThread() internal static void StopLogThread()
{ {
logQueue.CompleteAdding(); logQueue.CompleteAdding();
@ -248,4 +268,4 @@ namespace IPA.Logging
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
} }
}
}

+ 3
- 3
IPA.Loader/Updating/SelfPlugin.cs View File

@ -1,5 +1,5 @@
using System;
using IPA.Config;
using IPA.Config;
using System;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
namespace IPA.Updating namespace IPA.Updating
@ -47,4 +47,4 @@ namespace IPA.Updating
{ {
} }
} }
}
}

+ 6
- 6
IPA/Properties/AssemblyInfo.cs View File

@ -1,7 +1,7 @@
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("IPA.Installer")] [assembly: AssemblyTitle("IPA.Installer")]
@ -13,8 +13,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
@ -24,12 +24,12 @@ using System.Runtime.InteropServices;
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version
// Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.12.0")] [assembly: AssemblyVersion("3.12.0")]
[assembly: AssemblyFileVersion("3.12.0")]
[assembly: AssemblyFileVersion("3.12.0")]

BIN
Refs/UnityEngine.CoreModule.dll View File


Loading…
Cancel
Save