Skip to content

Commit

Permalink
Add public static method to find Chromium
Browse files Browse the repository at this point in the history
  • Loading branch information
Kees committed May 22, 2024
1 parent 23d0a53 commit fb95078
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
16 changes: 16 additions & 0 deletions ChromiumHtmlToPdfLib/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,22 @@ void OnChromiumProcessOnErrorDataReceived(object _, DataReceivedEventArgs args)
}
#endregion

/// <summary>
/// Returns the location of the Chromium based browser or <c>null</c> when not found
/// </summary>
/// <param name="browser"><see cref="Enums.Browser"/></param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static string? GetChromiumLocation(Enums.Browser browser)
{
return browser switch
{
Enums.Browser.Chrome => ChromeFinder.Find(),
Enums.Browser.Edge => EdgeFinder.Find(),
_ => throw new ArgumentOutOfRangeException(nameof(browser), browser, null)
};
}

#region ReadDevToolsActiveFileAsync
/// <summary>
/// Tries to read the content of the DevToolsActiveFile
Expand Down
13 changes: 3 additions & 10 deletions ChromiumHtmlToPdfLib/Helpers/ChromeFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Win32;

Expand Down Expand Up @@ -144,15 +145,7 @@ private static string GetAppPath()

GetApplicationDirectories(directories);

foreach (var exeName in exeNames)
foreach (var directory in directories)
{
var path = Path.Combine(directory, exeName);
if (File.Exists(path))
return path;
}

return null;
return (from exeName in exeNames from directory in directories select Path.Combine(directory, exeName)).FirstOrDefault(File.Exists);
}
#endregion
}
}
13 changes: 3 additions & 10 deletions ChromiumHtmlToPdfLib/Helpers/EdgeFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Win32;

Expand Down Expand Up @@ -136,15 +137,7 @@ private static string GetAppPath()

GetApplicationDirectories(directories);

foreach (var exeName in exeNames)
foreach (var directory in directories)
{
var path = Path.Combine(directory, exeName);
if (File.Exists(path))
return path;
}

return null;
return (from exeName in exeNames from directory in directories select Path.Combine(directory, exeName)).FirstOrDefault(File.Exists);
}
#endregion
}
}

0 comments on commit fb95078

Please sign in to comment.