-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathInitializer.cs
More file actions
67 lines (61 loc) · 2.57 KB
/
Copy pathInitializer.cs
File metadata and controls
67 lines (61 loc) · 2.57 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
// Copyright © 2020 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace CefSharp
{
/// <summary>
/// CLR Module Initializer
/// Used to load libcef.dll if required
/// </summary>
public static class Initializer
{
//TODO: Internal debugging only for now, needs improving if users are going to
//get meaningful data from this.
internal static IntPtr? LibCefHandle { get; private set; }
internal static bool LibCefLoaded { get; private set; }
internal static string LibCefPath { get; private set; }
internal static string BrowserSubProcessPath { get; private set; }
internal static string BrowserSubProcessCorePath { get; private set; }
[ModuleInitializer]
internal static void ModuleInitializer()
{
var currentFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var libCefPath = Path.Combine(currentFolder, "libcef.dll");
if (File.Exists(libCefPath))
{
//We didn't load CEF, it was already next to our calling assembly, the
//framework should load it correctly on it's own
LibCefPath = libCefPath;
LibCefLoaded = false;
}
else
{
//TODO: This will need changing if we support ARM64
var arch = Environment.Is64BitProcess ? "x64" : "x86";
var archFolder = $"runtimes\\win-{arch}\\native";
libCefPath = Path.Combine(currentFolder, archFolder, "libcef.dll");
if (File.Exists(libCefPath))
{
LibCefLoaded = NativeLibrary.TryLoad(libCefPath, out IntPtr handle);
if (LibCefLoaded)
{
BrowserSubProcessPath = Path.Combine(currentFolder, archFolder, "CefSharp.BrowserSubprocess.exe");
BrowserSubProcessCorePath = Path.Combine(currentFolder, archFolder, "CefSharp.BrowserSubprocess.Core.dll");
LibCefPath = libCefPath;
LibCefHandle = handle;
}
}
else
{
LibCefPath = libCefPath;
LibCefLoaded = false;
}
}
}
}
}