From 58c7fb49ddbcf124192238775f11d364c3f732d2 Mon Sep 17 00:00:00 2001 From: lennylxx Date: Thu, 23 Apr 2015 22:49:07 +0800 Subject: [PATCH 1/2] Fix the bug that opening url using default browser. --- shadowsocks-csharp/View/MenuViewController.cs | 38 ++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index ff5a018c..7366d627 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.Drawing; using System.Text; using System.Windows.Forms; +using Microsoft.Win32; using ZXing; using ZXing.Common; using ZXing.QrCode; @@ -325,9 +326,44 @@ namespace Shadowsocks.View } } + private static string GetDefaultBrowserPath() + { + string userChoice = @"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice"; + string commandPath = @"$BROWSER$\shell\open\command"; + string browserPath = ""; + try + { + // Read default browser path from userChoice Key + RegistryKey userChoiceKey = Registry.CurrentUser.OpenSubKey(userChoice, false); + string progId = (userChoiceKey.GetValue("ProgId").ToString()); + userChoiceKey.Close(); + + // Look up the path of the executable + commandPath = commandPath.Replace("$BROWSER$", progId); + RegistryKey pathKey = Registry.ClassesRoot.OpenSubKey(commandPath, false); + + browserPath = pathKey.GetValue(null).ToString().ToLower().Replace("\"", ""); + pathKey.Close(); + + // Trim parameters. + string exeSuffix = "exe"; + if (!browserPath.EndsWith(exeSuffix)) + { + browserPath = browserPath.Substring(0, browserPath.LastIndexOf(exeSuffix, StringComparison.Ordinal) + exeSuffix.Length); + } + } + catch (Exception e) + { + Logging.LogUsefulException(e); + } + + return browserPath; + } + private void AboutItem_Click(object sender, EventArgs e) { - Process.Start("https://github.com/shadowsocks/shadowsocks-csharp"); + string aboutLink = "https://github.com/shadowsocks/shadowsocks-csharp"; + Process.Start(GetDefaultBrowserPath(), aboutLink); } private void notifyIcon1_DoubleClick(object sender, MouseEventArgs e) From 2c480b73bb2cec735f6432a23a0d6d43b3856352 Mon Sep 17 00:00:00 2001 From: lennylxx Date: Fri, 24 Apr 2015 14:32:06 +0800 Subject: [PATCH 2/2] Open update checker link with default browser. --- shadowsocks-csharp/View/MenuViewController.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 7366d627..687cc073 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -237,7 +237,7 @@ namespace Shadowsocks.View void notifyIcon1_BalloonTipClicked(object sender, EventArgs e) { - System.Diagnostics.Process.Start(updateChecker.LatestVersionURL); + Process.Start(GetDefaultBrowserPath(), updateChecker.LatestVersionURL); _notifyIcon.BalloonTipClicked -= notifyIcon1_BalloonTipClicked; } @@ -330,7 +330,7 @@ namespace Shadowsocks.View { string userChoice = @"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice"; string commandPath = @"$BROWSER$\shell\open\command"; - string browserPath = ""; + string browserPath = null; try { // Read default browser path from userChoice Key @@ -357,6 +357,10 @@ namespace Shadowsocks.View Logging.LogUsefulException(e); } + if (browserPath == null) + { + browserPath = "iexplore.exe"; + } return browserPath; }