示例#1
0
 public NativeLibraryBuilder
 (
     ImplementationOptions options = default,
     [CanBeNull] ILibraryPathResolver pathResolver = default
 )
 {
     Options      = options;
     PathResolver = pathResolver ?? new DynamicLinkLibraryPathResolver();
 }
        public NativeLibraryBuilder
        (
            ImplementationOptions options = default,
            [CanBeNull] ILibraryPathResolver pathResolver         = default,
            [CanBeNull] IDynamicAssemblyProvider assemblyProvider = default
        )
        {
            _assemblyProvider = assemblyProvider ?? new TransientDynamicAssemblyProvider(DynamicAssemblyName, !options.HasFlagFast(EnableOptimizations));

            _moduleBuilder = _assemblyProvider.GetDynamicModule();

            Options      = options;
            PathResolver = pathResolver ?? new DynamicLinkLibraryPathResolver();
        }
示例#3
0
        static Interop()
        {
            string pluginsDirectory = null;
            string qmlDirectory     = null;
            string libDirectory     = null;

            ILibraryPathResolver pathResolver = null;

            if (Host.GetExportedSymbol != null)
            {
                // We are loading exported functions from the currently running executable.
                var member = (FieldInfo)typeof(NativeLibraryBase).GetMember("PlatformLoader", BindingFlags.Static | BindingFlags.NonPublic).First();
                member.SetValue(null, new Host.Loader());
                pathResolver = new Host.Loader();
            }
            else
            {
                var internalType = Type.GetType("AdvancedDLSupport.DynamicLinkLibraryPathResolver, AdvancedDLSupport");
                if (internalType != null)
                {
                    pathResolver = (ILibraryPathResolver)Activator.CreateInstance(internalType, new object[] { true });

                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        // This custom path resolver attempts to do a DllImport to get the path that .NET decides.
                        // It may load a special dll from a NuGet package.
                        pathResolver = new WindowsDllImportLibraryPathResolver(pathResolver);
                    }
                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                    {
                        pathResolver = new MacDllImportLibraryPathResolver(pathResolver);
                    }
                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                    {
                        pathResolver = new LinuxDllImportLibraryPathResolver(pathResolver);
                    }

                    var resolveResult = pathResolver.Resolve("QmlNet");

                    if (resolveResult.IsSuccess)
                    {
                        libDirectory = Path.GetDirectoryName(resolveResult.Path);
                        if (!string.IsNullOrEmpty(libDirectory))
                        {
                            // If this library has a plugins/qml directory below it, set it.
                            var potentialPlugisDirectory = Path.Combine(libDirectory, "plugins");
                            if (Directory.Exists(potentialPlugisDirectory))
                            {
                                pluginsDirectory = potentialPlugisDirectory;
                            }

                            var potentialQmlDirectory = Path.Combine(libDirectory, "qml");
                            if (Directory.Exists(potentialQmlDirectory))
                            {
                                qmlDirectory = potentialQmlDirectory;
                            }
                        }
                    }
                }
            }


            var builder = new NativeLibraryBuilder(pathResolver: pathResolver);

            var interop = builder.ActivateInterface <ICombined>("QmlNet");

            Callbacks             = interop;
            NetTypeInfo           = interop;
            NetMethodInfo         = interop;
            NetPropertyInfo       = interop;
            NetTypeManager        = interop;
            QGuiApplication       = interop;
            QQmlApplicationEngine = interop;
            NetVariant            = interop;
            NetReference          = interop;
            NetVariantList        = interop;
            NetTestHelper         = interop;
            NetSignalInfo         = interop;
            QResource             = interop;
            NetDelegate           = interop;
            NetJsValue            = interop;
            QQuickStyle           = interop;
            QtInterop             = interop;
            Utilities             = interop;
            QtWebEngine           = interop;

            if (!string.IsNullOrEmpty(pluginsDirectory))
            {
                Qt.PutEnv("QT_PLUGIN_PATH", pluginsDirectory);
            }
            if (!string.IsNullOrEmpty(qmlDirectory))
            {
                Qt.PutEnv("QML2_IMPORT_PATH", qmlDirectory);
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                if (!string.IsNullOrEmpty(libDirectory) && Directory.Exists(libDirectory))
                {
                    // Even though we opened up the native dll correctly, we need to add
                    // the folder to the path. The reason is because QML plugins aren't
                    // in the same directory and have trouble finding dependencies
                    // that are within our lib folder.
                    Environment.SetEnvironmentVariable("PATH",
                                                       Environment.GetEnvironmentVariable("PATH") + $";{libDirectory}");
                }
            }

            var cb = DefaultCallbacks.Callbacks();

            Callbacks.RegisterCallbacks(ref cb);
        }
