using System; using System.Collections.Generic; using System.Reflection; using DiscUtils.CoreCompat; namespace DiscUtils.Setup { /// /// Helps setup new DiscUtils dependencies, when loaded into target programs /// public static class SetupHelper { private static readonly HashSet _alreadyLoaded; static SetupHelper() { _alreadyLoaded = new HashSet(); // Register the core DiscUtils lib RegisterAssembly(ReflectionHelper.GetAssembly(typeof(SetupHelper))); } /// /// Registers the types provided by an assembly to all relevant DiscUtils managers /// /// public static void RegisterAssembly(Assembly assembly) { lock (_alreadyLoaded) { if (!_alreadyLoaded.Add(assembly.FullName)) return; FileSystemManager.RegisterFileSystems(assembly); VirtualDiskManager.RegisterVirtualDiskTypes(assembly); VolumeManager.RegisterLogicalVolumeFactory(assembly); } } /// /// Allows intercepting any file open operation /// /// /// Can be used to wrap the opened file for special use cases, /// modify the parameters for opening files, validate file names /// and many more. /// public static event EventHandler OpeningFile; internal static void OnOpeningFile(object sender, FileOpenEventArgs e) { OpeningFile?.Invoke(sender, e); } } }