static MyDirectory BuildUpdateConfigFile(XmlNode node) { MyDirectory dir = new MyDirectory(); dir.LastUpdate = node.Attributes["lastUpdate"].Value; dir.Name = node.Attributes["name"].Value; dir.Version = node.Attributes["version"].Value; XmlNodeList nodes = node.ChildNodes; foreach (XmlNode n in node.ChildNodes) { if (n.Name == "file") { FileSimpleInfo dir1 = new FileSimpleInfo(); dir1.ModifyDateTime = n.Attributes["lastUpdate"] == null?DateTime.Parse("1900-1-1") : DateTime.Parse(n.Attributes["lastUpdate"].Value); dir1.Name = n.Attributes["name"].Value; dir1.Version = n.Attributes["version"].Value; dir.Files.Add(dir1); } else if (n.Name == "dir") { dir.Directories.Add(BuildUpdateConfigFile(n)); } } return(dir); }
private static MyDirectory BuildUpdateConfigFile(string path) { MyDirectory dirFile = new MyDirectory(); string pathName = path.Substring(path.LastIndexOf("\\") + 1); string lastUpdate = Directory.GetLastWriteTimeUtc(path).ToString(); string version = "1.0.0"; string[] files = Directory.GetFiles(path); dirFile.Name = pathName; dirFile.Version = version; dirFile.LastUpdate = Directory.GetLastWriteTimeUtc(path).ToString(); for (int i = 0; i < files.Length; i++) { try { FileSimpleInfo chileFile = new FileSimpleInfo(); FileInfo fileInfo = new FileInfo(files[i]); chileFile.Name = fileInfo.Name; chileFile.Version = FileVersionInfo.GetVersionInfo(fileInfo.FullName).FileVersion == null ? "1.0.0" : FileVersionInfo.GetVersionInfo(fileInfo.FullName).FileVersion; chileFile.ModifyDateTime = fileInfo.LastWriteTimeUtc.ToLocalTime(); dirFile.Files.Add(chileFile); } catch (Exception ex) { //System.Diagnostics.Debug.WriteLine(ex.Message); } } string[] dirs = Directory.GetDirectories(path); for (int j = 0; j < dirs.Length; j++) { dirFile.Directories.Add(BuildUpdateConfigFile(dirs[j])); } return(dirFile); }