コード例 #1
0
        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);
        }
コード例 #2
0
        /// <summary>
        /// 构造更新配置信息
        /// </summary>
        /// <param name="path"></param>
        private static XmlElement BuildUpdateConfigFile(MyDirectory path)
        {
            string     pathName   = path.Name;
            string     lastUpdate = path.LastUpdate;
            string     version    = path.Version;
            XmlElement element    = null;

            element = _XmlSystemInfo.CreateElement("dir");
            element.SetAttribute("name", pathName);
            element.SetAttribute("lastUpdate", lastUpdate);
            element.SetAttribute("version", version);
            for (int i = 0; i < path.Files.Count; i++)
            {
                try
                {
                    XmlElement child = _XmlSystemInfo.CreateElement("file");
                    child.SetAttribute("lastUpdate", path.Files[i].ModifyDateTime.ToString());
                    child.SetAttribute("version", path.Files[i].Version);
                    child.SetAttribute("name", path.Files[i].Name);
                    element.AppendChild(child);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
            //  string[] dirs = Directory.GetDirectories(path);
            for (int j = 0; j < path.Directories.Count; j++)
            {
                element.AppendChild(BuildUpdateConfigFile(path.Directories[j]));
            }
            return(element);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        /// <summary>
        /// 构造要上传的文件路径
        /// </summary>
        /// <returns></returns>
        private void BuildUpdateFile(string path, MyDirectory directory)
        {
            foreach (FileSimpleInfo file in directory.Files)
            {
                string filepath = "";
                if (string.IsNullOrEmpty(path))
                {
                    filepath = string.Format(@"\{0} ", file.Name);
                }
                else
                {
                    filepath = string.Format(@"{0}\{1} ", path, file.Name);
                }
                _fileFullPaths.Add(filepath.Trim());
            }
            foreach (MyDirectory dir in directory.Directories)
            {
                if (!string.IsNullOrEmpty(path))
                {
                    path = string.Format(@"{0}\{1}", path, dir.Name);
                }
                else
                {
                    path = string.Format(@"\{0}", dir.Name);
                }

                BuildUpdateFile(path, dir);
                if (!string.IsNullOrEmpty(path))
                {
                    path = path.Remove(path.LastIndexOf("\\"));
                }
            }
        }
コード例 #5
0
        private void BuildSystemFileSilmpleList(string path, MyDirectory directory)
        {
            foreach (FileSimpleInfo file in directory.Files)
            {
                string filepath = "";
                if (string.IsNullOrEmpty(path))
                {
                    if (file.Name.IndexOf("\\") == -1)
                    {
                        filepath = string.Format(@"\{0} ", file.Name);
                    }
                    else
                    {
                        filepath = file.Name;
                    }
                }
                else
                {
                    filepath = string.Format(@"{0}\{1} ", path, file.Name);
                }
                file.Name = filepath.Trim();
                fileSimples.Add(file);
            }
            foreach (MyDirectory dir in directory.Directories)
            {
                if (!string.IsNullOrEmpty(path))
                {
                    path = string.Format(@"{0}\{1}", path, dir.Name);
                }
                else
                {
                    path = string.Format(@"\{0}", dir.Name);
                }

                BuildSystemFileSilmpleList(path, dir);
                if (!string.IsNullOrEmpty(path))
                {
                    path = path.Remove(path.LastIndexOf("\\"));
                }
            }
        }
コード例 #6
0
 /// <summary>
 /// 构造系统更新类的Xml
 /// </summary>
 /// <param name="path">系统所在文件夹</param>
 public FileUpdateInfo(string path)
 {
     this._Files = BuildUpdateConfigFile(path);
 }