Skip to content

Commit dbd5e2c

Browse files
authored
Merge pull request #3659 from Flow-Launcher/firefox_index_out_of_range
Check index out of range for FireFox
2 parents 4c4092d + 79d35bb commit dbd5e2c

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ public override List<Bookmark> GetBookmarks()
270270
/// <summary>
271271
/// Path to places.sqlite
272272
/// </summary>
273+
/// <remarks></remarks>
273274
private static string PlacesPath
274275
{
275276
get
@@ -295,12 +296,50 @@ private static string PlacesPath
295296

296297
var indexOfDefaultProfileAttributePath = lines.IndexOf("Path=" + defaultProfileFolderName);
297298

299+
/*
300+
Current profiles.ini structure example as of Firefox version 69.0.1
301+
302+
[Install736426B0AF4A39CB]
303+
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
304+
Locked=1
305+
306+
[Profile2]
307+
Name=newblahprofile
308+
IsRelative=0
309+
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.
310+
311+
[Profile1]
312+
Name=default
313+
IsRelative=1
314+
Path=Profiles/cydum7q4.default
315+
Default=1
316+
317+
[Profile0]
318+
Name=default-release
319+
IsRelative=1
320+
Path=Profiles/7789f565.default-release
321+
322+
[General]
323+
StartWithLastProfile=1
324+
Version=2
325+
*/
298326
// Seen in the example above, the IsRelative attribute is always above the Path attribute
327+
328+
var relativePath = Path.Combine(defaultProfileFolderName, "places.sqlite");
329+
var absoluePath = Path.Combine(profileFolderPath, relativePath);
330+
331+
// If the index is out of range, it means that the default profile is in a custom location or the file is malformed
332+
// If the profile is in a custom location, we need to check
333+
if (indexOfDefaultProfileAttributePath - 1 < 0 ||
334+
indexOfDefaultProfileAttributePath - 1 >= lines.Count)
335+
{
336+
return Directory.Exists(absoluePath) ? absoluePath : relativePath;
337+
}
338+
299339
var relativeAttribute = lines[indexOfDefaultProfileAttributePath - 1];
300340

301341
return relativeAttribute == "0" // See above, the profile is located in a custom location, path is not relative, so IsRelative=0
302-
? defaultProfileFolderName + @"\places.sqlite"
303-
: Path.Combine(profileFolderPath, defaultProfileFolderName) + @"\places.sqlite";
342+
? relativePath : absoluePath;
304343
}
305344
}
306345
}

0 commit comments

Comments
 (0)