//Proxy for SearchStartMenuSyncFast. Code literally copypasted from SearchItems and simplified. //Not thread-safe. private static void SearchRootFastSync(string query, PowerItem source, ICollection<PowerItem> destination) { if (!source.IsFolder && source.Match(query) && destination.All(d => d.FriendlyName != source.FriendlyName)) destination.Add(source); if (!source.AutoExpandIsPending) foreach (var powerItem in source.Items) SearchRootFastSync(query, powerItem, destination); }
/// <summary> /// From the 'source' given, recoursively searches the PowerItem that would Match() the 'query', including /// the 'source' itself, storing results in 'destination'. Finds folders unless they're under Start Menu. /// Cancellable. Intended to be run async. Thread/UI-thread-safe. /// </summary> /// <param name="query">Something searched results should Match() to.</param> /// <param name="source">Tree to search from, including the collection root item passed /// (but not the source.Root itself if the passed item isn't the root of the collection)</param> /// <param name="destination">Collection to store data in</param> /// <param name="stop">Cancellation token from initializer thread</param> private static void SearchItems(string query, PowerItem source, IList<PowerItem> destination, CancellationToken stop) { if(stop.IsCancellationRequested) return; if ((!source.IsFolder || source.Root != StartMenuRootItem) && source.Match(query)) {//return ((folders for not StartMenu children) or files) that Match() the query lock (destination) { if (!stop.IsCancellationRequested && //this item wasn't added before !destination.Any(d => d.FriendlyName == source.FriendlyName && d.IsFolder == source.IsFolder)) Util.Send(() => { if (!stop.IsCancellationRequested) destination.Add(source); }); } } if (!source.AutoExpandIsPending) foreach (var powerItem in source.Items) SearchItems(query, powerItem, destination, stop); }