private void CollectAllSubNodes(IResource root, IntHashSet nodes) { if (root != _root) { nodes.Add(root.Id); } foreach (IResource child in BookmarkService.SubNodes(null, root)) { CollectAllSubNodes(child, nodes); } }
private void EnumerateFavorites(string folder, IResource parent) { FileInfo[] files = IOTools.GetFiles(folder); if (files != null) { IResourceList weblinks = BookmarkService.SubNodes("Weblink", parent); IntArrayList processedWeblinks = new IntArrayList(files.Length); foreach (FileInfo fileInfo in files) { IResource weblink = null; try { if (fileInfo.Extension.ToLower() == ".url") { weblink = ProcessFavoriteFile(fileInfo, parent); } else if (fileInfo.Extension.ToLower() == ".lnk") { weblink = ProcessShortcut(fileInfo, parent); } } catch (Exception e) { FavoritesTools.TraceIfAllowed(e.Message); continue; } if (weblink != null) { processedWeblinks.Add(weblink.Id); } } _bookmarkservice.DeleteBookmarks(weblinks.Minus( Core.ResourceStore.ListFromIds(processedWeblinks, false))); } DirectoryInfo[] dirs = IOTools.GetDirectories(folder); if (dirs != null) { IResourceList folders = BookmarkService.SubNodes("Folder", parent); IntArrayList processedFolders = new IntArrayList(dirs.Length); foreach (DirectoryInfo dirInfo in dirs) { IResource subfolder = _bookmarkservice.FindOrCreateFolder(parent, dirInfo.Name); EnumerateFavorites(IOTools.GetFullName(dirInfo), subfolder); processedFolders.Add(subfolder.Id); } _bookmarkservice.DeleteFolders(folders.Minus( Core.ResourceStore.ListFromIds(processedFolders, false))); } }
bool IResourceNodeFilter.AcceptNode(IResource res, int level) { if (res.HasProp(FavoritesPlugin._propInvisible)) { return(false); } IBookmarkService service = (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService)); if (service != null) { IBookmarkProfile profile = service.GetOwnerProfile(res); if (profile is FakeRestrictProfile) { return(BookmarkService.SubNodes("Folder", res).Minus( Core.ResourceStore.FindResourcesWithProp(null, FavoritesPlugin._propInvisible)).Count > 0); } } return(true); }
private void CollectBookmarks(IResource parentFolder, MozillaBookmark[] bookmarks, ref int index, int level) { Guard.NullArgument(parentFolder, "parentFolder"); if (index >= bookmarks.Length) { return; } HashMap weblinks = new HashMap(); // urls 2 resources HashMap folders = new HashMap(); // folder names 2 resources IResourceList childs = BookmarkService.SubNodes(null, parentFolder); // at first, collect all child folders and bookmarks foreach (IResource child in childs.ValidResources) { string id = child.GetPropText(FavoritesPlugin._propBookmarkId); if (id.Length > 0) { if (child.Type == "Folder") { folders[id] = child; } else if (child.Type == "Weblink") { weblinks[id] = child; } else { child.DeleteLink(FavoritesPlugin._propParent, parentFolder); } } } // look through folders and bookmarks on current level and. recursively, on sub-levels while (index < bookmarks.Length) { MozillaBookmark bookmark = bookmarks[index]; if (bookmark.Level < level) { break; } level = bookmark.Level; ++index; string id = bookmark.Id; if (bookmark.IsFolder) { IResource folder = (IResource)folders[id]; if (folder == null) { folder = _bookmarkservice.FindOrCreateFolder(parentFolder, bookmark.Folder); } else { folders.Remove(id); _bookmarkservice.SetName(folder, bookmark.Folder); _bookmarkservice.SetParent(folder, parentFolder); } folder.SetProp(FavoritesPlugin._propBookmarkId, id); CollectBookmarks(folder, bookmarks, ref index, level + 1); } else { string url = bookmark.Url; IResource weblink = (IResource)weblinks[id]; if (weblink == null) { weblink = _bookmarkservice.FindOrCreateBookmark(parentFolder, bookmark.Name, url); } else { weblinks.Remove(id); _bookmarkservice.SetName(weblink, bookmark.Name); _bookmarkservice.SetUrl(weblink, url); _bookmarkservice.SetParent(weblink, parentFolder); } if (weblink != null && bookmark.Description != null && bookmark.Description.Length > 0) { weblink.SetProp("Annotation", bookmark.Description); } weblink.SetProp(FavoritesPlugin._propBookmarkId, id); } } // look through obsolete folders and bookmarks, delete them foreach (HashMap.Entry E in folders) { _bookmarkservice.DeleteFolder((IResource)E.Value); } foreach (HashMap.Entry E in weblinks) { _bookmarkservice.DeleteBookmark((IResource)E.Value); } }