示例#4
0
 static DynamicLinkLibraryPathResolver()
 {
     LocalPathResolver = new LocalPathResolver();
     PathResolver      = SelectPathResolver();
 }
示例#5
0
 public WindowsDllImportLibraryPathResolver(ILibraryPathResolver original)
 {
     _original = original;
 }
示例#6
0
        static Interop()
        {
            string pluginsDirectory = null;
            string qmlDirectory     = null;

            ILibraryPathResolver pathResolver = null;
            var internalType = Type.GetType("AdvancedDLSupport.DynamicLinkLibraryPathResolver, AdvancedDLSupport");

            if (internalType != null)
            {
                pathResolver = (ILibraryPathResolver)Activator.CreateInstance(internalType, new object[] { true });

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    // This custom path resolver attempts to do a DllImport to get the path that .NET decides.
                    // It may load a special dll from a NuGet package.
                    pathResolver = new WindowsDllImportLibraryPathResolver(pathResolver);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    pathResolver = new MacDllImportLibraryPathResolver(pathResolver);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    pathResolver = new LinuxDllImportLibraryPathResolver(pathResolver);
                }

                var resolveResult = pathResolver.Resolve("QmlNet");

                if (resolveResult.IsSuccess)
                {
                    var directory = Path.GetDirectoryName(resolveResult.Path);
                    if (!string.IsNullOrEmpty(directory))
                    {
                        // If this library has a plugins/qml directory below it, set it.
                        var potentialPlugisDirectory = Path.Combine(directory, "plugins");
                        if (Directory.Exists(potentialPlugisDirectory))
                        {
                            pluginsDirectory = potentialPlugisDirectory;
                        }

                        var potentialQmlDirectory = Path.Combine(directory, "qml");
                        if (Directory.Exists(potentialQmlDirectory))
                        {
                            qmlDirectory = potentialQmlDirectory;
                        }
                    }
                }
            }


            var builder = new NativeLibraryBuilder(pathResolver: pathResolver);

            var interop = builder.ActivateInterface <ICombined>("QmlNet");

            Callbacks             = interop;
            NetTypeInfo           = interop;
            NetMethodInfo         = interop;
            NetPropertyInfo       = interop;
            NetTypeManager        = interop;
            QGuiApplication       = interop;
            QQmlApplicationEngine = interop;
            NetVariant            = interop;
            NetReference          = interop;
            NetVariantList        = interop;
            NetTestHelper         = interop;
            NetSignalInfo         = interop;
            QResource             = interop;
            NetDelegate           = interop;
            NetJsValue            = interop;
            QQuickStyle           = interop;
            QtInterop             = interop;
            Utilities             = interop;

            if (!string.IsNullOrEmpty(pluginsDirectory))
            {
                Qt.PutEnv("QT_PLUGIN_PATH", pluginsDirectory);
            }
            if (!string.IsNullOrEmpty(qmlDirectory))
            {
                Qt.PutEnv("QML2_IMPORT_PATH", qmlDirectory);
            }

            var cb = DefaultCallbacks.Callbacks();

            Callbacks.RegisterCallbacks(ref cb);
        }
 public MacDllImportLibraryPathResolver(ILibraryPathResolver original)
 {
     _original = original;
 }