mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-02-16 10:58:31 -05:00
Initial commit
This commit is contained in:
65
BrowserCommon.cs
Normal file
65
BrowserCommon.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Common.Debug;
|
||||
using Common.Internet;
|
||||
using FeedCenter.Properties;
|
||||
|
||||
namespace FeedCenter
|
||||
{
|
||||
public static class BrowserCommon
|
||||
{
|
||||
public static Browser FindBrowser(string browserKey)
|
||||
{
|
||||
Browser browser = null;
|
||||
|
||||
// Get the list of installed browsers
|
||||
var browsers = Browser.DetectInstalledBrowsers();
|
||||
|
||||
// Make sure the desired browser exists
|
||||
if (browsers.ContainsKey(browserKey))
|
||||
{
|
||||
// Get the browser
|
||||
browser = browsers[browserKey];
|
||||
}
|
||||
|
||||
return browser;
|
||||
}
|
||||
|
||||
public static bool OpenLink(string url)
|
||||
{
|
||||
// Get the browser
|
||||
Browser browser = FindBrowser(Settings.Default.Browser);
|
||||
|
||||
// Start the browser
|
||||
return OpenLink(browser, url);
|
||||
}
|
||||
|
||||
public static bool OpenLink(Browser browser, string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Don't bother with empty links
|
||||
if (String.IsNullOrEmpty(url))
|
||||
return true;
|
||||
|
||||
// Add quotes around the URL for safety
|
||||
url = string.Format("\"{0}\"", url);
|
||||
|
||||
// Start the browser
|
||||
if (browser == null)
|
||||
Process.Start(url);
|
||||
else
|
||||
Process.Start(browser.Command, url);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// Just log the exception
|
||||
Tracer.WriteException(exception);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user