void UpdateDesktopItemsList () { if (RegisteredItems == null) RegisteredItems = new List<DesktopItem> (); List<DesktopItem> newItems = new List<DesktopItem> (); IEnumerable<DesktopItem> knownItems = DesktopItems; // Get desktop items for new "valid" desktop files newItems = DesktopFileDirectories .SelectMany (dir => dir.SubDirs ()) .Union (DesktopFileDirectories) .SelectMany (dir => dir.GetFiles (".desktop")) .Where (file => !knownItems.Any (existing => existing.File.Path == file.Path)) .Select (file => new DesktopItem (file)) .ToList (); RegisteredItems.AddRange (newItems); if (newItems.Count () > 0) { Log<DesktopItemService>.Debug ("{0} new application(s) found.", newItems.Count ()); foreach (DesktopItem item in newItems) Log<DesktopItemService>.Debug ("Adding '{0}'.", item.Path); } // Check file existence and remove unlinked items List<DesktopItem> removeItems = RegisteredItems.Where (item => !item.File.Exists).ToList (); if (removeItems.Count > 0) { removeItems.ForEach (item => { RegisteredItems.Remove (item); item.Dispose (); }); Log<DesktopItemService>.Debug ("{0} application(s) removed.", removeItems.Count); } }