From 0eda96841caf71818c38f0e480d2e6f70ba6aec2 Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 24 Mar 2015 10:58:43 +1000 Subject: [PATCH 01/18] Add rough draft of DependencyChecker - loops through list of all Cef/CefSharp dependencies --- CefSharp.Example/CefExample.cs | 6 +- CefSharp/CefSharp.csproj | 1 + CefSharp/DependencyChecker.cs | 113 +++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 CefSharp/DependencyChecker.cs diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index ca5657411e..390f88de38 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics; -using System.Linq; namespace CefSharp.Example { @@ -15,6 +14,11 @@ public static class CefExample public static void Init() { + if(!DependencyChecker.AreAllDependenciesPresent()) + { + throw new Exception("Missing Dependencies"); + } + // Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys // Environment.SetEnvironmentVariable("GOOGLE_API_KEY", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", ""); diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 6c635dc745..584423aa08 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -91,6 +91,7 @@ + diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs new file mode 100644 index 0000000000..bd1afbdf6d --- /dev/null +++ b/CefSharp/DependencyChecker.cs @@ -0,0 +1,113 @@ +// 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.Collections.Generic; +using System.IO; +using System.Reflection; + +namespace CefSharp +{ + /// + /// TODO: Expand to support optional dependencies + /// + public static class DependencyChecker + { + /// + /// List of Cef Dependencies - currently contains all possabilties + /// + public static string[] CefDependencies = + { + "libcef.dll", + "libEGL.dll", + "libGLESv2.dll", + "pdf.dll", + "icudtl.dat", + "ffmpegsumo.dll", + "d3dcompiler_43.dll", + "d3dcompiler_47.dll", + "devtools_resources.pak", + "cef.pak", + "cef_100_percent.pak", + "cef_200_percent.pak" + }; + + /// + /// List of CefSharp Dependencies + /// + public static string[] CefSharpDependencies = + { + "CefSharp.Core.dll", + "CefSharp.dll", + "CefSharp.BrowserSubprocess.Core.dll", + "CefSharp.BrowserSubprocess.exe" + }; + + /// + /// Check Dependencies relative to the executing assembly + /// + /// List of missing dependencies, if all present an empty List will be returned + public static List CheckDependencies() + { + var executingAssembly = Assembly.GetExecutingAssembly(); + + var path = Path.GetDirectoryName(executingAssembly.Location); + + return CheckDependencies(path); + } + + /// + /// CheckDependencies iterates through the list of Cef and CefSharp dependencines + /// relative to the path provided and returns a list of missing ones + /// + /// path to check for dependencies + /// The local pack file + /// List of missing dependencies, if all present an empty List will be returned + public static List CheckDependencies(string path, string localePackFile = @"locales\en-US.pak") + { + var missingDependencies = new List(); + + //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); + } + } + + // 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); + } + } + + var localePath = Path.Combine(path, localePackFile); + + if (!File.Exists(localePath)) + { + missingDependencies.Add(localePackFile); + } + + return missingDependencies; + } + + /// + /// Shortcut method that calls + /// + /// Returns true of missing dependency count is 0 + public static bool AreAllDependenciesPresent() + { + var missingDependencies = CheckDependencies(); + + return missingDependencies.Count == 0; + } + } +} From 8a7b9e2adbc1522948ede8e1c1f7d77e35c38b9b Mon Sep 17 00:00:00 2001 From: amaitland Date: Tue, 24 Mar 2015 11:05:38 +1000 Subject: [PATCH 02/18] Untabify --- CefSharp/DependencyChecker.cs | 204 +++++++++++++++++----------------- 1 file changed, 102 insertions(+), 102 deletions(-) diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index bd1afbdf6d..af271f6570 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -8,106 +8,106 @@ namespace CefSharp { - /// - /// TODO: Expand to support optional dependencies - /// - public static class DependencyChecker - { - /// - /// List of Cef Dependencies - currently contains all possabilties - /// - public static string[] CefDependencies = - { - "libcef.dll", - "libEGL.dll", - "libGLESv2.dll", - "pdf.dll", - "icudtl.dat", - "ffmpegsumo.dll", - "d3dcompiler_43.dll", - "d3dcompiler_47.dll", - "devtools_resources.pak", - "cef.pak", - "cef_100_percent.pak", - "cef_200_percent.pak" - }; - - /// - /// List of CefSharp Dependencies - /// - public static string[] CefSharpDependencies = - { - "CefSharp.Core.dll", - "CefSharp.dll", - "CefSharp.BrowserSubprocess.Core.dll", - "CefSharp.BrowserSubprocess.exe" - }; - - /// - /// Check Dependencies relative to the executing assembly - /// - /// List of missing dependencies, if all present an empty List will be returned - public static List CheckDependencies() - { - var executingAssembly = Assembly.GetExecutingAssembly(); - - var path = Path.GetDirectoryName(executingAssembly.Location); - - return CheckDependencies(path); - } - - /// - /// CheckDependencies iterates through the list of Cef and CefSharp dependencines - /// relative to the path provided and returns a list of missing ones - /// - /// path to check for dependencies - /// The local pack file - /// List of missing dependencies, if all present an empty List will be returned - public static List CheckDependencies(string path, string localePackFile = @"locales\en-US.pak") - { - var missingDependencies = new List(); - - //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); - } - } - - // 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); - } - } - - var localePath = Path.Combine(path, localePackFile); - - if (!File.Exists(localePath)) - { - missingDependencies.Add(localePackFile); - } - - return missingDependencies; - } - - /// - /// Shortcut method that calls - /// - /// Returns true of missing dependency count is 0 - public static bool AreAllDependenciesPresent() - { - var missingDependencies = CheckDependencies(); - - return missingDependencies.Count == 0; - } - } + /// + /// TODO: Expand to support optional dependencies + /// + public static class DependencyChecker + { + /// + /// List of Cef Dependencies - currently contains all possabilties + /// + public static string[] CefDependencies = + { + "libcef.dll", + "libEGL.dll", + "libGLESv2.dll", + "pdf.dll", + "icudtl.dat", + "ffmpegsumo.dll", + "d3dcompiler_43.dll", + "d3dcompiler_47.dll", + "devtools_resources.pak", + "cef.pak", + "cef_100_percent.pak", + "cef_200_percent.pak" + }; + + /// + /// List of CefSharp Dependencies + /// + public static string[] CefSharpDependencies = + { + "CefSharp.Core.dll", + "CefSharp.dll", + "CefSharp.BrowserSubprocess.Core.dll", + "CefSharp.BrowserSubprocess.exe" + }; + + /// + /// Check Dependencies relative to the executing assembly + /// + /// List of missing dependencies, if all present an empty List will be returned + public static List CheckDependencies() + { + var executingAssembly = Assembly.GetExecutingAssembly(); + + var path = Path.GetDirectoryName(executingAssembly.Location); + + return CheckDependencies(path); + } + + /// + /// CheckDependencies iterates through the list of Cef and CefSharp dependencines + /// relative to the path provided and returns a list of missing ones + /// + /// path to check for dependencies + /// The local pack file + /// List of missing dependencies, if all present an empty List will be returned + public static List CheckDependencies(string path, string localePackFile = @"locales\en-US.pak") + { + var missingDependencies = new List(); + + //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); + } + } + + // 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); + } + } + + var localePath = Path.Combine(path, localePackFile); + + if (!File.Exists(localePath)) + { + missingDependencies.Add(localePackFile); + } + + return missingDependencies; + } + + /// + /// Shortcut method that calls + /// + /// Returns true of missing dependency count is 0 + public static bool AreAllDependenciesPresent() + { + var missingDependencies = CheckDependencies(); + + return missingDependencies.Count == 0; + } + } } From 591b47775b56065af22e40b9107994f692256bae Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 11:08:02 +1000 Subject: [PATCH 03/18] Move localePackFile param with default value to first overload of CheckDependencies Plan is to use `CefSettings.Locale` and `CefSettings.LocalesDirPath` to infer the users local preferences --- CefSharp/DependencyChecker.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index af271f6570..5cf7968dd3 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -46,14 +46,15 @@ public static class DependencyChecker /// /// Check Dependencies relative to the executing assembly /// + /// The local pack file, if empty then locales\en-US.pak will be used /// List of missing dependencies, if all present an empty List will be returned - public static List CheckDependencies() + public static List CheckDependencies(string localePackFile = @"locales\en-US.pak") { var executingAssembly = Assembly.GetExecutingAssembly(); var path = Path.GetDirectoryName(executingAssembly.Location); - return CheckDependencies(path); + return CheckDependencies(path, localePackFile); } /// @@ -61,9 +62,9 @@ public static List CheckDependencies() /// relative to the path provided and returns a list of missing ones /// /// path to check for dependencies - /// The local pack file + /// The local pack file e.g. en-US /// List of missing dependencies, if all present an empty List will be returned - public static List CheckDependencies(string path, string localePackFile = @"locales\en-US.pak") + public static List CheckDependencies(string path, string localePackFile) { var missingDependencies = new List(); From 2b8923813c0e08f4d9eff086ad07bbf75ddfa601 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 11:12:58 +1000 Subject: [PATCH 04/18] Allow for full locales path --- CefSharp/DependencyChecker.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index 5cf7968dd3..5aaea69ee5 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -90,7 +90,9 @@ public static List CheckDependencies(string path, string localePackFile) } } - var localePath = Path.Combine(path, localePackFile); + //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)) { @@ -101,7 +103,7 @@ public static List CheckDependencies(string path, string localePackFile) } /// - /// Shortcut method that calls + /// Shortcut method that calls /// /// Returns true of missing dependency count is 0 public static bool AreAllDependenciesPresent() From a17b145968f0501482e9956ae101a9ebfe171195 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 11:19:44 +1000 Subject: [PATCH 05/18] Expand Locale support to check `CefSettings` for user specified values For now code is in `CefExample` will eventually be moved into `Cef.Initialize()` --- CefSharp.Example/CefExample.cs | 16 +++++++++++----- CefSharp/DependencyChecker.cs | 13 ++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index 390f88de38..82ac8728a7 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -14,11 +14,6 @@ public static class CefExample public static void Init() { - if(!DependencyChecker.AreAllDependenciesPresent()) - { - throw new Exception("Missing Dependencies"); - } - // Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys // Environment.SetEnvironmentVariable("GOOGLE_API_KEY", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", ""); @@ -56,6 +51,17 @@ public static void Init() SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); + var locale = string.IsNullOrEmpty(settings.Locale) ? "en-US" : settings.Locale; + + var localPackPath = string.IsNullOrEmpty(settings.LocalesDirPath) ? @"locales\" : settings.LocalesDirPath; + + localPackPath += locale + ".pak"; + + if (!DependencyChecker.AreAllDependenciesPresent(localPackPath)) + { + throw new Exception("Missing Dependencies"); + } + if (!Cef.Initialize(settings)) { throw new Exception("Unable to Initialize Cef"); diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index 5aaea69ee5..279177f596 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -13,6 +13,8 @@ namespace CefSharp /// public static class DependencyChecker { + private const string LocalPackPath = @"locales\en-US.pak"; + /// /// List of Cef Dependencies - currently contains all possabilties /// @@ -46,9 +48,9 @@ public static class DependencyChecker /// /// Check Dependencies relative to the executing assembly /// - /// The local pack file, if empty then locales\en-US.pak will be used + /// The locale pack file, if empty then locales\en-US.pak will be used /// List of missing dependencies, if all present an empty List will be returned - public static List CheckDependencies(string localePackFile = @"locales\en-US.pak") + public static List CheckDependencies(string localePackFile = LocalPackPath) { var executingAssembly = Assembly.GetExecutingAssembly(); @@ -62,7 +64,7 @@ public static List CheckDependencies(string localePackFile = @"locales\e /// relative to the path provided and returns a list of missing ones /// /// path to check for dependencies - /// The local pack file e.g. en-US + /// The locale pack file e.g. locales\en-US.pak /// List of missing dependencies, if all present an empty List will be returned public static List CheckDependencies(string path, string localePackFile) { @@ -105,10 +107,11 @@ public static List CheckDependencies(string path, string localePackFile) /// /// Shortcut method that calls /// + /// The locale pack file, if empty then locales\en-US.pak will be used /// Returns true of missing dependency count is 0 - public static bool AreAllDependenciesPresent() + public static bool AreAllDependenciesPresent(string localePackPath = LocalPackPath) { - var missingDependencies = CheckDependencies(); + var missingDependencies = CheckDependencies(localePackPath); return missingDependencies.Count == 0; } From ce3274032be03a50a68e895e2f532e052a7e7a10 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 11:20:00 +1000 Subject: [PATCH 06/18] Fix typo in CefExample --- CefSharp.Example/CefExample.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index 82ac8728a7..b7d4e253d8 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -21,7 +21,7 @@ public static void Init() //Chromium Command Line args //http://peter.sh/experiments/chromium-command-line-switches/ - //NOTE: Note all relevant in relation to `CefSharp`, use for reference purposes only. + //NOTE: Not all relevant in relation to `CefSharp`, use for reference purposes only. var settings = new CefSettings(); settings.RemoteDebuggingPort = 8088; From a188b862c4089cb51ddfab5349c80684c54a0b42 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 11:34:35 +1000 Subject: [PATCH 07/18] Refactor code so now AssetAllDependenciesPresent throws an exception if dependencies missing Error message needs some work --- CefSharp.Example/CefExample.cs | 5 +--- CefSharp/DependencyChecker.cs | 44 +++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index b7d4e253d8..abef3d340f 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -57,10 +57,7 @@ public static void Init() localPackPath += locale + ".pak"; - if (!DependencyChecker.AreAllDependenciesPresent(localPackPath)) - { - throw new Exception("Missing Dependencies"); - } + DependencyChecker.AssetAllDependenciesPresent(localPackPath); if (!Cef.Initialize(settings)) { diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index 279177f596..f9ca41269d 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -2,9 +2,11 @@ // // 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 { @@ -45,20 +47,6 @@ public static class DependencyChecker "CefSharp.BrowserSubprocess.exe" }; - /// - /// Check Dependencies relative to the executing assembly - /// - /// The locale pack file, if empty then locales\en-US.pak will be used - /// List of missing dependencies, if all present an empty List will be returned - public static List CheckDependencies(string localePackFile = LocalPackPath) - { - var executingAssembly = Assembly.GetExecutingAssembly(); - - var path = Path.GetDirectoryName(executingAssembly.Location); - - return CheckDependencies(path, localePackFile); - } - /// /// CheckDependencies iterates through the list of Cef and CefSharp dependencines /// relative to the path provided and returns a list of missing ones @@ -105,15 +93,33 @@ public static List CheckDependencies(string path, string localePackFile) } /// - /// Shortcut method that calls + /// Checks if all Cef and CefSharp dependencies were found relative to the Executing Assembly. + /// Shortcut method that calls , throws an Exception if not files are missing. /// /// The locale pack file, if empty then locales\en-US.pak will be used - /// Returns true of missing dependency count is 0 - public static bool AreAllDependenciesPresent(string localePackPath = LocalPackPath) + /// Throw when not all dependencies are present + public static void AssetAllDependenciesPresent(string localePackPath = LocalPackPath) { - var missingDependencies = CheckDependencies(localePackPath); + var executingAssembly = Assembly.GetExecutingAssembly(); - return missingDependencies.Count == 0; + var path = Path.GetDirectoryName(executingAssembly.Location); + + var missingDependencies = CheckDependencies(path, localePackPath); + + 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); + + throw new Exception(builder.ToString()); + } } } } From 36ea815fe2beed20fcb7354af6e0e8bbfc67a7a1 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 11:46:09 +1000 Subject: [PATCH 08/18] First attempt at splitting out into required/optional dependencies Based on https://github.com/cefsharp/cef-binary/blob/master/README.txt --- CefSharp/DependencyChecker.cs | 37 +++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index f9ca41269d..ecb90fb690 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -22,20 +22,34 @@ public static class DependencyChecker /// public static string[] CefDependencies = { + // CEF core library "libcef.dll", - "libEGL.dll", - "libGLESv2.dll", - "pdf.dll", + // Unicode support "icudtl.dat", - "ffmpegsumo.dll", - "d3dcompiler_43.dll", - "d3dcompiler_47.dll", + // 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", + "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", + }; + /// /// List of CefSharp Dependencies /// @@ -69,6 +83,17 @@ public static List CheckDependencies(string path, string localePackFile) } } + //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) { From a9762bbb5f5cf9b4c399594b651e6b54748aca02 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 11:48:12 +1000 Subject: [PATCH 09/18] Add optional bool for checking dependencies --- CefSharp/DependencyChecker.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index ecb90fb690..7085e98304 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -47,7 +47,7 @@ public static class DependencyChecker "pdf.dll", //FFmpeg audio and video support // Note: Without this component HTML5 audio and video will not function. - "ffmpegsumo.dll", + "ffmpegsumo.dll" }; /// @@ -65,10 +65,11 @@ public static class DependencyChecker /// CheckDependencies iterates through the list of Cef and CefSharp dependencines /// relative to the path provided and returns a list of missing ones /// + /// check to see if optional dependencies are present /// path to check for dependencies /// The locale pack file e.g. locales\en-US.pak /// List of missing dependencies, if all present an empty List will be returned - public static List CheckDependencies(string path, string localePackFile) + public static List CheckDependencies(bool checkOptional, string path, string localePackFile) { var missingDependencies = new List(); @@ -83,14 +84,17 @@ public static List CheckDependencies(string path, string localePackFile) } } - //Loop through Cef Optional dependencies and add to list if not found - foreach (var cefDependency in CefOptionalDependencies) + if (checkOptional) { - var dependencyPath = Path.Combine(path, cefDependency); - - if (!File.Exists(dependencyPath)) + //Loop through Cef Optional dependencies and add to list if not found + foreach (var cefDependency in CefOptionalDependencies) { - missingDependencies.Add(cefDependency); + var dependencyPath = Path.Combine(path, cefDependency); + + if (!File.Exists(dependencyPath)) + { + missingDependencies.Add(cefDependency); + } } } @@ -129,7 +133,7 @@ public static void AssetAllDependenciesPresent(string localePackPath = LocalPack var path = Path.GetDirectoryName(executingAssembly.Location); - var missingDependencies = CheckDependencies(path, localePackPath); + var missingDependencies = CheckDependencies(true, path, localePackPath); if (missingDependencies.Count > 0) { From fea3d8f6aff1a6aa0bdcaf2ba23dc8cdb7589c8f Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 11:56:39 +1000 Subject: [PATCH 10/18] Allow setting cefSettings->resources_dir_path 'The fully qualified path for the resources directory. If this value is empty the cef.pak and/or devtools_resources.pak files must be located in the module directory' --- CefSharp.Core/CefSettings.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CefSharp.Core/CefSettings.h b/CefSharp.Core/CefSettings.h index aab0b0389a..45a1dfffc7 100644 --- a/CefSharp.Core/CefSettings.h +++ b/CefSharp.Core/CefSettings.h @@ -79,6 +79,12 @@ namespace CefSharp void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->locales_dir_path, value); } } + virtual property String^ ResourcesDirPath + { + String^ get() { return StringUtils::ToClr(_cefSettings->resources_dir_path); } + void set(String^ value) { StringUtils::AssignNativeFromClr(_cefSettings->resources_dir_path, value); } + } + virtual property String^ LogFile { String^ get() { return StringUtils::ToClr(_cefSettings->log_file); } From be4128749754b56f31bf8be57eae04b8ed1db50f Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 12:05:11 +1000 Subject: [PATCH 11/18] Refactor to pass params directly in from CefSettings - make life easier then implementing checks in `Cef.Initialize()` --- CefSharp.Example/CefExample.cs | 8 +----- CefSharp/DependencyChecker.cs | 50 ++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index abef3d340f..52d94bcbd8 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -51,13 +51,7 @@ public static void Init() SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); - var locale = string.IsNullOrEmpty(settings.Locale) ? "en-US" : settings.Locale; - - var localPackPath = string.IsNullOrEmpty(settings.LocalesDirPath) ? @"locales\" : settings.LocalesDirPath; - - localPackPath += locale + ".pak"; - - DependencyChecker.AssetAllDependenciesPresent(localPackPath); + DependencyChecker.AssetAllDependenciesPresent(settings.Locale, settings.LocalesDirPath, settings.ResourcesDirPath); if (!Cef.Initialize(settings)) { diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index 7085e98304..860aa57641 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -15,17 +15,22 @@ namespace CefSharp /// public static class DependencyChecker { - private const string LocalPackPath = @"locales\en-US.pak"; - /// - /// List of Cef Dependencies - currently contains all possabilties + /// List of Cef Dependencies /// public static string[] CefDependencies = { // CEF core library "libcef.dll", // Unicode support - "icudtl.dat", + "icudtl.dat" + }; + + /// + /// List of Cef Resources (pack files) + /// + public static string[] CefResources = + { // Pack Files // Note: Contains WebKit image and inspector resources. "devtools_resources.pak", @@ -68,8 +73,9 @@ public static class DependencyChecker /// check to see if optional dependencies are present /// path to check for dependencies /// The locale pack file e.g. locales\en-US.pak + /// /// List of missing dependencies, if all present an empty List will be returned - public static List CheckDependencies(bool checkOptional, string path, string localePackFile) + public static List CheckDependencies(bool checkOptional, string path, string localePackFile, string resourcesDirPath) { var missingDependencies = new List(); @@ -84,6 +90,17 @@ public static List CheckDependencies(bool checkOptional, string path, st } } + //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 @@ -125,15 +142,32 @@ public static List CheckDependencies(bool checkOptional, string path, st /// Checks if all Cef and CefSharp dependencies were found relative to the Executing Assembly. /// Shortcut method that calls , throws an Exception if not files are missing. /// - /// The locale pack file, if empty then locales\en-US.pak will be used + /// The locale, if empty then en-US will be used. + /// The path to the locales directory, if empty locales\ will be used. + /// The path to the resources directory, if empty the Executing Assembly path is used. /// Throw when not all dependencies are present - public static void AssetAllDependenciesPresent(string localePackPath = LocalPackPath) + public static void AssetAllDependenciesPresent(string locale, string localesDirPath, string resourcesDirPath) { var executingAssembly = Assembly.GetExecutingAssembly(); var path = Path.GetDirectoryName(executingAssembly.Location); - var missingDependencies = CheckDependencies(true, path, localePackPath); + if(string.IsNullOrEmpty(locale)) + { + locale = "en-US"; + } + + if (string.IsNullOrEmpty(localesDirPath)) + { + localesDirPath = @"locales\"; + } + + if (string.IsNullOrEmpty(resourcesDirPath)) + { + resourcesDirPath = path; + } + + var missingDependencies = CheckDependencies(true, path, localesDirPath + locale + ".pak", resourcesDirPath); if (missingDependencies.Count > 0) { From 76ea44930afddd1283c6feabd93dae2b5ea545eb Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 12:06:50 +1000 Subject: [PATCH 12/18] Add packLoadingDisabled check --- CefSharp.Example/CefExample.cs | 2 +- CefSharp/DependencyChecker.cs | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index 52d94bcbd8..0a96a4a1ea 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -51,7 +51,7 @@ public static void Init() SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); - DependencyChecker.AssetAllDependenciesPresent(settings.Locale, settings.LocalesDirPath, settings.ResourcesDirPath); + DependencyChecker.AssetAllDependenciesPresent(settings.Locale, settings.LocalesDirPath, settings.ResourcesDirPath, settings.PackLoadingDisabled); if (!Cef.Initialize(settings)) { diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index 860aa57641..9d9b8ac3e9 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -74,8 +74,9 @@ public static class DependencyChecker /// path to check for dependencies /// The locale pack file e.g. locales\en-US.pak /// + /// Is loading of pack files disabled? /// List of missing dependencies, if all present an empty List will be returned - public static List CheckDependencies(bool checkOptional, string path, string localePackFile, string resourcesDirPath) + public static List CheckDependencies(bool checkOptional, string path, string localePackFile, string resourcesDirPath, bool packLoadingDisabled) { var missingDependencies = new List(); @@ -90,14 +91,17 @@ public static List CheckDependencies(bool checkOptional, string path, st } } - //Loop through Cef Resources and add to list if not found - foreach (var cefResource in CefResources) + if (!packLoadingDisabled) { - var resourcePath = Path.Combine(resourcesDirPath, cefResource); - - if (!File.Exists(resourcePath)) + //Loop through Cef Resources and add to list if not found + foreach (var cefResource in CefResources) { - missingDependencies.Add(cefResource); + var resourcePath = Path.Combine(resourcesDirPath, cefResource); + + if (!File.Exists(resourcePath)) + { + missingDependencies.Add(cefResource); + } } } @@ -145,8 +149,9 @@ public static List CheckDependencies(bool checkOptional, string path, st /// The locale, if empty then en-US will be used. /// The path to the locales directory, if empty locales\ will be used. /// The path to the resources directory, if empty the Executing Assembly path is used. + /// Is loading of pack files disabled? /// Throw when not all dependencies are present - public static void AssetAllDependenciesPresent(string locale, string localesDirPath, string resourcesDirPath) + public static void AssetAllDependenciesPresent(string locale, string localesDirPath, string resourcesDirPath, bool packLoadingDisabled) { var executingAssembly = Assembly.GetExecutingAssembly(); @@ -167,7 +172,7 @@ public static void AssetAllDependenciesPresent(string locale, string localesDirP resourcesDirPath = path; } - var missingDependencies = CheckDependencies(true, path, localesDirPath + locale + ".pak", resourcesDirPath); + var missingDependencies = CheckDependencies(true, path, localesDirPath + locale + ".pak", resourcesDirPath, packLoadingDisabled); if (missingDependencies.Count > 0) { From b12f131e9f8efa305cb560eb8ffe40b0d6971ee4 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 12:09:57 +1000 Subject: [PATCH 13/18] Re-add LocalesPackFile default param value (moved to end of function) --- CefSharp/DependencyChecker.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index 9d9b8ac3e9..0cadd60ac4 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -11,10 +11,13 @@ namespace CefSharp { /// - /// TODO: Expand to support optional dependencies + /// DependencyChecker provides a known list of Cef/CefSharp dependencies and + /// provides helper methods to check for their existance. /// public static class DependencyChecker { + public const string LocalesPackFile = @"locales\en-US.pak"; + /// /// List of Cef Dependencies /// @@ -72,11 +75,11 @@ public static class DependencyChecker /// /// check to see if optional dependencies are present /// path to check for dependencies - /// The locale pack file e.g. locales\en-US.pak /// /// Is loading of pack files disabled? + /// The locale pack file e.g. /// List of missing dependencies, if all present an empty List will be returned - public static List CheckDependencies(bool checkOptional, string path, string localePackFile, string resourcesDirPath, bool packLoadingDisabled) + public static List CheckDependencies(bool checkOptional, string path, string resourcesDirPath, bool packLoadingDisabled, string localePackFile = LocalesPackFile) { var missingDependencies = new List(); @@ -172,7 +175,7 @@ public static void AssetAllDependenciesPresent(string locale, string localesDirP resourcesDirPath = path; } - var missingDependencies = CheckDependencies(true, path, localesDirPath + locale + ".pak", resourcesDirPath, packLoadingDisabled); + var missingDependencies = CheckDependencies(true, path, resourcesDirPath, packLoadingDisabled, localesDirPath + locale + ".pak"); if (missingDependencies.Count > 0) { From 475067bdfa9b67a9954c8aa535fb62028a8d85a3 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 12:11:15 +1000 Subject: [PATCH 14/18] Reorder method params (move packLoadingDisabled to second param) --- CefSharp/DependencyChecker.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index 0cadd60ac4..651eef1715 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -74,12 +74,12 @@ public static class DependencyChecker /// relative to the path provided and returns a list of missing ones /// /// check to see if optional dependencies are present + /// Is loading of pack files disabled? /// path to check for dependencies /// - /// Is loading of pack files disabled? /// The locale pack file e.g. /// List of missing dependencies, if all present an empty List will be returned - public static List CheckDependencies(bool checkOptional, string path, string resourcesDirPath, bool packLoadingDisabled, string localePackFile = LocalesPackFile) + public static List CheckDependencies(bool checkOptional, bool packLoadingDisabled, string path, string resourcesDirPath, string localePackFile = LocalesPackFile) { var missingDependencies = new List(); @@ -175,7 +175,7 @@ public static void AssetAllDependenciesPresent(string locale, string localesDirP resourcesDirPath = path; } - var missingDependencies = CheckDependencies(true, path, resourcesDirPath, packLoadingDisabled, localesDirPath + locale + ".pak"); + var missingDependencies = CheckDependencies(true, packLoadingDisabled, path, resourcesDirPath, localesDirPath + locale + ".pak"); if (missingDependencies.Count > 0) { From 3a47bbbedde9415bfb1a52a330fcb23c4824f97c Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 13:53:47 +1000 Subject: [PATCH 15/18] Added IsWindowsXp special case (It's not the best code in the world, don't think it's worth spending too much time on though) Use Path.Combine instead of manual string concat --- CefSharp.Example/CefExample.cs | 3 +++ CefSharp/DependencyChecker.cs | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index 0a96a4a1ea..fa446cf40b 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -51,6 +51,9 @@ public static void Init() SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); + //For special case when Checking Windows Xp Dependencies + //DependencyChecker.IsWindowsXp = true; + DependencyChecker.AssetAllDependenciesPresent(settings.Locale, settings.LocalesDirPath, settings.ResourcesDirPath, settings.PackLoadingDisabled); if (!Cef.Initialize(settings)) diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index 651eef1715..1b082eceea 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -17,6 +17,11 @@ namespace CefSharp public static class DependencyChecker { public const string LocalesPackFile = @"locales\en-US.pak"; + + /// + /// IsWindowsXp - Special case for legacy XP support + /// + public static bool IsWindowsXp { get; set; } /// /// List of Cef Dependencies @@ -48,8 +53,7 @@ public static class DependencyChecker // Note: Without these components HTML5 accelerated content like 2D canvas, 3D CSS and WebGL will not function. "libEGL.dll", "libGLESv2.dll", - "d3dcompiler_43.dll", - "d3dcompiler_47.dll", + (IsWindowsXp ? "d3dcompiler_43.dll" : "d3dcompiler_47.dll"), // PDF support // Note: Without this component printing will not function. "pdf.dll", @@ -167,7 +171,7 @@ public static void AssetAllDependenciesPresent(string locale, string localesDirP if (string.IsNullOrEmpty(localesDirPath)) { - localesDirPath = @"locales\"; + localesDirPath = @"locales"; } if (string.IsNullOrEmpty(resourcesDirPath)) @@ -175,7 +179,7 @@ public static void AssetAllDependenciesPresent(string locale, string localesDirP resourcesDirPath = path; } - var missingDependencies = CheckDependencies(true, packLoadingDisabled, path, resourcesDirPath, localesDirPath + locale + ".pak"); + var missingDependencies = CheckDependencies(true, packLoadingDisabled, path, resourcesDirPath, Path.Combine(localesDirPath, locale + ".pak")); if (missingDependencies.Count > 0) { From 4ad11e7261a3054149e2dc71b7c52774f07c78ce Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 13:59:35 +1000 Subject: [PATCH 16/18] Move dependency check call into Cef.Initialize() - currently not enabled by default --- CefSharp.Core/Cef.h | 10 ++++++++-- CefSharp.Example/CefExample.cs | 5 ++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index b2bd80450f..3232de4693 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -139,21 +139,27 @@ namespace CefSharp /// true if successful; otherwise, false. static bool Initialize(CefSettings^ cefSettings) { - return Initialize(cefSettings, true); + return Initialize(cefSettings, true, false); } /// Initializes CefSharp with user-provided settings. /// CefSharp configuration settings. /// When the Current AppDomain (relative to the thread called on) /// Exits(ProcessExit event) then Shudown will be called. + /// Check that all relevant dependencies avaliable, throws exception if any are missing /// true if successful; otherwise, false. - static bool Initialize(CefSettings^ cefSettings, bool shutdownOnProcessExit) + static bool Initialize(CefSettings^ cefSettings, bool shutdownOnProcessExit, bool performDependencyCheck) { bool success = false; // NOTE: Can only initialize Cef once, so subsiquent calls are ignored. if (!IsInitialized) { + if(performDependencyCheck) + { + DependencyChecker::AssetAllDependenciesPresent(cefSettings->Locale, cefSettings->LocalesDirPath, cefSettings->ResourcesDirPath, cefSettings->PackLoadingDisabled); + } + CefMainArgs main_args; CefRefPtr app(new CefSharpApp(cefSettings)); diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index fa446cf40b..a58391c376 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -51,12 +51,11 @@ public static void Init() SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); + //Cef will check if all dependencies are present //For special case when Checking Windows Xp Dependencies //DependencyChecker.IsWindowsXp = true; - DependencyChecker.AssetAllDependenciesPresent(settings.Locale, settings.LocalesDirPath, settings.ResourcesDirPath, settings.PackLoadingDisabled); - - if (!Cef.Initialize(settings)) + if (!Cef.Initialize(settings, shutdownOnProcessExit: true, performDependencyCheck: true)) { throw new Exception("Unable to Initialize Cef"); } From ea2ad1036a78baab4ee99425d420c6e58780ca82 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 14:27:32 +1000 Subject: [PATCH 17/18] Assert not Asset - fix typo --- CefSharp/DependencyChecker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CefSharp/DependencyChecker.cs b/CefSharp/DependencyChecker.cs index 1b082eceea..0fb0f84b25 100644 --- a/CefSharp/DependencyChecker.cs +++ b/CefSharp/DependencyChecker.cs @@ -158,7 +158,7 @@ public static List CheckDependencies(bool checkOptional, bool packLoadin /// The path to the resources directory, if empty the Executing Assembly path is used. /// Is loading of pack files disabled? /// Throw when not all dependencies are present - public static void AssetAllDependenciesPresent(string locale, string localesDirPath, string resourcesDirPath, bool packLoadingDisabled) + public static void AssertAllDependenciesPresent(string locale, string localesDirPath, string resourcesDirPath, bool packLoadingDisabled) { var executingAssembly = Assembly.GetExecutingAssembly(); From ccbaebd7c28dacf41f6085509c9fb65d4bfbaec7 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 25 Mar 2015 14:51:17 +1000 Subject: [PATCH 18/18] Update AssertAllDependenciesPresent reference --- CefSharp.Core/Cef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index 3232de4693..d1bc00afc5 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -157,7 +157,7 @@ namespace CefSharp { if(performDependencyCheck) { - DependencyChecker::AssetAllDependenciesPresent(cefSettings->Locale, cefSettings->LocalesDirPath, cefSettings->ResourcesDirPath, cefSettings->PackLoadingDisabled); + DependencyChecker::AssertAllDependenciesPresent(cefSettings->Locale, cefSettings->LocalesDirPath, cefSettings->ResourcesDirPath, cefSettings->PackLoadingDisabled); } CefMainArgs main_args;