From 1ed7d342005d2691e121fbdf2e37d341b61b0c18 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 3 Oct 2019 08:06:56 +1000 Subject: [PATCH] Update how plugin locates profile path --- .../FirefoxBookmarks.cs | 55 +++++++++++++++---- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/Plugins/Wox.Plugin.BrowserBookmark/FirefoxBookmarks.cs b/Plugins/Wox.Plugin.BrowserBookmark/FirefoxBookmarks.cs index fec331a76e..67c8b1f78c 100644 --- a/Plugins/Wox.Plugin.BrowserBookmark/FirefoxBookmarks.cs +++ b/Plugins/Wox.Plugin.BrowserBookmark/FirefoxBookmarks.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Data.SQLite; using System.IO; @@ -61,17 +61,52 @@ namespace Wox.Plugin.BrowserBookmark using (var sReader = new StreamReader(profileIni)) { ini = sReader.ReadToEnd(); } + + /* + Current profiles.ini structure example as of Firefox version 69.0.1 + + [Install736426B0AF4A39CB] + Default=Profiles/7789f565.default-release <== this is the default profile this plugin will get the bookmarks from. When opened Firefox will load the default profile + Locked=1 + + [Profile2] + Name=newblahprofile + IsRelative=0 + Path=C:\t6h2yuq8.newblahprofile <== Note this is a custom location path for the profile user can set, we need to cater for this in code. + + [Profile1] + Name=default + IsRelative=1 + Path=Profiles/cydum7q4.default + Default=1 + + [Profile0] + Name=default-release + IsRelative=1 + Path=Profiles/7789f565.default-release + + [General] + StartWithLastProfile=1 + Version=2 + */ + var lines = ini.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList(); - var index = lines.IndexOf("Default=1"); - if (index > 3) { - var relative = lines[index - 2].Split('=')[1]; - var profiePath = lines[index - 1].Split('=')[1]; - return relative == "0" - ? profiePath + @"\places.sqlite" - : Path.Combine(profileFolderPath, profiePath) + @"\places.sqlite"; - } - return string.Empty; + var defaultProfileFolderNameRaw = lines.Where(x => x.Contains("Default=") && x != "Default=1").FirstOrDefault() ?? string.Empty; + + if (string.IsNullOrEmpty(defaultProfileFolderNameRaw)) + return string.Empty; + + var defaultProfileFolderName = defaultProfileFolderNameRaw.Split('=').Last(); + + var indexOfDefaultProfileAtttributePath = lines.IndexOf("Path="+ defaultProfileFolderName); + + // Seen in the example above, the IsRelative attribute is always above the Path attribute + var relativeAttribute = lines[indexOfDefaultProfileAtttributePath - 1]; + + return relativeAttribute == "0" // See above, the profile is located in a custom location, path is not relative, so IsRelative=0 + ? defaultProfileFolderName + @"\places.sqlite" + : Path.Combine(profileFolderPath, defaultProfileFolderName) + @"\places.sqlite"; } } }