#nullable enable
|
|
using IPA.Config;
|
|
using IPA.Logging;
|
|
using System;
|
|
|
|
namespace IPA.AntiMalware
|
|
{
|
|
/// <summary>
|
|
/// Provides a way to access BSIPA's Anti-Malware engine.
|
|
/// </summary>
|
|
/// <see cref="Engine"/>
|
|
/// <see cref="IAntiMalware"/>
|
|
public static class AntiMalwareEngine
|
|
{
|
|
private static IAntiMalware? engine;
|
|
|
|
/// <summary>
|
|
/// Gets the current Anti-Malware engine.
|
|
/// </summary>
|
|
public static IAntiMalware Engine => engine ?? throw new InvalidOperationException();
|
|
|
|
internal static bool IsInitialized => engine != null;
|
|
|
|
internal static void Initialize()
|
|
{
|
|
engine = CreateEngine();
|
|
}
|
|
|
|
private static IAntiMalware CreateEngine()
|
|
{
|
|
IAntiMalware? engine = null;
|
|
if (SelfConfig.AntiMalware_.UseIfAvailable_)
|
|
{
|
|
#if !NET35
|
|
engine = WindowsCOMAntiMalware.TryInitialize();
|
|
#endif
|
|
engine ??= WindowsWin32AntiMalware.TryInitialize();
|
|
}
|
|
engine ??= new NoopAntiMalware();
|
|
|
|
Logger.AntiMalware.Debug($"Antimalware engine initialized with {engine.GetType()}");
|
|
|
|
return engine;
|
|
}
|
|
}
|
|
}
|