public void CreateDispose() { string libPath = TestSetup.PackagedMagicPath; using (SimpleFileMagic m = new SimpleFileMagic()) { m.LoadLibrary(libPath); m.MagicVersion(); } }
public static void AssemblyInitalize(TestContext ctx) { BaseDir = Path.GetFullPath(Path.Combine(TestHelper.GetProgramAbsolutePath(), "..", "..", "..")); SampleDir = Path.Combine(BaseDir, "Samples"); const string zlibDllName = "zlibwapi.dll"; const string magicDllName = "libmagic-1.dll"; #if NETCOREAPP const string zlibSoName = "libz.so"; const string zlibDylibName = "libz.dylib"; const string magicSoName = "libmagic.so"; const string magicDylibName = "libmagic.dylib"; #endif string arch = null; switch (RuntimeInformation.ProcessArchitecture) { case Architecture.X86: arch = "x86"; break; case Architecture.X64: arch = "x64"; break; case Architecture.Arm: arch = "armhf"; break; case Architecture.Arm64: arch = "arm64"; break; } bool implicitLoadZLib = false; bool implicitLoadMagic = false; bool implicitLoadPlataform = false; string libDir; #if NETFRAMEWORK libDir = arch; #elif NETCOREAPP libDir = "runtimes"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { libDir = Path.Combine(libDir, "win-"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { libDir = Path.Combine(libDir, "linux-"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { libDir = Path.Combine(libDir, "osx-"); } libDir += arch; libDir = Path.Combine(libDir, "native"); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) #endif { PackagedZLibPath = Path.Combine(libDir, zlibDllName); PackagedMagicPath = Path.Combine(libDir, magicDllName); implicitLoadPlataform = true; } #if NETCOREAPP else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { PackagedZLibPath = Path.Combine(libDir, zlibSoName); PackagedMagicPath = Path.Combine(libDir, magicSoName); implicitLoadZLib = true; implicitLoadMagic = true; implicitLoadPlataform = true; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { PackagedZLibPath = Path.Combine(libDir, zlibDylibName); PackagedMagicPath = Path.Combine(libDir, magicDylibName); implicitLoadZLib = true; } #endif ExplicitZLib = new SimpleZLib(); ExplicitZLib.LoadLibrary(PackagedZLibPath); if (implicitLoadZLib) { ImplicitZLib = new SimpleZLib(); ImplicitZLib.LoadLibrary(); } ExplicitMagic = new SimpleFileMagic(); ExplicitMagic.LoadLibrary(PackagedMagicPath); if (implicitLoadMagic) { ImplicitMagic = new SimpleFileMagic(); ImplicitMagic.LoadLibrary(); } if (implicitLoadPlataform) { PlatformLib = new SimplePlatform(); PlatformLib.LoadLibrary(); } }