Browse Source

- Updated IPA to 4.6 for Beat Saber 0.11

- Updated Logger to use more streamlined queueing that that allows
pull/46/head
Anairkoen Schno 6 years ago
parent
commit
beb9234b11
10 changed files with 90 additions and 55 deletions
  1. +1
    -1
      IPA.Tests/IPA.Tests.csproj
  2. +6
    -2
      IPA/IPA.csproj
  3. +3
    -0
      IPA/app.config
  4. +1
    -1
      IPA/obj/Debug/IPA.csproj.CoreCompileInputs.cache
  5. +1
    -1
      IPA/packages.config
  6. +4
    -2
      IllusionInjector/IllusionInjector.csproj
  7. +1
    -1
      IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache
  8. +4
    -2
      IllusionPlugin/IllusionPlugin.csproj
  9. +68
    -44
      IllusionPlugin/Logger.cs
  10. +1
    -1
      IllusionPlugin/obj/Debug/IllusionPlugin.csproj.CoreCompileInputs.cache

+ 1
- 1
IPA.Tests/IPA.Tests.csproj View File

@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IPA.Tests</RootNamespace>
<AssemblyName>IPA.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>


+ 6
- 2
IPA/IPA.csproj View File

@ -9,9 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IPA</RootNamespace>
<AssemblyName>IPA</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -22,6 +23,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -31,6 +33,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>favicon.ico</ApplicationIcon>
@ -71,6 +74,7 @@
<Compile Include="Shortcut.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>


+ 3
- 0
IPA/app.config View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>

+ 1
- 1
IPA/obj/Debug/IPA.csproj.CoreCompileInputs.cache View File

@ -1 +1 @@
65c33cfc23e8dcfc89c7fd78e8cd8344a2518294
6744afebdfdc05ced46858bdac21e047b0d6e43f

+ 1
- 1
IPA/packages.config View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Mono.Cecil" version="0.9.6.4" targetFramework="net35-client" />
<package id="Mono.Cecil" version="0.9.6.4" targetFramework="net35-client" requireReinstallation="true" />
</packages>

+ 4
- 2
IllusionInjector/IllusionInjector.csproj View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IllusionInjector</RootNamespace>
<AssemblyName>IllusionInjector</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
@ -30,6 +31,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />


+ 1
- 1
IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache View File

@ -1 +1 @@
c4f9eceab04df8633c0ae4f922a37f459ec45217
e3db2f4e6085eb1ed3ec468191bb328ebb0f8b7f

+ 4
- 2
IllusionPlugin/IllusionPlugin.csproj View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IllusionPlugin</RootNamespace>
<AssemblyName>IllusionPlugin</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
@ -31,6 +32,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\IllusionPlugin.XML</DocumentationFile>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />


