From 7f6d416645352b1a2ddfe1a52616bd44a057906b Mon Sep 17 00:00:00 2001 From: perqin Date: Wed, 11 Nov 2020 23:24:49 +0800 Subject: [PATCH] feat: support Firfox profiles --- BrowserSelect/Browser.cs | 39 +++++++++++++++++++++++++++++++++++ BrowserSelect/packages.config | 1 + 2 files changed, 40 insertions(+) diff --git a/BrowserSelect/Browser.cs b/BrowserSelect/Browser.cs index f6dc422..94b70f4 100644 --- a/BrowserSelect/Browser.cs +++ b/BrowserSelect/Browser.cs @@ -9,6 +9,8 @@ using Newtonsoft.Json.Linq; using System.Text.RegularExpressions; using Newtonsoft.Json; +using IniParser; +using IniParser.Model; namespace BrowserSelect { @@ -134,6 +136,9 @@ public static List find(bool update = false) //Check for Chrome Profiles AddChromeProfiles(browsers, "Google Chrome", @"Google\Chrome\User Data", "Google Profile.ico"); + //Check for Firefox profiles + AddFirefoxProfiles(browsers, "Mozilla Firefox"); + System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(browsers)); Properties.Settings.Default.BrowserList = JsonConvert.SerializeObject(browsers); Properties.Settings.Default.Save(); @@ -185,6 +190,40 @@ private static List FindChromeProfiles(string ChromeUserDataDir, string return Profiles; } + private static void AddFirefoxProfiles(List browsers, string BrowserName) + { + Browser BrowserFirefox = browsers.FirstOrDefault(x => x.name == BrowserName); + if (BrowserFirefox == null) + return; + string Exec = BrowserFirefox.exec; + var FirefoxProfilesIni = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Mozilla\Firefox\profiles.ini"); + var parser = new FileIniDataParser(); + IniData data = parser.ReadFile(FirefoxProfilesIni); + string defaultProfile = null; + foreach (var section in data.Sections) + { + if (section.SectionName.StartsWith("Install")) + { + defaultProfile = section.Keys["Default"]; + } + } + foreach (var section in data.Sections) + { + if (section.SectionName.StartsWith("Profile")) + { + if (section.Keys["Path"] == defaultProfile) + continue; + browsers.Add(new Browser() + { + name = BrowserName + " (" + section.Keys["Name"] + ")", + exec = Exec, + icon = icon2String(IconExtractor.fromFile(Exec)), + additionalArgs = String.Format("-p \"{0}\"", section.Keys["Name"]) + }); + } + } + } + private static List find(RegistryKey hklm) { List browsers = new List(); diff --git a/BrowserSelect/packages.config b/BrowserSelect/packages.config index 1df47c7..5b3dcea 100644 --- a/BrowserSelect/packages.config +++ b/BrowserSelect/packages.config @@ -1,5 +1,6 @@  + \ No newline at end of file