コード例 #1
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);
        }
コード例 #2
0
ファイル: Interop.cs プロジェクト: moialbla/Qml.Net
        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);
        }
コード例 #3
0
ファイル: Interop.cs プロジェクト: afillebrown/qmlnet
        static Interop()
        {
            IPathResolver   pathResolver = null;
            IPlatformLoader loader       = null;

            if (Host.GetExportedSymbol != null)
            {
                // We are loading exported functions from the currently running executable.
                pathResolver = new Host.Loader();
                loader       = new Host.Loader();
            }
            else
            {
                pathResolver = new DynamicLinkLibraryPathResolver();
                loader       = PlatformLoaderBase.SelectPlatformLoader();
                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 result = pathResolver.Resolve("QmlNet");

            if (!result.IsSuccess)
            {
                throw new Exception("Unable to find the native Qml.Net library." +
                                    " Try calling \"RuntimeManager.DiscoverOrDownloadSuitableQtRuntime();\" in Program.Main()");;
            }

            var library = loader.LoadLibrary(result.Path);

            if (library == IntPtr.Zero)
            {
                throw new Exception("Unable to load native Qml.Net library." +
                                    " Try calling \"RuntimeManager.DiscoverOrDownloadSuitableQtRuntime();\" in Program.Main()");;
            }

            Callbacks             = LoadInteropType <CallbacksInterop>(library, loader);
            NetTypeInfo           = LoadInteropType <NetTypeInfoInterop>(library, loader);
            NetJsValue            = LoadInteropType <NetJsValueInterop>(library, loader);
            NetMethodInfo         = LoadInteropType <NetMethodInfoInterop>(library, loader);
            NetPropertyInfo       = LoadInteropType <NetPropertyInfoInterop>(library, loader);
            NetTypeManager        = LoadInteropType <NetTypeManagerInterop>(library, loader);
            QCoreApplication      = LoadInteropType <QCoreApplicationInterop>(library, loader);
            QQmlApplicationEngine = LoadInteropType <QQmlApplicationEngineInterop>(library, loader);
            NetVariant            = LoadInteropType <NetVariantInterop>(library, loader);
            NetReference          = LoadInteropType <NetReferenceInterop>(library, loader);
            NetVariantList        = LoadInteropType <NetVariantListInterop>(library, loader);
            NetTestHelper         = LoadInteropType <NetTestHelperInterop>(library, loader);
            NetSignalInfo         = LoadInteropType <NetSignalInfoInterop>(library, loader);
            QResource             = LoadInteropType <QResourceInterop>(library, loader);
            NetDelegate           = LoadInteropType <NetDelegateInterop>(library, loader);
            QQuickStyle           = LoadInteropType <QQuickStyleInterop>(library, loader);
            QtInterop             = LoadInteropType <QtInterop>(library, loader);
            Utilities             = LoadInteropType <UtilitiesInterop>(library, loader);
            QtWebEngine           = LoadInteropType <QtWebEngineInterop>(library, loader);
            QTest      = LoadInteropType <QTestInterop>(library, loader);
            NetQObject = LoadInteropType <NetQObjectInterop>(library, loader);
            NetQObjectSignalConnection = LoadInteropType <NetQObjectSignalConnectionInterop>(library, loader);

            // RuntimeManager.ConfigureRuntimeDirectory may set these environment variables.
            // However, they only really work when called with Qt.PutEnv.
            Qt.PutEnv("QT_PLUGIN_PATH", Environment.GetEnvironmentVariable("QT_PLUGIN_PATH"));
            Qt.PutEnv("QML2_IMPORT_PATH", Environment.GetEnvironmentVariable("QML2_IMPORT_PATH"));

            var cb = DefaultCallbacks.Callbacks();

            Callbacks.RegisterCallbacks(ref cb);
        }
コード例 #4
0
        static Interop()
        {
            string pluginsDirectory = null;
            string qmlDirectory     = null;
            string libDirectory     = null;

            IPathResolver   pathResolver = null;
            IPlatformLoader loader       = null;

            if (Host.GetExportedSymbol != null)
            {
                // We are loading exported functions from the currently running executable.
                pathResolver = new Host.Loader();
                loader       = new Host.Loader();
            }
            else
            {
                pathResolver = new DynamicLinkLibraryPathResolver();
                loader       = PlatformLoaderBase.SelectPlatformLoader();
                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;
                        }
                    }
                }

                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 result = pathResolver.Resolve("QmlNet");

            if (!result.IsSuccess)
            {
                throw new Exception("Couldn't find the native Qml.Net library.");
            }

            var library = loader.LoadLibrary(result.Path);

            Callbacks             = LoadInteropType <CallbacksInterop>(library, loader);
            NetTypeInfo           = LoadInteropType <NetTypeInfoInterop>(library, loader);
            NetJsValue            = LoadInteropType <NetJsValueInterop>(library, loader);
            NetMethodInfo         = LoadInteropType <NetMethodInfoInterop>(library, loader);
            NetPropertyInfo       = LoadInteropType <NetPropertyInfoInterop>(library, loader);
            NetTypeManager        = LoadInteropType <NetTypeManagerInterop>(library, loader);
            QGuiApplication       = LoadInteropType <QGuiApplicationInterop>(library, loader);
            QQmlApplicationEngine = LoadInteropType <QQmlApplicationEngineInterop>(library, loader);
            NetVariant            = LoadInteropType <NetVariantInterop>(library, loader);
            NetReference          = LoadInteropType <NetReferenceInterop>(library, loader);
            NetVariantList        = LoadInteropType <NetVariantListInterop>(library, loader);
            NetTestHelper         = LoadInteropType <NetTestHelperInterop>(library, loader);
            NetSignalInfo         = LoadInteropType <NetSignalInfoInterop>(library, loader);
            QResource             = LoadInteropType <QResourceInterop>(library, loader);
            NetDelegate           = LoadInteropType <NetDelegateInterop>(library, loader);
            QQuickStyle           = LoadInteropType <QQuickStyleInterop>(library, loader);
            QtInterop             = LoadInteropType <QtInterop>(library, loader);
            Utilities             = LoadInteropType <UtilitiesInterop>(library, loader);
            QtWebEngine           = LoadInteropType <QtWebEngineInterop>(library, loader);

            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);
        }