Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0eda968
Add rough draft of DependencyChecker - loops through list of all Cef/…
amaitland Mar 24, 2015
8a7b9e2
Untabify
amaitland Mar 24, 2015
591b477
Move localePackFile param with default value to first overload of Che…
amaitland Mar 25, 2015
2b89238
Allow for full locales path
amaitland Mar 25, 2015
a17b145
Expand Locale support to check `CefSettings` for user specified values
amaitland Mar 25, 2015
ce32740
Fix typo in CefExample
amaitland Mar 25, 2015
a188b86
Refactor code so now AssetAllDependenciesPresent throws an exception …
amaitland Mar 25, 2015
36ea815
First attempt at splitting out into required/optional dependencies
amaitland Mar 25, 2015
a9762bb
Add optional bool for checking dependencies
amaitland Mar 25, 2015
fea3d8f
Allow setting cefSettings->resources_dir_path
amaitland Mar 25, 2015
be41287
Refactor to pass params directly in from CefSettings - make life easi…
amaitland Mar 25, 2015
76ea449
Add packLoadingDisabled check
amaitland Mar 25, 2015
b12f131
Re-add LocalesPackFile default param value (moved to end of function)
amaitland Mar 25, 2015
475067b
Reorder method params (move packLoadingDisabled to second param)
amaitland Mar 25, 2015
3a47bbb
Added IsWindowsXp special case (It's not the best code in the world, …
amaitland Mar 25, 2015
4ad11e7
Move dependency check call into Cef.Initialize() - currently not enab…
amaitland Mar 25, 2015
ea2ad10
Assert not Asset - fix typo
amaitland Mar 25, 2015
ccbaebd
Update AssertAllDependenciesPresent reference
amaitland Mar 25, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CefSharp.Core/Cef.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,27 @@ namespace CefSharp
/// <return>true if successful; otherwise, false.</return>
static bool Initialize(CefSettings^ cefSettings)
{
return Initialize(cefSettings, true);
return Initialize(cefSettings, true, false);
}

/// <summary>Initializes CefSharp with user-provided settings.</summary>
/// <param name="cefSettings">CefSharp configuration settings.</param>
/// <param name="shutdownOnProcessExit">When the Current AppDomain (relative to the thread called on)
/// Exits(ProcessExit event) then Shudown will be called.</param>
/// <param name="performDependencyCheck">Check that all relevant dependencies avaliable, throws exception if any are missing</param>
/// <return>true if successful; otherwise, false.</return>
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::AssertAllDependenciesPresent(cefSettings->Locale, cefSettings->LocalesDirPath, cefSettings->ResourcesDirPath, cefSettings->PackLoadingDisabled);
}

CefMainArgs main_args;
CefRefPtr<CefSharpApp> app(new CefSharpApp(cefSettings));

Expand Down
6 changes: 6 additions & 0 deletions CefSharp.Core/CefSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
9 changes: 6 additions & 3 deletions CefSharp.Example/CefExample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Diagnostics;
using System.Linq;

namespace CefSharp.Example
{
Expand All @@ -22,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;
Expand Down Expand Up @@ -52,7 +51,11 @@ public static void Init()
SchemeHandlerFactory = new CefSharpSchemeHandlerFactory()
});

if (!Cef.Initialize(settings))
//Cef will check if all dependencies are present
//For special case when Checking Windows Xp Dependencies
//DependencyChecker.IsWindowsXp = true;

if (!Cef.Initialize(settings, shutdownOnProcessExit: true, performDependencyCheck: true))
{
throw new Exception("Unable to Initialize Cef");
}
Expand Down
1 change: 1 addition & 0 deletions CefSharp/CefSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<Compile Include="CefDirtyRect.cs" />
<Compile Include="CefFileDialogMode.cs" />
<Compile Include="DefaultResourceHandlerFactory.cs" />
<Compile Include="DependencyChecker.cs" />
<Compile Include="IJavascriptCallback.cs" />
<Compile Include="Internals\JavascriptCallbackProxy.cs" />
<Compile Include="Internals\JavascriptCallback.cs" />
Expand Down
200 changes: 200 additions & 0 deletions CefSharp/DependencyChecker.cs
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)
Copy link
Contributor

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?

Copy link
Member Author

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. checkOptional would be replaced with an enum if we went down that path.

{
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);

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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());
}
}
}
}