-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Implement DependencyChecker #900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0eda968
8a7b9e2
591b477
2b89238
a17b145
ce32740
a188b86
36ea815
a9762bb
fea3d8f
be41287
76ea449
b12f131
475067b
3a47bbb
4ad11e7
ea2ad10
ccbaebd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| // Copyright © 2010-2015 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.Collections.Generic; | ||
| using System.IO; | ||
| using System.Reflection; | ||
| using System.Text; | ||
|
|
||
| namespace CefSharp | ||
| { | ||
| /// <summary> | ||
| /// DependencyChecker provides a known list of Cef/CefSharp dependencies and | ||
| /// provides helper methods to check for their existance. | ||
| /// </summary> | ||
| public static class DependencyChecker | ||
| { | ||
| public const string LocalesPackFile = @"locales\en-US.pak"; | ||
|
|
||
| /// <summary> | ||
| /// IsWindowsXp - Special case for legacy XP support | ||
| /// </summary> | ||
| public static bool IsWindowsXp { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// List of Cef Dependencies | ||
| /// </summary> | ||
| public static string[] CefDependencies = | ||
| { | ||
| // CEF core library | ||
| "libcef.dll", | ||
| // Unicode support | ||
| "icudtl.dat" | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// List of Cef Resources (pack files) | ||
| /// </summary> | ||
| public static string[] CefResources = | ||
| { | ||
| // Pack Files | ||
| // Note: Contains WebKit image and inspector resources. | ||
| "devtools_resources.pak", | ||
| "cef.pak", | ||
| "cef_100_percent.pak", | ||
| "cef_200_percent.pak" | ||
| }; | ||
|
|
||
| public static string[] CefOptionalDependencies = | ||
| { | ||
| // Angle and Direct3D support | ||
| // Note: Without these components HTML5 accelerated content like 2D canvas, 3D CSS and WebGL will not function. | ||
| "libEGL.dll", | ||
| "libGLESv2.dll", | ||
| (IsWindowsXp ? "d3dcompiler_43.dll" : "d3dcompiler_47.dll"), | ||
| // PDF support | ||
| // Note: Without this component printing will not function. | ||
| "pdf.dll", | ||
| //FFmpeg audio and video support | ||
| // Note: Without this component HTML5 audio and video will not function. | ||
| "ffmpegsumo.dll" | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// List of CefSharp Dependencies | ||
| /// </summary> | ||
| public static string[] CefSharpDependencies = | ||
| { | ||
| "CefSharp.Core.dll", | ||
| "CefSharp.dll", | ||
| "CefSharp.BrowserSubprocess.Core.dll", | ||
| "CefSharp.BrowserSubprocess.exe" | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// CheckDependencies iterates through the list of Cef and CefSharp dependencines | ||
| /// relative to the path provided and returns a list of missing ones | ||
| /// </summary> | ||
| /// <param name="checkOptional">check to see if optional dependencies are present</param> | ||
| /// <param name="packLoadingDisabled">Is loading of pack files disabled?</param> | ||
| /// <param name="path">path to check for dependencies</param> | ||
| /// <param name="resourcesDirPath"></param> | ||
| /// <param name="localePackFile">The locale pack file e.g. <see cref="LocalesPackFile"/> </param> | ||
| /// <returns>List of missing dependencies, if all present an empty List will be returned</returns> | ||
| public static List<string> CheckDependencies(bool checkOptional, bool packLoadingDisabled, string path, string resourcesDirPath, string localePackFile = LocalesPackFile) | ||
| { | ||
| var missingDependencies = new List<string>(); | ||
|
|
||
| //Loop through Cef dependencies and add to list if not found | ||
| foreach (var cefDependency in CefDependencies) | ||
| { | ||
| var dependencyPath = Path.Combine(path, cefDependency); | ||
|
|
||
| if (!File.Exists(dependencyPath)) | ||
| { | ||
| missingDependencies.Add(cefDependency); | ||
| } | ||
| } | ||
|
|
||
| if (!packLoadingDisabled) | ||
| { | ||
| //Loop through Cef Resources and add to list if not found | ||
| foreach (var cefResource in CefResources) | ||
| { | ||
| var resourcePath = Path.Combine(resourcesDirPath, cefResource); | ||
|
|
||
| if (!File.Exists(resourcePath)) | ||
| { | ||
| missingDependencies.Add(cefResource); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (checkOptional) | ||
| { | ||
| //Loop through Cef Optional dependencies and add to list if not found | ||
| foreach (var cefDependency in CefOptionalDependencies) | ||
| { | ||
| var dependencyPath = Path.Combine(path, cefDependency); | ||
|
|
||
| if (!File.Exists(dependencyPath)) | ||
| { | ||
| missingDependencies.Add(cefDependency); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Loop through CefSharp dependencies and add to list if not found | ||
| foreach (var cefSharpDependency in CefSharpDependencies) | ||
| { | ||
| var dependencyPath = Path.Combine(path, cefSharpDependency); | ||
|
|
||
| if (!File.Exists(dependencyPath)) | ||
| { | ||
| missingDependencies.Add(cefSharpDependency); | ||
| } | ||
| } | ||
|
|
||
| //If path path is not rooted (doesn't start with a drive letter + folder) | ||
| //then make it relative to the executing assembly. | ||
| var localePath = Path.IsPathRooted(localePackFile) ? localePackFile : Path.Combine(path, localePackFile); | ||
|
|
||
| if (!File.Exists(localePath)) | ||
| { | ||
| missingDependencies.Add(localePackFile); | ||
| } | ||
|
|
||
| return missingDependencies; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Checks if all Cef and CefSharp dependencies were found relative to the Executing Assembly. | ||
| /// Shortcut method that calls <see cref="CheckDependencies"/>, throws an Exception if not files are missing. | ||
| /// </summary> | ||
| /// <param name="locale">The locale, if empty then en-US will be used.</param> | ||
| /// <param name="localesDirPath">The path to the locales directory, if empty locales\ will be used.</param> | ||
| /// <param name="resourcesDirPath">The path to the resources directory, if empty the Executing Assembly path is used.</param> | ||
| /// <param name="packLoadingDisabled">Is loading of pack files disabled?</param> | ||
| /// <exception cref="Exception">Throw when not all dependencies are present</exception> | ||
| public static void AssertAllDependenciesPresent(string locale, string localesDirPath, string resourcesDirPath, bool packLoadingDisabled) | ||
| { | ||
| var executingAssembly = Assembly.GetExecutingAssembly(); | ||
|
|
||
| var path = Path.GetDirectoryName(executingAssembly.Location); | ||
|
|
||
| if(string.IsNullOrEmpty(locale)) | ||
| { | ||
| locale = "en-US"; | ||
| } | ||
|
|
||
| if (string.IsNullOrEmpty(localesDirPath)) | ||
| { | ||
| localesDirPath = @"locales"; | ||
| } | ||
|
|
||
| if (string.IsNullOrEmpty(resourcesDirPath)) | ||
| { | ||
| resourcesDirPath = path; | ||
| } | ||
|
|
||
| var missingDependencies = CheckDependencies(true, packLoadingDisabled, path, resourcesDirPath, Path.Combine(localesDirPath, locale + ".pak")); | ||
|
|
||
| if (missingDependencies.Count > 0) | ||
| { | ||
| var builder = new StringBuilder(); | ||
| builder.AppendLine("Unable to locate required Cef/CefSharp dependencies:"); | ||
|
|
||
| foreach (var missingDependency in missingDependencies) | ||
| { | ||
| builder.AppendLine("Missing:" + missingDependency); | ||
| } | ||
|
|
||
| builder.AppendLine("Executing Assembly Path:" + path); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also add an informational reminder in this string about locales\xxxx.pak that explains what they do if we know even though I would never suggest checking for the dependency to exist.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rassilon Not sure I understand, can you clarify? |
||
| throw new Exception(builder.ToString()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whenever I see gobs of bool parameters I usually think: Are you really sure using a flag enum isn't the correct thing to do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pack loading is a special case.
checkOptionalwould be replaced with an enum if we went down that path.