Beispiel #1
0
        public CoreRunLib([JetBrains.Annotations.NotNull] ISnapFilesystem filesystem, OSPlatform osPlatform, [JetBrains.Annotations.NotNull] string workingDirectory)
        {
            if (filesystem == null)
            {
                throw new ArgumentNullException(nameof(filesystem));
            }
            if (workingDirectory == null)
            {
                throw new ArgumentNullException(nameof(workingDirectory));
            }

            if (!osPlatform.IsSupportedOsVersion())
            {
                throw new PlatformNotSupportedException();
            }

            _osPlatform = osPlatform;

            var filename = filesystem.PathCombine(workingDirectory, "libcorerun-");

            #if SNAP_BOOTSTRAP
            return;
            #endif

            var rid = osPlatform.BuildRid();
            if (osPlatform == OSPlatform.Windows)
            {
                filename += $"{rid}.dll";
                _libPtr   = NativeMethodsWindows.dlopen(filename);
            }
            else if (osPlatform == OSPlatform.Linux)
            {
                filename += $"{rid}.so";
                _libPtr   = NativeMethodsUnix.dlopen(filename, NativeMethodsUnix.libdl_RTLD_NOW | NativeMethodsUnix.libdl_RTLD_LOCAL);
            }

            if (_libPtr == IntPtr.Zero)
            {
                throw new FileNotFoundException($"Failed to load corerun: {filename}. " +
                                                $"OS: {osPlatform}. " +
                                                $"64-bit OS: {Environment.Is64BitOperatingSystem}. " +
                                                $"Last error: {Marshal.GetLastWin32Error()}.");
            }

            // generic
            pal_is_elevated = new Delegate <pal_is_elevated_delegate>(_libPtr, osPlatform);
            pal_set_icon    = new Delegate <pal_set_icon_delegate>(_libPtr, osPlatform);

            // filesystem
            pal_fs_chmod       = new Delegate <pal_fs_chmod_delegate>(_libPtr, osPlatform);
            pal_fs_file_exists = new Delegate <pal_fs_file_exists_delegate>(_libPtr, osPlatform);
        }