public static void Init(TestContext context)
        {
            _ = context;

            string absPath = TestHelper.GetProgramAbsolutePath();

            BaseDir   = Path.GetFullPath(Path.Combine(absPath, "..", "..", ".."));
            SampleDir = Path.Combine(BaseDir, "Samples");

            string libPath = GetNativeLibPath();

            XZInit.GlobalInit(libPath);
        }
        public static void Init(TestContext context)
        {
            string absPath = TestHelper.GetProgramAbsolutePath();

            BaseDir   = Path.GetFullPath(Path.Combine(absPath, "..", "..", ".."));
            SampleDir = Path.Combine(BaseDir, "Samples");

            string arch = null;

            switch (RuntimeInformation.OSArchitecture)
            {
            case Architecture.X86:
                arch = "x86";
                break;

            case Architecture.X64:
                arch = "x64";
                break;

            case Architecture.Arm:
                arch = "armhf";
                break;

            case Architecture.Arm64:
                arch = "arm64";
                break;
            }

            string libPath = null;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                libPath = Path.Combine(absPath, arch, "liblzma.dll");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                libPath = Path.Combine(absPath, arch, "liblzma.so");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                libPath = Path.Combine(absPath, arch, "liblzma.dylib");
            }

            if (libPath == null || !File.Exists(libPath))
            {
                throw new PlatformNotSupportedException();
            }

            XZInit.GlobalInit(libPath);
        }
Beispiel #3
0
        private static void Initialize()
        {
            string arch         = RuntimeInformation.OSArchitecture.ToString().ToLower();
            string foundLibPath = string.Empty;
            string libPath;
            string rid;
            string libName;

            // Determine Platform (needed for proper Runtime ID)
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                rid     = $"win-{arch}";
                libName = "liblzma.dll";
            }
            else
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                rid     = $"linux-{arch}";
                libName = "liblzma.so";
            }
            else
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                rid     = $"osx-{arch}";
                libName = "liblzma.dylib";
            }
            else
            {
                // Unknown platform
                throw new PlatformNotSupportedException("Unknown runtime platform!");
            }

            // Try to search for the lib in the working directory and the application binary directory
            foreach (var relPath in new List <string> {
                ".", AppDomain.CurrentDomain.BaseDirectory
            })
            {
                // Try first the lib name directly
                libPath = Path.Combine(relPath, libName);
                if (System.IO.File.Exists(libPath))
                {
                    foundLibPath = libPath;
                    break;
                }

                // Try the runtimes/RID/native location
                // This is the default location for netstandard native libs
                libPath = Path.Combine(relPath, "runtimes", rid, "native", libName);
                if (System.IO.File.Exists(libPath))
                {
                    foundLibPath = libPath;
                    break;
                }
            }

            // Try the OS search path if nothing is found yet
            if (string.IsNullOrEmpty(foundLibPath))
            {
                var values = Environment.GetEnvironmentVariable("PATH");
                foreach (string path in values.Split(Path.PathSeparator))
                {
                    libPath = Path.Combine(path, libName);
                    if (System.IO.File.Exists(libPath))
                    {
                        foundLibPath = libPath;
                        break;
                    }
                }
            }

            if (string.IsNullOrEmpty(foundLibPath))
            {
                throw new PlatformNotSupportedException($"Unable to find {libName}");
            }

            // Initialize XZ library
            XZInit.GlobalInit(foundLibPath);
        }