-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
207 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace SiraUtil.Attributes | ||
{ | ||
/// <summary> | ||
/// Allows SiraUtil to detect if plugins are built for release. : D | ||
/// </summary> | ||
[Conditional("DEBUG")] | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] | ||
public sealed class SlogAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// An empty constructor. | ||
/// </summary> | ||
public SlogAttribute() { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.IO; | ||
using IPA.Config.Data; | ||
using IPA.Config.Stores; | ||
|
||
namespace SiraUtil.Converters | ||
{ | ||
/// <summary> | ||
/// A config converter for BSIPA which can serialize and deserialize IO <see cref="FileInfo"/> values. | ||
/// </summary> | ||
public class FileInfoConverter : ValueConverter<FileInfo> | ||
{ | ||
/// <summary> | ||
/// Converts a config value to a <see cref="FileInfo"/> instance. | ||
/// </summary> | ||
/// <param name="value"></param> | ||
/// <param name="parent"></param> | ||
/// <returns></returns> | ||
public override FileInfo FromValue(Value value, object parent) | ||
{ | ||
return value is Text t | ||
? new FileInfo(t.Value) | ||
: throw new System.ArgumentNullException("Value is not a valid IO Path", nameof(value)); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Converts a <see cref="FileInfo"/> instance into a string. | ||
/// </summary> | ||
/// <param name="obj"></param> | ||
/// <param name="parent"></param> | ||
/// <returns></returns> | ||
public override Value ToValue(FileInfo obj, object parent) | ||
{ | ||
return Value.Text(obj.FullName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace SiraUtil.Interfaces | ||
{ | ||
/// <summary> | ||
/// A generic interface which defines a registration. | ||
/// </summary> | ||
/// <typeparam name="T">The type to register.</typeparam> | ||
public interface IRegistrar<T> | ||
{ | ||
/// <summary> | ||
/// Adds a registration to this registrar. | ||
/// </summary> | ||
/// <param name="value"></param> | ||
void Add(T value); | ||
|
||
/// <summary> | ||
/// Removes a registration from this registrar. | ||
/// </summary> | ||
/// <param name="value"></param> | ||
void Remove(T value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace SiraUtil.Interfaces | ||
{ | ||
/// <summary> | ||
/// Controls the state for something to be toggled. | ||
/// </summary> | ||
public interface IToggleable | ||
{ | ||
/// <summary> | ||
/// The toggleability. | ||
/// </summary> | ||
bool Status { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,44 @@ | ||
using IPA.Logging; | ||
using SiraUtil.Zenject; | ||
using System.Reflection; | ||
using System.Collections.Generic; | ||
|
||
namespace SiraUtil.Services | ||
{ | ||
internal class SiraLogManager | ||
{ | ||
internal struct LoggerContext | ||
{ | ||
public Logger logger; | ||
public bool debugMode; | ||
private readonly ZenjectManager _zenjectManager; | ||
private readonly Dictionary<Assembly, LoggerContext> _loggerAssemblies = new Dictionary<Assembly, LoggerContext>(); | ||
|
||
public LoggerContext(Logger logger, bool defaultToDebugMode) | ||
{ | ||
this.logger = logger; | ||
debugMode = defaultToDebugMode; | ||
} | ||
internal SiraLogManager(ZenjectManager zenjectManager) | ||
{ | ||
_zenjectManager = zenjectManager; | ||
} | ||
|
||
private readonly Dictionary<Assembly, LoggerContext> _loggerAssemblies = new Dictionary<Assembly, LoggerContext>(); | ||
|
||
internal void AddLogger(Assembly assembly, Logger logger, bool defaultToDebugMode = false) | ||
{ | ||
if (!_loggerAssemblies.ContainsKey(assembly)) | ||
{ | ||
_loggerAssemblies.Add(assembly, new LoggerContext(logger, defaultToDebugMode)); | ||
var zen = _zenjectManager.GetZenjector(assembly); | ||
_loggerAssemblies.Add(assembly, new LoggerContext(logger, zen.IsSlog || defaultToDebugMode)); | ||
} | ||
} | ||
|
||
internal LoggerContext LoggerFromAssembly(Assembly assembly) | ||
{ | ||
return _loggerAssemblies[assembly]; | ||
} | ||
|
||
internal struct LoggerContext | ||
{ | ||
public Logger logger; | ||
public bool debugMode; | ||
|
||
public LoggerContext(Logger logger, bool defaultToDebugMode) | ||
{ | ||
this.logger = logger; | ||
debugMode = defaultToDebugMode; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.