-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
96 lines (82 loc) · 3.19 KB
/
App.xaml.cs
File metadata and controls
96 lines (82 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows;
using CefSharp;
namespace CefSharp.MinimalExample.WpfXBap
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
#region Constructor
/// <summary>
///
/// </summary>
public App()
{
IBrowserProcessHandler browserProcessHandler;
AppDomain.CurrentDomain.AssemblyResolve += Resolver;
browserProcessHandler = null;
//Any CefSharp references have to be in another method with NonInlining
// attribute so the assembly rolver has time to do it's thing.
InitializeCefSharp(browserProcessHandler);
}
#endregion
#region Protected Methods
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnExit(ExitEventArgs e)
{
Cef.Shutdown();
base.OnExit(e);
}
#endregion
#region Private Methods
[MethodImpl(MethodImplOptions.NoInlining)]
private static void InitializeCefSharp(IBrowserProcessHandler browserProcessHandler)
{
CefSettings settings;
try
{
settings = new CefSettings();
// Set BrowserSubProcessPath based on app bitness at runtime
settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", "CefSharp.BrowserSubprocess.exe");
Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: browserProcessHandler);
}
catch (FileNotFoundException exception)
{
Debug.WriteLine(exception.Message);
}
}
/// <summary>
/// Will attempt to load missing assembly from either x86 or x64 subdir
/// Required by CefSharp to load the unmanaged dependencies when running using AnyCPU
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <returns></returns>
private static Assembly Resolver(object sender, ResolveEventArgs e)
{
Assembly resolvedAssembly;
string assemblyName;
string archSpecificPath;
resolvedAssembly = null;
if (e.Name.StartsWith("CefSharp") == true)
{
//https://github.com/cefsharp/CefSharp/issues/1714
assemblyName = e.Name.Split(new[] { ',' }, 2)[0] + ".dll";
archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", assemblyName);
//LoadFile does not load files into the load-from context, and does not resolve dependencies using the load path
resolvedAssembly = File.Exists(archSpecificPath) ? Assembly.LoadFile(archSpecificPath) : null;
}
return resolvedAssembly;
}
#endregion
}
}