Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support Firfox profiles #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions BrowserSelect/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using IniParser;
using IniParser.Model;

namespace BrowserSelect
{
Expand Down Expand Up @@ -134,6 +136,9 @@ public static List<Browser> 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();
Expand Down Expand Up @@ -185,6 +190,40 @@ private static List<string> FindChromeProfiles(string ChromeUserDataDir, string
return Profiles;
}

private static void AddFirefoxProfiles(List<Browser> 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<Browser> find(RegistryKey hklm)
{
List<Browser> browsers = new List<Browser>();
Expand Down
1 change: 1 addition & 0 deletions BrowserSelect/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ini-parser" version="2.5.2" targetFramework="net40" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also include changes to the .csproj file, specifically this addition:

<Reference Include="INIFileParser, Version=2.5.2.0, Culture=neutral, PublicKeyToken=79af7b307b65cf3c, processorArchitecture=MSIL">
      <HintPath>..\packages\ini-parser.2.5.2\lib\net20\INIFileParser.dll</HintPath>
    </Reference>

Otherwise it won't compile
image

<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net40" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net40" />
</packages>