public static CategoryList Deserialize(string ConfigFile) { XmlDocument doc = new XmlDocument(); doc.Load(ConfigFile); XmlElement root = doc.ChildNodes[0] as XmlElement; CategoryList catList = new CategoryList(); foreach (XmlElement catElement in root.ChildNodes) { Category cat = new Category(); cat.Name = catElement.Attributes["Name"].Value; catList.Add(cat); foreach (XmlElement appElement in catElement.ChildNodes) { ApplicationInfo app = new ApplicationInfo(); app.Name = appElement.ChildNodes[0].InnerText; app.Path = appElement.ChildNodes[1].InnerText; if (!System.IO.File.Exists(app.Path)) { System.Diagnostics.Debug.WriteLine(app.Path + " does not exist"); continue; } app.Icon = app.GetAssociatedIcon(); cat.Add(app); } } return(catList); }
private List <ApplicationInfo> generateAppListRecursing(DirectoryInfo directory) { //_logger.Debug("Scanning directory {0}", directory.FullName); List <ApplicationInfo> rval = new List <ApplicationInfo>(); foreach (DirectoryInfo subfolder in directory.GetDirectories()) { rval.AddRange(generateAppListRecursing(subfolder)); } foreach (FileInfo file in directory.GetFiles()) { //_logger.Debug("Interrogating file {0}", file.FullName); ApplicationInfo ai = new ApplicationInfo(); String ext = Path.GetExtension(file.FullName); if (executableExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase)) { try { ai.Name = Path.GetFileNameWithoutExtension(file.FullName); ai.Path = file.FullName; string target = string.Empty; if (file.Extension.Equals(".lnk", StringComparison.OrdinalIgnoreCase)) { //_logger.Debug("Attempting to interrogate shortcut to application: {0}", file.FullName); Interop.Shell.Link link = new Interop.Shell.Link(file.FullName); target = link.Target; } else { target = file.FullName; } if (!executableExtensions.Contains(Path.GetExtension(target), StringComparer.OrdinalIgnoreCase)) { System.Diagnostics.Debug.WriteLine(file.Name + ": " + target); continue; } //_logger.Debug("Attempting to get associated icon for {0}", file.FullName); ai.Icon = ai.GetAssociatedIcon(); rval.Add(ai); } catch (Exception ex) { //Output the reason to the debugger //_logger.Debug("Error creating ApplicationInfo object in appgrabber. Details: {0}\n{1}", ex.Message, ex.StackTrace); } } } return(rval); }