Browse Source

Added documentation to those that needed it, and internalized those that don't.

piracy-check
Anairkoen Schno 6 years ago
parent
commit
b91940cacd
14 changed files with 160 additions and 27 deletions
  1. +1
    -0
      IPA.Loader/IPA.Loader.csproj
  2. +1
    -1
      IPA.Loader/Loader/Composite/CompositeBSPlugin.cs
  3. +1
    -1
      IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs
  4. +3
    -3
      IPA.Loader/Loader/PluginComponent.cs
  5. +13
    -3
      IPA.Loader/Loader/PluginManager.cs
  6. +19
    -4
      IPA.Loader/Logging/Printers/ColoredConsolePrinter.cs
  7. +17
    -1
      IPA.Loader/Logging/Printers/GZFilePrinter.cs
  8. +19
    -2
      IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs
  9. +23
    -2
      IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs
  10. +18
    -4
      IPA.Loader/Logging/StandardLogger.cs
  11. +1
    -1
      IPA.Loader/Updating/Backup/BackupUnit.cs
  12. +8
    -0
      IPA.Loader/Utilities/Extensions.cs
  13. +27
    -2
      IPA.Loader/Utilities/LoneFunctions.cs
  14. +9
    -3
      IPA.Loader/Utilities/SteamCheck.cs

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

@ -22,6 +22,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>bin\Debug\IPA.Loader.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>


+ 1
- 1
IPA.Loader/Loader/Composite/CompositeBSPlugin.cs View File

