Exemplo n.º 1
0
        /// <summary>
        /// Adds a <see cref="CefSharpResolver"/> as an <see cref="AppDomain.AssemblyResolve"/> handler of the <see cref="AppDomain.CurrentDomain"/>.
        /// This is necessary for finding CefSharp assemblies.
        /// </summary>
        /// <param name="resolverArgs">Arguments for customizing how CefSharp / cef resources are searched, or <c>null</c> to use defaults.</param>
        /// <returns>The <see cref="CefSharpResolverArgs"/> object used for initializing the resolver.</returns>
        public static CefSharpResolverArgs AddAssemblyResolverForCefSharp(CefSharpResolverArgs resolverArgs = null)
        {
            var resolverArgsOrDefault = resolverArgs == null?BuildDefaultCefSharpResolverArgs() : resolverArgs;

            AppDomain.CurrentDomain.AssemblyResolve += (sender, eventArgs) => CefSharpResolver.ResolveCefSharp(sender, eventArgs, resolverArgsOrDefault);
            return(resolverArgsOrDefault);
        }
Exemplo n.º 2
0
        public static void InitializeCefSharp(CefSettingsBase cefSettings, CefSharpResolverArgs resolverArgs = null)
        {
            var resolverArgsOrDefault = resolverArgs == null?BuildDefaultCefSharpResolverArgs() : resolverArgs;

            if (resolverArgsOrDefault.BaseDir != null)
            {
                var browserSubprocessFileName         = "CefSharp.BrowserSubprocess.exe";
                var archSpecificBrowserSubprocessPath = Path.Combine(resolverArgsOrDefault.BaseDir,
                                                                     Environment.Is64BitProcess ? "x64" : "x86",
                                                                     browserSubprocessFileName);
                if (File.Exists(archSpecificBrowserSubprocessPath))
                {
                    cefSettings.BrowserSubprocessPath = archSpecificBrowserSubprocessPath;
                }
                else
                {
                    var flatBrowserSubprocessPath = Path.Combine(resolverArgsOrDefault.BaseDir,
                                                                 browserSubprocessFileName);
                    cefSettings.BrowserSubprocessPath = flatBrowserSubprocessPath;
                }
            }
            Cef.Initialize(cefSettings, performDependencyCheck: false, browserProcessHandler: null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Attempts to load missing assembly from either <c>x86</c> or <c>x64</c> subdir.
        /// Required by CefSharp to load the unmanaged dependencies when running using <c>AnyCPU</c>.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="eventArgs">Event arguments.</param>
        /// <param name="resolverArgs">Arguments for customizing how CefSharp / cef resources are searched.
        /// Must not be <c>null</c>.</param>
        /// <returns>Assembly for the correct architecture.</returns>
        public static Assembly ResolveCefSharp(object sender, ResolveEventArgs eventArgs, CefSharpResolverArgs resolverArgs)
        {
            if (eventArgs.Name.StartsWith("CefSharp"))
            {
                string assemblyName = eventArgs.Name.Split(new[] { ',' }, 2)[0] + ".dll";

                string archSpecificPath = Path.Combine(
                    resolverArgs.BaseDir,
                    Environment.Is64BitProcess ? SUBDIR_X64 : SUBDIR_X86,
                    assemblyName);
                if (File.Exists(archSpecificPath))
                {
                    return(Assembly.LoadFile(archSpecificPath));
                }

                string flatPath = Path.Combine(
                    resolverArgs.BaseDir,
                    assemblyName);
                return(File.Exists(flatPath)
                           ? Assembly.LoadFile(flatPath)
                           : null);
            }

            return(null);
        }