+ 68
- 44
IllusionPlugin/Logger.cs View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.IO;
using System.Runtime.Remoting.Messaging;
using System.Threading;
@ -7,96 +8,119 @@ using IllusionPlugin;
namespace IllusionPlugin {
public class Logger {
private readonly Queue<logMessage> _logQueue;
private static BlockingCollection<logMessage> _logQueue;
private static Thread _watcherThread;
private static bool _threadRunning;
private readonly FileInfo _logFile;
private readonly Thread _watcherThread;
private bool _threadRunning;
private string ModName;
private logMessage oldLog;
struct logMessage {
public static readonly string logFormat = "[{3} @ {2:HH:mm:ss} | {1}] {0}";
public WarningLevel WarningLevel;
public DateTime Time;
public Logger Log;
public string Message;
public logMessage(string msg, WarningLevel wl) {
public logMessage(string msg, Logger log, DateTime time, WarningLevel wl) {
Message = msg;
WarningLevel = wl;
Log = log;
Time = time;
}
}
enum WarningLevel {
Log, Error, Exception, Warning
}
static void SetupStatic()
{
if (_logQueue == null)
_logQueue = new BlockingCollection<logMessage>();
if (_watcherThread == null || !_watcherThread.IsAlive)
{
_watcherThread = new Thread(QueueWatcher); // { IsBackground = true };
_threadRunning = true;
_watcherThread.Start();
}
}
public Logger(string modName = "Default") {
_logQueue = new Queue<logMessage>();
SetupStatic();
_logFile = GetPath(modName);
_watcherThread = new Thread(QueueWatcher) {IsBackground = true};
_threadRunning = true;
Start();
_logFile.Create().Close();
}
public Logger(IPlugin plugin) {
_logQueue = new Queue<logMessage>();
public Logger(IPlugin plugin)
{
SetupStatic();
_logFile = GetPath(plugin);
_watcherThread = new Thread(QueueWatcher) {IsBackground = true};
_threadRunning = true;
Start();
_logFile.Create().Close();
}
public void Log(string msg) {
if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!");
_logQueue.Enqueue(new logMessage($"[LOG @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Log));
//_logQueue.Add(new logMessage($"[LOG @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Log));
_logQueue.Add(new logMessage(msg, this, DateTime.Now, WarningLevel.Log));
}
public void Error(string msg) {
if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!");
_logQueue.Enqueue(new logMessage($"[ERROR @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Error));
//_logQueue.Add(new logMessage($"[ERROR @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Error));
_logQueue.Add(new logMessage(msg, this, DateTime.Now, WarningLevel.Error));
}
public void Exception(string msg) {
if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!");
_logQueue.Enqueue(new logMessage($"[EXCEPTION @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Exception));
//_logQueue.Add(new logMessage($"[EXCEPTION @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Exception));
_logQueue.Add(new logMessage(msg, this, DateTime.Now, WarningLevel.Exception));
}
public void Warning(string msg) {
if(!_watcherThread.IsAlive) throw new Exception("Logger is Closed!");
_logQueue.Enqueue(new logMessage($"[WARNING @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Warning));
//_logQueue.Add(new logMessage($"[WARNING @ {DateTime.Now:HH:mm:ss} | {ModName}] {msg}", WarningLevel.Warning));
_logQueue.Add(new logMessage(msg, this, DateTime.Now, WarningLevel.Warning));
}
void QueueWatcher() {
_logFile.Create().Close();
while (_threadRunning) {
if (_logQueue.Count > 0) {
_watcherThread.IsBackground = false;
using (var f = _logFile.AppendText()) {
while (_logQueue.Count > 0) {
var d = _logQueue.Dequeue();
if (d.Message == oldLog.Message) return;
oldLog = d;
f.WriteLine(d.Message);
Console.ForegroundColor = GetConsoleColour(d.WarningLevel);
Console.WriteLine(d.Message);
Console.ResetColor();
}
}
static void QueueWatcher() {
//StreamWriter wstream = null;
Dictionary<string, StreamWriter> wstreams = new Dictionary<string, StreamWriter>();
while (_threadRunning && _logQueue.TryTake(out logMessage message, Timeout.Infinite))
{
string msg = string.Format(logMessage.logFormat, message.Message, message.Log.ModName, message.Time, message.WarningLevel);
wstreams[message.Log.ModName] = message.Log._logFile.AppendText();
wstreams[message.Log.ModName].WriteLine(msg);
Console.ForegroundColor = GetConsoleColour(message.WarningLevel);
Console.WriteLine(message.Message);
Console.ResetColor();
_watcherThread.IsBackground = true;
if (_logQueue.Count == 0)
{ // no more messages
foreach (var kvp in wstreams)
{
if (kvp.Value == null) continue;
kvp.Value.Dispose();
wstreams[kvp.Key] = null;
}
}
Thread.Sleep(5);
}
}
void Start() => _watcherThread.Start();
foreach (var kvp in wstreams)
{
if (kvp.Value == null) continue;
kvp.Value.Dispose();
}
}
public void Stop() {
public static void Stop() {
_threadRunning = false;
_watcherThread.Join();
}
ConsoleColor GetConsoleColour(WarningLevel level) {
static ConsoleColor GetConsoleColour(WarningLevel level) {
switch (level) {
case WarningLevel.Log:
return ConsoleColor.Green;
@ -120,7 +144,7 @@ namespace IllusionPlugin {
}
}
public static class DebugExtensions {
public static class LoggerExtensions {
public static Logger GetLogger(this IPlugin plugin) {
return new Logger(plugin);
}


+ 1
- 1
IllusionPlugin/obj/Debug/IllusionPlugin.csproj.CoreCompileInputs.cache View File

@ -1 +1 @@
de4d7d5be2f255b6eb5fe16bec001496ad0c8963
3916871581af94648b18c3cc477ec3f5b61ffa03

Loading…
Cancel
Save