mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
get firefox default profile directory from profiles.ini
This commit is contained in:
@@ -50,17 +50,28 @@ namespace Wox.Plugin.BrowserBookmark
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var profilesPath = Environment.ExpandEnvironmentVariables(@"%appdata%\Mozilla\Firefox\Profiles\");
|
var profileFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Mozilla\Firefox");
|
||||||
|
var profileIni = Path.Combine(profileFolderPath, @"profiles.ini");
|
||||||
|
|
||||||
// return null if the Profiles folder does not exist
|
if (!File.Exists(profileIni))
|
||||||
if (!Directory.Exists(profilesPath)) return null;
|
return string.Empty;
|
||||||
|
|
||||||
var folders = new DirectoryInfo(profilesPath).GetDirectories().Select(x => x.FullName).ToList();
|
// get firefox default profile directory from profiles.ini
|
||||||
|
string ini;
|
||||||
|
using (var sReader = new StreamReader(profileIni)) {
|
||||||
|
ini = sReader.ReadToEnd();
|
||||||
|
}
|
||||||
|
var lines = ini.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList();
|
||||||
|
|
||||||
// Look for the default profile folder
|
var index = lines.IndexOf("Default=1");
|
||||||
return string.Format(@"{0}\places.sqlite",
|
if (index > 3) {
|
||||||
folders.FirstOrDefault(d => File.Exists(d + @"\places.sqlite") && d.EndsWith(".default"))
|
var relative = lines[index - 2].Split('=')[1];
|
||||||
?? folders.First(d => File.Exists(d + @"\places.sqlite")));
|
var profiePath = lines[index - 1].Split('=')[1];
|
||||||
|
return relative == "0"
|
||||||
|
? profiePath + @"\places.sqlite"
|
||||||
|
: Path.Combine(profileFolderPath, profiePath) + @"\places.sqlite";
|
||||||
|
}
|
||||||
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user