Add bookmarks support for Chromium / ChromeSxS and multiple profiles

This commit is contained in:
Yeechan Lu 2014-03-17 12:32:19 +08:00
parent 2c50adb6f2
commit 70f0d8d558

View File

@ -55,16 +55,14 @@ namespace Wox.Plugin.System
{
bookmarks.Clear();
LoadChromeBookmarks();
bookmarks = bookmarks.Distinct().ToList();
}
private void LoadChromeBookmarks()
private void ParseChromeBookmarks(String path, string source)
{
String platformPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string path = global::System.IO.Path.Combine(platformPath, @"Google\Chrome\User Data\Default\Bookmarks");
if (!File.Exists(path)) return;
if (File.Exists(path))
{
string all = File.ReadAllText(path);
Regex nameRegex = new Regex("\"name\": \"(?<name>.*?)\"");
MatchCollection nameCollection = nameRegex.Matches(all);
@ -95,11 +93,30 @@ namespace Wox.Plugin.System
{
Name = name,
Url = url,
Source = "Chrome"
Source = source
});
}
}
}
private void LoadChromeBookmarks(string path, string name)
{
if (!Directory.Exists(path)) return;
var paths = Directory.GetDirectories(path);
foreach (var profile in paths)
{
if (File.Exists(Path.Combine(profile, "Bookmarks")))
ParseChromeBookmarks(Path.Combine(profile, "Bookmarks"), name + (Path.GetFileName(profile) == "Default" ? "" : (" (" + Path.GetFileName(profile) + ")")));
}
}
private void LoadChromeBookmarks()
{
String platformPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
LoadChromeBookmarks(Path.Combine(platformPath, @"Google\Chrome\User Data"), "Google Chrome");
LoadChromeBookmarks(Path.Combine(platformPath, @"Google\Chrome SxS\User Data"), "Google Chrome Canary");
LoadChromeBookmarks(Path.Combine(platformPath, @"Chromium\User Data"), "Chromium");
}
private String DecodeUnicode(String dataStr)