|
| 1 | +// Copyright © 2010-2015 The CefSharp Authors. All rights reserved. |
| 2 | +// |
| 3 | +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.IO; |
| 8 | +using System.Reflection; |
| 9 | +using System.Text; |
| 10 | + |
| 11 | +namespace CefSharp |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// DependencyChecker provides a known list of Cef/CefSharp dependencies and |
| 15 | + /// provides helper methods to check for their existance. |
| 16 | + /// </summary> |
| 17 | + public static class DependencyChecker |
| 18 | + { |
| 19 | + public const string LocalesPackFile = @"locales\en-US.pak"; |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// IsWindowsXp - Special case for legacy XP support |
| 23 | + /// </summary> |
| 24 | + public static bool IsWindowsXp { get; set; } |
| 25 | + |
| 26 | + /// <summary> |
| 27 | + /// List of Cef Dependencies |
| 28 | + /// </summary> |
| 29 | + public static string[] CefDependencies = |
| 30 | + { |
| 31 | + // CEF core library |
| 32 | + "libcef.dll", |
| 33 | + // Unicode support |
| 34 | + "icudtl.dat" |
| 35 | + }; |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// List of Cef Resources (pack files) |
| 39 | + /// </summary> |
| 40 | + public static string[] CefResources = |
| 41 | + { |
| 42 | + // Pack Files |
| 43 | + // Note: Contains WebKit image and inspector resources. |
| 44 | + "devtools_resources.pak", |
| 45 | + "cef.pak", |
| 46 | + "cef_100_percent.pak", |
| 47 | + "cef_200_percent.pak" |
| 48 | + }; |
| 49 | + |
| 50 | + public static string[] CefOptionalDependencies = |
| 51 | + { |
| 52 | + // Angle and Direct3D support |
| 53 | + // Note: Without these components HTML5 accelerated content like 2D canvas, 3D CSS and WebGL will not function. |
| 54 | + "libEGL.dll", |
| 55 | + "libGLESv2.dll", |
| 56 | + (IsWindowsXp ? "d3dcompiler_43.dll" : "d3dcompiler_47.dll"), |
| 57 | + // PDF support |
| 58 | + // Note: Without this component printing will not function. |
| 59 | + "pdf.dll", |
| 60 | + //FFmpeg audio and video support |
| 61 | + // Note: Without this component HTML5 audio and video will not function. |
| 62 | + "ffmpegsumo.dll" |
| 63 | + }; |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// List of CefSharp Dependencies |
| 67 | + /// </summary> |
| 68 | + public static string[] CefSharpDependencies = |
| 69 | + { |
| 70 | + "CefSharp.Core.dll", |
| 71 | + "CefSharp.dll", |
| 72 | + "CefSharp.BrowserSubprocess.Core.dll", |
| 73 | + "CefSharp.BrowserSubprocess.exe" |
| 74 | + }; |
| 75 | + |
| 76 | + /// <summary> |
| 77 | + /// CheckDependencies iterates through the list of Cef and CefSharp dependencines |
| 78 | + /// relative to the path provided and returns a list of missing ones |
| 79 | + /// </summary> |
| 80 | + /// <param name="checkOptional">check to see if optional dependencies are present</param> |
| 81 | + /// <param name="packLoadingDisabled">Is loading of pack files disabled?</param> |
| 82 | + /// <param name="path">path to check for dependencies</param> |
| 83 | + /// <param name="resourcesDirPath"></param> |
| 84 | + /// <param name="localePackFile">The locale pack file e.g. <see cref="LocalesPackFile"/> </param> |
| 85 | + /// <returns>List of missing dependencies, if all present an empty List will be returned</returns> |
| 86 | + public static List<string> CheckDependencies(bool checkOptional, bool packLoadingDisabled, string path, string resourcesDirPath, string localePackFile = LocalesPackFile) |
| 87 | + { |
| 88 | + var missingDependencies = new List<string>(); |
| 89 | + |
| 90 | + //Loop through Cef dependencies and add to list if not found |
| 91 | + foreach (var cefDependency in CefDependencies) |
| 92 | + { |
| 93 | + var dependencyPath = Path.Combine(path, cefDependency); |
| 94 | + |
| 95 | + if (!File.Exists(dependencyPath)) |
| 96 | + { |
| 97 | + missingDependencies.Add(cefDependency); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + if (!packLoadingDisabled) |
| 102 | + { |
| 103 | + //Loop through Cef Resources and add to list if not found |
| 104 | + foreach (var cefResource in CefResources) |
| 105 | + { |
| 106 | + var resourcePath = Path.Combine(resourcesDirPath, cefResource); |
| 107 | + |
| 108 | + if (!File.Exists(resourcePath)) |
| 109 | + { |
| 110 | + missingDependencies.Add(cefResource); |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + if (checkOptional) |
| 116 | + { |
| 117 | + //Loop through Cef Optional dependencies and add to list if not found |
| 118 | + foreach (var cefDependency in CefOptionalDependencies) |
| 119 | + { |
| 120 | + var dependencyPath = Path.Combine(path, cefDependency); |
| 121 | + |
| 122 | + if (!File.Exists(dependencyPath)) |
| 123 | + { |
| 124 | + missingDependencies.Add(cefDependency); |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + // Loop through CefSharp dependencies and add to list if not found |
| 130 | + foreach (var cefSharpDependency in CefSharpDependencies) |
| 131 | + { |
| 132 | + var dependencyPath = Path.Combine(path, cefSharpDependency); |
| 133 | + |
| 134 | + if (!File.Exists(dependencyPath)) |
| 135 | + { |
| 136 | + missingDependencies.Add(cefSharpDependency); |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + //If path path is not rooted (doesn't start with a drive letter + folder) |
| 141 | + //then make it relative to the executing assembly. |
| 142 | + var localePath = Path.IsPathRooted(localePackFile) ? localePackFile : Path.Combine(path, localePackFile); |
| 143 | + |
| 144 | + if (!File.Exists(localePath)) |
| 145 | + { |
| 146 | + missingDependencies.Add(localePackFile); |
| 147 | + } |
| 148 | + |
| 149 | + return missingDependencies; |
| 150 | + } |
| 151 | + |
| 152 | + /// <summary> |
| 153 | + /// Checks if all Cef and CefSharp dependencies were found relative to the Executing Assembly. |
| 154 | + /// Shortcut method that calls <see cref="CheckDependencies"/>, throws an Exception if not files are missing. |
| 155 | + /// </summary> |
| 156 | + /// <param name="locale">The locale, if empty then en-US will be used.</param> |
| 157 | + /// <param name="localesDirPath">The path to the locales directory, if empty locales\ will be used.</param> |
| 158 | + /// <param name="resourcesDirPath">The path to the resources directory, if empty the Executing Assembly path is used.</param> |
| 159 | + /// <param name="packLoadingDisabled">Is loading of pack files disabled?</param> |
| 160 | + /// <exception cref="Exception">Throw when not all dependencies are present</exception> |
| 161 | + public static void AssertAllDependenciesPresent(string locale, string localesDirPath, string resourcesDirPath, bool packLoadingDisabled) |
| 162 | + { |
| 163 | + var executingAssembly = Assembly.GetExecutingAssembly(); |
| 164 | + |
| 165 | + var path = Path.GetDirectoryName(executingAssembly.Location); |
| 166 | + |
| 167 | + if(string.IsNullOrEmpty(locale)) |
| 168 | + { |
| 169 | + locale = "en-US"; |
| 170 | + } |
| 171 | + |
| 172 | + if (string.IsNullOrEmpty(localesDirPath)) |
| 173 | + { |
| 174 | + localesDirPath = @"locales"; |
| 175 | + } |
| 176 | + |
| 177 | + if (string.IsNullOrEmpty(resourcesDirPath)) |
| 178 | + { |
| 179 | + resourcesDirPath = path; |
| 180 | + } |
| 181 | + |
| 182 | + var missingDependencies = CheckDependencies(true, packLoadingDisabled, path, resourcesDirPath, Path.Combine(localesDirPath, locale + ".pak")); |
| 183 | + |
| 184 | + if (missingDependencies.Count > 0) |
| 185 | + { |
| 186 | + var builder = new StringBuilder(); |
| 187 | + builder.AppendLine("Unable to locate required Cef/CefSharp dependencies:"); |
| 188 | + |
| 189 | + foreach (var missingDependency in missingDependencies) |
| 190 | + { |
| 191 | + builder.AppendLine("Missing:" + missingDependency); |
| 192 | + } |
| 193 | + |
| 194 | + builder.AppendLine("Executing Assembly Path:" + path); |
| 195 | + |
| 196 | + throw new Exception(builder.ToString()); |
| 197 | + } |
| 198 | + } |
| 199 | + } |
| 200 | +} |
0 commit comments