From 356af71c7de6fa962e533f8f4dc633915b1c393a Mon Sep 17 00:00:00 2001 From: bor Date: Fri, 16 Dec 2016 11:37:03 +0330 Subject: [PATCH] changed BrowserFinder to be more tolerant (#17) --- BrowserSelect/Browser.cs | 68 +++++++++++++++++------- BrowserSelect/Form1.Designer.cs | 4 +- BrowserSelect/Properties/AssemblyInfo.cs | 4 +- README.md | 44 +++++++++------ 4 files changed, 80 insertions(+), 40 deletions(-) diff --git a/BrowserSelect/Browser.cs b/BrowserSelect/Browser.cs index 63f9302..61da157 100644 --- a/BrowserSelect/Browser.cs +++ b/BrowserSelect/Browser.cs @@ -95,26 +95,54 @@ public static List find() private static List find(RegistryKey hklm) { List browsers = new List(); - RegistryKey webClientsRootKey = hklm.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet"); - if (webClientsRootKey != null) - foreach (var subKeyName in webClientsRootKey.GetSubKeyNames()) - if (webClientsRootKey.OpenSubKey(subKeyName) != null) - if (webClientsRootKey.OpenSubKey(subKeyName).OpenSubKey("shell") != null) - if (webClientsRootKey.OpenSubKey(subKeyName).OpenSubKey("shell").OpenSubKey("open") != null) - if (webClientsRootKey.OpenSubKey(subKeyName).OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command") != null) - { - string commandLineUri = (string)webClientsRootKey.OpenSubKey(subKeyName).OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command").GetValue(null); - if (string.IsNullOrEmpty(commandLineUri)) - continue; - commandLineUri = commandLineUri.Trim("\"".ToCharArray()); - browsers.Add(new Browser() - { - name = (string)webClientsRootKey.OpenSubKey(subKeyName).GetValue(null), - exec = commandLineUri, - //icon = Icon.ExtractAssociatedIcon(commandLineUri) - icon = IconExtractor.fromFile(commandLineUri) - }); - } + // startmenu internet key + RegistryKey smi = hklm.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet"); + if (smi != null) + foreach (var browser in smi.GetSubKeyNames()) + { + try + { + var key = smi.OpenSubKey(browser); + var name = (string)key.GetValue(null); + var cmd = key.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command"); + var exec = (string)cmd.GetValue(null); + + // by this point if registry is missing keys we are alreay out of here + // because of the try catch, but there are still things that could go wrong + + //0. check if it can handle the http protocol + if ((string)key.OpenSubKey("Capabilities").OpenSubKey("URLAssociations").GetValue("http") == null) + continue; + //1. check if path is not empty + if (string.IsNullOrWhiteSpace(exec)) + continue; + + //1.1. remove possible "%1" from the end + exec = exec.Replace("\"%1\"", ""); + //1.2. remove possible quotes around address + exec = exec.Trim("\"".ToCharArray()); + //2. check if path is valid + if (!File.Exists(exec)) + continue; + //3. check if name is valid + if (string.IsNullOrWhiteSpace(name)) + name = Path.GetFileNameWithoutExtension(exec); + + browsers.Add(new Browser() + { + name = name, + exec = exec, + icon = IconExtractor.fromFile(exec) + }); + } + catch (NullReferenceException) + { + } // incomplete registry record for browser, ignore it + catch (Exception ex) + { + // todo: log errors + } + } return browsers; } } diff --git a/BrowserSelect/Form1.Designer.cs b/BrowserSelect/Form1.Designer.cs index 1619055..9b43ce1 100644 --- a/BrowserSelect/Form1.Designer.cs +++ b/BrowserSelect/Form1.Designer.cs @@ -36,7 +36,7 @@ private void InitializeComponent() { this.btn_help.Cursor = System.Windows.Forms.Cursors.Hand; this.btn_help.FlatAppearance.BorderSize = 0; this.btn_help.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btn_help.Location = new System.Drawing.Point(469, 155); + this.btn_help.Location = new System.Drawing.Point(97, 155); this.btn_help.Name = "btn_help"; this.btn_help.Size = new System.Drawing.Size(25, 25); this.btn_help.TabIndex = 0; @@ -48,7 +48,7 @@ private void InitializeComponent() { this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.ClientSize = new System.Drawing.Size(496, 181); + this.ClientSize = new System.Drawing.Size(124, 181); this.Controls.Add(this.btn_help); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.Name = "Form1"; diff --git a/BrowserSelect/Properties/AssemblyInfo.cs b/BrowserSelect/Properties/AssemblyInfo.cs index 584be48..49adcaf 100644 --- a/BrowserSelect/Properties/AssemblyInfo.cs +++ b/BrowserSelect/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.4.0")] -[assembly: AssemblyFileVersion("1.3.4.0")] +[assembly: AssemblyVersion("1.3.5.0")] +[assembly: AssemblyFileVersion("1.3.5.0")] diff --git a/README.md b/README.md index afb9e26..4ce7432 100644 --- a/README.md +++ b/README.md @@ -18,20 +18,28 @@ it has been tested on windows 7, windows 8.1 and windows 10. requires **.net fra # Download -you can download browser select here : [Browser select v1.3.4 (205KB)](https://github.com/zumoshi/BrowserSelect/releases/download/1.3.4/BrowserSelect.exe) +you can download browser select here : [Browser select v1.3.5 (205KB)](https://github.com/zumoshi/BrowserSelect/releases/download/1.3.5/BrowserSelect.exe) [![100% safe Award from softpedia](http://s1.softpedia-static.com/_img/sp100free.png?1)](http://www.softpedia.com/get/Internet/Browsers/Browser-Select.shtml#status) # Related links -http://alternativeto.net/software/browser-select/ +[AlternativeTo](http://alternativeto.net/software/browser-select/) -http://www.snapfiles.com/get/browserselect.html +Reviews: [TrishTech](http://www.trishtech.com/2016/07/use-different-browsers-for-different-links-with-browserselect/) +[DonationCoder](http://www.donationcoder.com/forum/index.php?topic=42860.msg401447) -http://www.softpedia.com/get/Internet/Browsers/Browser-Select.shtml +Download Mirrors: +[GitHub](https://github.com/zumoshi/BrowserSelect/releases/latest) +[SoftPedia](http://www.softpedia.com/get/Internet/Browsers/Browser-Select.shtml) +[SnapFiles](http://www.snapfiles.com/get/browserselect.html) +[FindmySoft](http://browserselect.findmysoft.com/) +[browserss](http://browserss.ru/m.browser-select.php) +[ComputerBild](http://www.computerbild.de/download/BrowserSelect-15967517.html) + +Note: Mirror's may have outdated versions of browserSelect. you can always download the latest version [here](https://github.com/zumoshi/BrowserSelect/releases). -http://www.donationcoder.com/forum/index.php?topic=42860.msg401447 # ToDo @@ -61,25 +69,29 @@ just a list of some ideas that can be integrated into BrowserSelect. - [ ] Localization - [ ] handling of other link types (e.g. `mail:` in case you have both outlook and thunderbird installed [or maybe as a sister app]) - [x] update checker (not as a popup or messagebox, a tiny icon somewhere on the main form that appears when you don't have the last version) +- [ ] add file associations (e.g. .url files, or .html files) + +# Changelog -# Changelog +v1.3.5 [16/12/16] +- fixed crash on startup caused by incompatible/incomplete registry keys (issues #17,#20,#21) -v1.3.4 +v1.3.4 [02/09/16] - fixed Always button adding rule with wrong pattern for second level domains (e.g. *.com.au for news.com.au) - Shift Clicking on browsers now opens the url in incognito/private browsing - added an update checker (adds a yellow "New" icon to main window to indicate a new version is available)[disabled by default] -v1.3.3 +v1.3.3 [03/08/16] - fixed a crash on malformed (without protocol) url's - added donate button in about page -v1.3.2 +v1.3.2 [28/07/16] - bugfix to bring IE to foreground if it is already open -v1.3.1 +v1.3.1 [14/07/16] - bugfix for Auto rule creation of domains with subdomains -v1.3 +v1.3 [11/07/16] - Added an "Always" button under browser icons that adds a rule for *.domain.tld - Added a help button in the main form - made about form closable by Esc key @@ -90,17 +102,17 @@ v1.3 - polished the rule adding interface - some code Formating/Indenting/Restructuring -v1.2.1 +v1.2.1 [14/06/16] - bugfix for InternetExplorer to open links in a new tab instead of a new window -v1.2 +v1.2 [08/06/16] - you can now add url patterns to select the browser based on url automatically. -v1.1 +v1.1 [18/05/16] - added option to select browsers that are displayed on the list (and remove/hide some) -v1.0.2 +v1.0.2 [15/01/16] - added option to set browser select as default browser in settings -v1.0.1 +v1.0.1 [27/10/15] - added edge browser for windows 10 (it wouldn't show up due edge being a Universal App) \ No newline at end of file