You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

  1. #nullable enable
  2. using IPA.Config;
  3. using IPA.Logging;
  4. namespace IPA.AntiMalware
  5. {
  6. /// <summary>
  7. /// Provides a way to access BSIPA's Anti-Malware engine.
  8. /// </summary>
  9. /// <see cref="Engine"/>
  10. /// <see cref="IAntiMalware"/>
  11. public static class AntiMalwareEngine
  12. {
  13. /// <summary>
  14. /// Gets the current Anti-Malware engine.
  15. /// </summary>
  16. public static IAntiMalware Engine { get; } = InitializeEngine();
  17. private static IAntiMalware InitializeEngine()
  18. {
  19. IAntiMalware? engine = null;
  20. if (SelfConfig.AntiMalware_.UseIfAvailable_)
  21. {
  22. #if !NET35
  23. engine = WindowsCOMAntiMalware.TryInitialize();
  24. #endif
  25. engine ??= WindowsWin32AntiMalware.TryInitialize();
  26. }
  27. engine ??= new NoopAntiMalware();
  28. Logger.AntiMalware.Debug($"Antimalware engine initialized with {engine.GetType()}");
  29. return engine;
  30. }
  31. }
  32. }