diff --git a/Wox.Plugin.System/BrowserBookmarks.cs b/Wox.Plugin.System/BrowserBookmarks.cs index d57d0a5d28..756ea3daad 100644 --- a/Wox.Plugin.System/BrowserBookmarks.cs +++ b/Wox.Plugin.System/BrowserBookmarks.cs @@ -55,51 +55,68 @@ namespace Wox.Plugin.System { bookmarks.Clear(); LoadChromeBookmarks(); + bookmarks = bookmarks.Distinct().ToList(); } + private void ParseChromeBookmarks(String path, string source) + { + if (!File.Exists(path)) return; + + string all = File.ReadAllText(path); + Regex nameRegex = new Regex("\"name\": \"(?.*?)\""); + MatchCollection nameCollection = nameRegex.Matches(all); + Regex typeRegex = new Regex("\"type\": \"(?.*?)\""); + MatchCollection typeCollection = typeRegex.Matches(all); + Regex urlRegex = new Regex("\"url\": \"(?.*?)\""); + MatchCollection urlCollection = urlRegex.Matches(all); + + List names = (from Match match in nameCollection select match.Groups["name"].Value).ToList(); + List types = (from Match match in typeCollection select match.Groups["type"].Value).ToList(); + List urls = (from Match match in urlCollection select match.Groups["url"].Value).ToList(); + + int urlIndex = 0; + for (int i = 0; i < names.Count; i++) + { + string name = DecodeUnicode(names[i]); + string type = types[i]; + if (type == "url") + { + string url = urls[urlIndex]; + urlIndex++; + + if (url == null) continue; + if (url.StartsWith("javascript:", StringComparison.OrdinalIgnoreCase)) continue; + if (url.StartsWith("vbscript:", StringComparison.OrdinalIgnoreCase)) continue; + + bookmarks.Add(new Bookmark() + { + Name = name, + Url = url, + 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); - string path = global::System.IO.Path.Combine(platformPath, @"Google\Chrome\User Data\Default\Bookmarks"); - - if (File.Exists(path)) - { - string all = File.ReadAllText(path); - Regex nameRegex = new Regex("\"name\": \"(?.*?)\""); - MatchCollection nameCollection = nameRegex.Matches(all); - Regex typeRegex = new Regex("\"type\": \"(?.*?)\""); - MatchCollection typeCollection = typeRegex.Matches(all); - Regex urlRegex = new Regex("\"url\": \"(?.*?)\""); - MatchCollection urlCollection = urlRegex.Matches(all); - - List names = (from Match match in nameCollection select match.Groups["name"].Value).ToList(); - List types = (from Match match in typeCollection select match.Groups["type"].Value).ToList(); - List urls = (from Match match in urlCollection select match.Groups["url"].Value).ToList(); - - int urlIndex = 0; - for (int i = 0; i < names.Count; i++) - { - string name = DecodeUnicode(names[i]); - string type = types[i]; - if (type == "url") - { - string url = urls[urlIndex]; - urlIndex++; - - if (url == null) continue; - if (url.StartsWith("javascript:", StringComparison.OrdinalIgnoreCase)) continue; - if (url.StartsWith("vbscript:", StringComparison.OrdinalIgnoreCase)) continue; - - bookmarks.Add(new Bookmark() - { - Name = name, - Url = url, - Source = "Chrome" - }); - } - } - } + 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)