PluginSecurityManager.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Mediabrowser.Model.Entities;
  2. using Mediabrowser.PluginSecurity;
  3. using MediaBrowser.Common.Kernel;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. namespace MediaBrowser.Controller.Plugins
  7. {
  8. public class PluginSecurityManager : BaseManager<Kernel>
  9. {
  10. private bool? _isMBSupporter;
  11. private bool _isMBSupporterInitialized;
  12. private object _isMBSupporterSyncLock = new object();
  13. public bool IsMBSupporter
  14. {
  15. get
  16. {
  17. LazyInitializer.EnsureInitialized(ref _isMBSupporter, ref _isMBSupporterInitialized, ref _isMBSupporterSyncLock, () => GetRegistrationStatus("MBSupporter").Result.IsRegistered);
  18. return _isMBSupporter.Value;
  19. }
  20. }
  21. public PluginSecurityManager(Kernel kernel) : base(kernel)
  22. {
  23. }
  24. public async Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent = null)
  25. {
  26. return await MBRegistration.GetRegistrationStatus(feature, mb2Equivalent).ConfigureAwait(false);
  27. }
  28. public string SupporterKey
  29. {
  30. get { return MBRegistration.SupporterKey; }
  31. set {
  32. if (value != MBRegistration.SupporterKey)
  33. {
  34. MBRegistration.SupporterKey = value;
  35. // Clear this so it will re-evaluate
  36. ResetSupporterInfo();
  37. // And we'll need to restart to re-evaluate the status of plug-ins
  38. Kernel.NotifyPendingRestart();
  39. }
  40. }
  41. }
  42. public string LegacyKey
  43. {
  44. get { return MBRegistration.LegacyKey; }
  45. set {
  46. MBRegistration.LegacyKey = value;
  47. // And we'll need to restart to re-evaluate the status of plug-ins
  48. Kernel.NotifyPendingRestart();
  49. }
  50. }
  51. private void ResetSupporterInfo()
  52. {
  53. _isMBSupporter = null;
  54. _isMBSupporterInitialized = false;
  55. }
  56. }
  57. }