@ -9,7 +9,7 @@ using Logger = IPA.Logging.Logger;
namespace IPA.Loader.Composite namespace IPA.Loader.Composite
{ {
public class CompositeBSPlugin : IBeatSaberPlugin
internal class CompositeBSPlugin : IBeatSaberPlugin
{ {
IEnumerable<IBeatSaberPlugin> plugins; IEnumerable<IBeatSaberPlugin> plugins;


+ 1
- 1
IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs View File

@ -11,7 +11,7 @@ using Logger = IPA.Logging.Logger;
namespace IPA.Loader.Composite namespace IPA.Loader.Composite
{ {
#pragma warning disable CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete
public class CompositeIPAPlugin : IPlugin
internal class CompositeIPAPlugin : IPlugin
{ {
IEnumerable<IPlugin> plugins; IEnumerable<IPlugin> plugins;


+ 3
- 3
IPA.Loader/Loader/PluginComponent.cs View File

@ -9,13 +9,13 @@ using IPA.Logging;
namespace IPA.Loader namespace IPA.Loader
{ {
public class PluginComponent : MonoBehaviour
internal class PluginComponent : MonoBehaviour
{ {
private CompositeBSPlugin bsPlugins; private CompositeBSPlugin bsPlugins;
private CompositeIPAPlugin ipaPlugins; private CompositeIPAPlugin ipaPlugins;
private bool quitting = false; private bool quitting = false;
public static PluginComponent Create()
internal static PluginComponent Create()
{ {
Application.logMessageReceived += delegate (string condition, string stackTrace, LogType type) Application.logMessageReceived += delegate (string condition, string stackTrace, LogType type)
{ {
@ -87,7 +87,7 @@ namespace IPA.Loader
ipaPlugins.OnLevelWasLoaded(level); ipaPlugins.OnLevelWasLoaded(level);
} }
public void OnLevelWasInitialized(int level)
void OnLevelWasInitialized(int level)
{ {
ipaPlugins.OnLevelWasInitialized(level); ipaPlugins.OnLevelWasInitialized(level);
} }


+ 13
- 3
IPA.Loader/Loader/PluginManager.cs View File

@ -5,6 +5,7 @@ using IPA.Updating;
using IPA.Utilities; using IPA.Utilities;
using Mono.Cecil; using Mono.Cecil;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@ -17,17 +18,23 @@ using System.Threading.Tasks;
namespace IPA.Loader namespace IPA.Loader
{ {
/// <summary>
/// The manager class for all plugins.
/// </summary>
public static class PluginManager public static class PluginManager
{ {
#pragma warning disable CS0618 // Type or member is obsolete (IPlugin) #pragma warning disable CS0618 // Type or member is obsolete (IPlugin)
public class BSPluginMeta
internal class BSPluginMeta
{ {
public IBeatSaberPlugin Plugin { get; internal set; } public IBeatSaberPlugin Plugin { get; internal set; }
public string Filename { get; internal set; } public string Filename { get; internal set; }
public ModsaberModInfo ModsaberInfo { get; internal set; } public ModsaberModInfo ModsaberInfo { get; internal set; }
} }
/// <summary>
/// An <see cref="IEnumerable"/> of new Beat Saber plugins
/// </summary>
public static IEnumerable<IBeatSaberPlugin> BSPlugins public static IEnumerable<IBeatSaberPlugin> BSPlugins
{ {
get get
@ -52,6 +59,9 @@ namespace IPA.Loader
} }
} }
/// <summary>
/// An <see cref="IEnumerable"/> of old IPA plugins
/// </summary>
public static IEnumerable<IPlugin> Plugins public static IEnumerable<IPlugin> Plugins
{ {
get get
@ -288,7 +298,7 @@ namespace IPA.Loader
return new Tuple<IEnumerable<BSPluginMeta>, IEnumerable<IPlugin>>(bsPlugins, ipaPlugins); return new Tuple<IEnumerable<BSPluginMeta>, IEnumerable<IPlugin>>(bsPlugins, ipaPlugins);
} }
public class AppInfo
internal class AppInfo
{ {
[DllImport("kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = false)] [DllImport("kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = false)]
private static extern int GetModuleFileName(HandleRef hModule, StringBuilder buffer, int length); private static extern int GetModuleFileName(HandleRef hModule, StringBuilder buffer, int length);


+ 19
- 4
IPA.Loader/Logging/Printers/ColoredConsolePrinter.cs View File

@ -8,18 +8,33 @@ using IPA.Logging;
namespace IPA.Logging.Printers namespace IPA.Logging.Printers
{ {
/// <summary>
/// Prints a pretty message to the console.
/// </summary>
public class ColoredConsolePrinter : LogPrinter public class ColoredConsolePrinter : LogPrinter
{ {
Logger.LogLevel filter = Logger.LogLevel.All; Logger.LogLevel filter = Logger.LogLevel.All;
public override Logger.LogLevel Filter { get => filter; set => filter = value; }
ConsoleColor color = Console.ForegroundColor;
public ConsoleColor Color { get => color; set => color = value; }
/// <summary>
/// A filter for this specific printer.
/// </summary>
public override Logger.LogLevel Filter { get => filter; set => filter = value; }
/// <summary>
/// The color to print messages as.
/// </summary>
public ConsoleColor Color { get; set; } = Console.ForegroundColor;
/// <summary>
/// Prints an entry to the associated file.
/// </summary>
/// <param name="level">the <see cref="Logger.Level"/> of the message</param>
/// <param name="time">the <see cref="DateTime"/> the message was recorded at</param>
/// <param name="logName">the name of the log that sent the message</param>
/// <param name="message">the message to print</param>
public override void Print(Logger.Level level, DateTime time, string logName, string message) public override void Print(Logger.Level level, DateTime time, string logName, string message)
{ {
if (((byte)level & (byte)StandardLogger.PrintFilter) == 0) return; if (((byte)level & (byte)StandardLogger.PrintFilter) == 0) return;
Console.ForegroundColor = color;
Console.ForegroundColor = Color;
foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
Console.WriteLine(string.Format(Logger.LogFormat, line, logName, time, level.ToString().ToUpper())); Console.WriteLine(string.Format(Logger.LogFormat, line, logName, time, level.ToString().ToUpper()));
Console.ResetColor(); Console.ResetColor();


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

@ -10,6 +10,9 @@ using System.Threading.Tasks;
namespace IPA.Logging.Printers namespace IPA.Logging.Printers
{ {
/// <summary>
/// A <see cref="LogPrinter"/> abstract class that provides the utilities to write to a GZip file.
/// </summary>
public abstract class GZFilePrinter : LogPrinter public abstract class GZFilePrinter : LogPrinter
{ {
[DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
@ -20,13 +23,20 @@ namespace IPA.Logging.Printers
); );
[DllImport("Kernel32.dll")] [DllImport("Kernel32.dll")]
static extern Int32 GetLastError();
static extern int GetLastError();
private FileInfo fileInfo; private FileInfo fileInfo;
/// <summary>
/// The <see cref="StreamWriter"/> that writes to the GZip file.
/// </summary>
protected StreamWriter fileWriter; protected StreamWriter fileWriter;
private GZipStream zstream; private GZipStream zstream;
private FileStream fstream; private FileStream fstream;
/// <summary>
/// Gets the <see cref="FileInfo"/> for the file to write to without the .gz extension.
/// </summary>
/// <returns></returns>
protected abstract FileInfo GetFileInfo(); protected abstract FileInfo GetFileInfo();
private void InitLog() private void InitLog()
@ -64,6 +74,9 @@ namespace IPA.Logging.Printers
} }
} }
/// <summary>
/// Called at the start of any print session.
/// </summary>
public override sealed void StartPrint() public override sealed void StartPrint()
{ {
InitLog(); InitLog();
@ -76,6 +89,9 @@ namespace IPA.Logging.Printers
fileWriter = new StreamWriter(zstream, new UTF8Encoding(false)); fileWriter = new StreamWriter(zstream, new UTF8Encoding(false));
} }
/// <summary>
/// Called at the end of any print session.
/// </summary>
public override sealed void EndPrint() public override sealed void EndPrint()
{ {
fileWriter.Flush(); fileWriter.Flush();


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

@ -8,16 +8,33 @@ using IPA.Logging;
namespace IPA.Logging.Printers namespace IPA.Logging.Printers
{ {
class GlobalLogFilePrinter : GZFilePrinter
/// <summary>
/// A printer for all messages to a unified log location.
/// </summary>
public class GlobalLogFilePrinter : GZFilePrinter
{ {
/// <summary>
/// Provides a filter for this specific printer.
/// </summary>
public override Logger.LogLevel Filter { get; set; } = Logger.LogLevel.All; public override Logger.LogLevel Filter { get; set; } = Logger.LogLevel.All;
public override void Print(IPA.Logging.Logger.Level level, DateTime time, string logName, string message)
/// <summary>
/// Prints an entry to the associated file.
/// </summary>
/// <param name="level">the <see cref="Logger.Level"/> of the message</param>
/// <param name="time">the <see cref="DateTime"/> the message was recorded at</param>
/// <param name="logName">the name of the log that sent the message</param>
/// <param name="message">the message to print</param>
public override void Print(Logger.Level level, DateTime time, string logName, string message)
{ {
foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
fileWriter.WriteLine(string.Format(Logger.LogFormat, line, logName, time, level.ToString().ToUpper())); fileWriter.WriteLine(string.Format(Logger.LogFormat, line, logName, time, level.ToString().ToUpper()));
} }
/// <summary>
/// Gets the <see cref="FileInfo"/> for the target file.
/// </summary>
/// <returns></returns>
protected override FileInfo GetFileInfo() protected override FileInfo GetFileInfo()
{ {
var logsDir = new DirectoryInfo("Logs"); var logsDir = new DirectoryInfo("Logs");


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

@ -8,12 +8,22 @@ using System.Threading.Tasks;
namespace IPA.Logging.Printers namespace IPA.Logging.Printers
{ {
class PluginLogFilePrinter : GZFilePrinter
/// <summary>
/// Prints log messages to the file specified by the name.
/// </summary>
public class PluginLogFilePrinter : GZFilePrinter
{ {
/// <summary>
/// Provides a filter for this specific printer.
/// </summary>
public override Logger.LogLevel Filter { get; set; } = Logger.LogLevel.All; public override Logger.LogLevel Filter { get; set; } = Logger.LogLevel.All;
private string name; private string name;
/// <summary>
/// Gets the <see cref="FileInfo"/> for the target file.
/// </summary>
/// <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));
@ -22,12 +32,23 @@ namespace IPA.Logging.Printers
return finfo; return finfo;
} }
/// <summary>
/// Creates a new printer with the given name.
/// </summary>
/// <param name="name">the name of the logger</param>
public PluginLogFilePrinter(string name) public PluginLogFilePrinter(string name)
{ {
this.name = name; this.name = name;
} }
public override void Print(IPA.Logging.Logger.Level level, DateTime time, string logName, string message)
/// <summary>
/// Prints an entry to the associated file.
/// </summary>
/// <param name="level">the <see cref="Logger.Level"/> of the message</param>
/// <param name="time">the <see cref="DateTime"/> the message was recorded at</param>
/// <param name="logName">the name of the log that sent the message</param>
/// <param name="message">the message to print</param>
public override void Print(Logger.Level level, DateTime time, string logName, string message)
{ {
foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
fileWriter.WriteLine(string.Format("[{3} @ {2:HH:mm:ss}] {0}", line, logName, time, level.ToString().ToUpper())); fileWriter.WriteLine(string.Format("[{3} @ {2:HH:mm:ss}] {0}", line, logName, time, level.ToString().ToUpper()));


+ 18
- 4
IPA.Loader/Logging/StandardLogger.cs View File

@ -8,12 +8,14 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using IPA; using IPA;
using LoggerBase = IPA.Logging.Logger;
using IPA.Logging.Printers; using IPA.Logging.Printers;
namespace IPA.Logging namespace IPA.Logging
{ {
public class StandardLogger : LoggerBase
/// <summary>
/// The default <see cref="Logger"/> implimentation.
/// </summary>
public class StandardLogger : Logger
{ {
private static readonly IReadOnlyList<LogPrinter> defaultPrinters = new List<LogPrinter>() private static readonly IReadOnlyList<LogPrinter> defaultPrinters = new List<LogPrinter>()
{ {
@ -47,6 +49,9 @@ namespace IPA.Logging
private string logName; private string logName;
private static bool showSourceClass = true; private static bool showSourceClass = true;
/// <summary>
/// All levels defined by this filter will be sent to loggers. All others will be ignored.
/// </summary>
public static LogLevel PrintFilter { get; set; } = LogLevel.InfoUp; public static LogLevel PrintFilter { get; set; } = LogLevel.InfoUp;
private List<LogPrinter> printers = new List<LogPrinter>(defaultPrinters); private List<LogPrinter> printers = new List<LogPrinter>(defaultPrinters);
@ -70,6 +75,11 @@ namespace IPA.Logging
} }
} }
/// <summary>
/// Logs a specific message at a given level.
/// </summary>
/// <param name="level">the message level</param>
/// <param name="message">the message to log</param>
public override void Log(Level level, string message) public override void Log(Level level, string message)
{ {
_logQueue.Add(new LogMessage _logQueue.Add(new LogMessage
@ -80,7 +90,11 @@ namespace IPA.Logging
time = DateTime.Now time = DateTime.Now
}); });
} }
/// <summary>
/// An override to <see cref="Logger.Debug(string)"/> which shows the method that called it.
/// </summary>
/// <param name="message">the message to log</param>
public override void Debug(string message) public override void Debug(string message)
{ // add source to message { // add source to message
var stfm = new StackTrace().GetFrame(1).GetMethod(); var stfm = new StackTrace().GetFrame(1).GetMethod();
@ -144,7 +158,7 @@ namespace IPA.Logging
} }
} }
public static void StopLogThread()
internal static void StopLogThread()
{ {
_logQueue.CompleteAdding(); _logQueue.CompleteAdding();
_logThread.Join(); _logThread.Join();


+ 1
- 1
IPA.Loader/Updating/Backup/BackupUnit.cs View File

@ -69,7 +69,7 @@ namespace IPA.Updating.Backup
/// <summary> /// <summary>
/// Adds a file to the list of changed files and backups it. /// Adds a file to the list of changed files and backups it.
/// </summary> /// </summary>
/// <param name="path"></param>
/// <param name="file"></param>
public void Add(FileInfo file) public void Add(FileInfo file)
{ {
var relativePath = LoneFunctions.GetRelativePath(Environment.CurrentDirectory, file.FullName); var relativePath = LoneFunctions.GetRelativePath(Environment.CurrentDirectory, file.FullName);


+ 8
- 0
IPA.Loader/Utilities/Extensions.cs View File

@ -6,8 +6,16 @@ using System.Threading.Tasks;
namespace IPA.Utilities namespace IPA.Utilities
{ {
/// <summary>
/// A class providing various extension methods.
/// </summary>
public static class Extensions public static class Extensions
{ {
/// <summary>
/// Gets the default value for a given <see cref="Type"/>.
/// </summary>
/// <param name="type">the <see cref="Type"/> to get the default value for</param>
/// <returns>the default value of <paramref name="type"/></returns>
public static object GetDefault(this Type type) public static object GetDefault(this Type type)
{ {
if (type.IsValueType) if (type.IsValueType)


+ 27
- 2
IPA.Loader/Utilities/LoneFunctions.cs View File

@ -7,8 +7,16 @@ using System.Threading.Tasks;
namespace IPA.Utilities namespace IPA.Utilities
{ {
/// <summary>
/// A class providing static utility functions that in any other language would just *exist*.
/// </summary>
public static class LoneFunctions public static class LoneFunctions
{ {
/// <summary>
/// Converts a hex string to a byte array.
/// </summary>
/// <param name="hex">the hex stream</param>
/// <returns>the corresponding byte array</returns>
public static byte[] StringToByteArray(string hex) public static byte[] StringToByteArray(string hex)
{ {
int NumberChars = hex.Length; int NumberChars = hex.Length;
@ -18,6 +26,11 @@ namespace IPA.Utilities
return bytes; return bytes;
} }
/// <summary>
///
/// </summary>
/// <param name="ba"></param>
/// <returns></returns>
public static string ByteArrayToString(byte[] ba) public static string ByteArrayToString(byte[] ba)
{ {
StringBuilder hex = new StringBuilder(ba.Length * 2); StringBuilder hex = new StringBuilder(ba.Length * 2);
@ -30,6 +43,12 @@ namespace IPA.Utilities
// Distributed under the MIT/X11 software license // Distributed under the MIT/X11 software license
// Ref: http://www.opensource.org/licenses/mit-license.php. // Ref: http://www.opensource.org/licenses/mit-license.php.
// From: https://stackoverflow.com/a/8808245/3117125 // From: https://stackoverflow.com/a/8808245/3117125
/// <summary>
/// Uses unsafe code to compare 2 byte arrays quickly.
/// </summary>
/// <param name="a1">array 1</param>
/// <param name="a2">array 2</param>
/// <returns>whether or not they are byte-for-byte equal</returns>
public static unsafe bool UnsafeCompare(byte[] a1, byte[] a2) public static unsafe bool UnsafeCompare(byte[] a1, byte[] a2)
{ {
if (a1 == a2) return true; if (a1 == a2) return true;
@ -48,9 +67,15 @@ namespace IPA.Utilities
} }
} }
public static string GetRelativePath(string filespec, string folder)
/// <summary>
/// Gets a path relative to the provided folder.
/// </summary>
/// <param name="file">the file to relativize</param>
/// <param name="folder">the source folder</param>
/// <returns>a path to get from <paramref name="folder"/> to <paramref name="file"/></returns>
public static string GetRelativePath(string file, string folder)
{ {
Uri pathUri = new Uri(filespec);
Uri pathUri = new Uri(file);
// Folders must end in a slash // Folders must end in a slash
if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString())) if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString()))
{ {


+ 9
- 3
IPA.Loader/Utilities/SteamCheck.cs View File

@ -6,11 +6,17 @@ using System.Threading.Tasks;
namespace IPA.Utilities namespace IPA.Utilities
{ {
/// <summary>
/// Provides a utility to test if this is a Steam build of Beat Saber.
/// </summary>
public static class SteamCheck public static class SteamCheck
{ {
public static Type SteamVRCamera;
public static Type SteamVRExternalCamera;
public static Type SteamVRFade;
private static Type SteamVRCamera;
private static Type SteamVRExternalCamera;
private static Type SteamVRFade;
/// <summary>
/// Returns <see langword="true"/> when called on a Steam installation.
/// </summary>
public static bool IsAvailable => FindSteamVRAsset(); public static bool IsAvailable => FindSteamVRAsset();
private static bool FindSteamVRAsset() private static bool FindSteamVRAsset()


Loading…
Cancel
Save