123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- using System.Xml.Serialization;
- namespace ProjectBase.Data.Update
- {
- /// <summary>
- /// 文件清单对象
- /// </summary>
- [XmlRoot("manifest")]
- public class Manifest
- {
- [XmlElement("version")]
- public string Version { get; set; }
- [XmlElement("description")]
- public string Description { get; set; }
- [XmlElement("ftpname")]
- public string FtpName { get; set; }
- [XmlElement("ftppsswd")]
- public string FtpPsswd { get; set; }
- [XmlElement("fileBytes")]
- public long FileBytes { get; set; }
- [XmlElement("myapplication")]
- public MyApplication MyApplication { get; set; }
- [XmlElement("files")]
- public ManifestFiles ManifestFiles { get; set; }
- [XmlArray("excludes")]
- [XmlArrayItem("exclude", typeof(MyExclude))]
- public List<MyExclude> ExcludeList { get; set; }
- }
- /// <summary>
- /// 更新的文件列表
- /// </summary>
- public class ManifestFiles
- {
- [XmlElement("file")]
- public ManifestFile[] Files { get; set; }
- [XmlAttribute("base")]
- public string BaseUrl { get; set; }
- }
- /// <summary>
- /// 更新的单个文件对象
- /// </summary>
- public class ManifestFile
- {
- [XmlAttribute("source")]
- public string Source
- {
- get;
- set;
- }
- [XmlAttribute("hash")]
- public string Hash
- {
- get;
- set;
- }
- [XmlAttribute("unzip")]
- public string Unzip
- {
- get;
- set;
- }
- }
- /// <summary>
- /// 更新的程序对象
- /// </summary>
- public class MyApplication
- {
- [XmlAttribute("applicationId")]
- public string ApplicationId { get; set; }
- [XmlElement("entryPoint")]
- public EntryPoint EntryPoint { get; set; }
- [XmlElement("location")]
- public string Location { get; set; }
- [XmlElement("expand")]
- public string Expand { get; set; }
- }
- /// <summary>
- /// 排除更新的文件扩展名
- /// </summary>
- public class MyExclude
- {
- [XmlAttribute("name")]
- public string Exclude { get; set; }
- }
- /// <summary>
- /// 程序启动对象
- /// </summary>
- public class EntryPoint
- {
- [XmlAttribute("file")]
- public string File { get; set; }
- [XmlAttribute("parameters")]
- public string Parameters { get; set; }
- }
- /// <summary>
- /// 客户端配置文件对象
- /// </summary>
- public class UpdaterConfigurationView
- {
- private static XmlDocument document = new XmlDocument();
- private static readonly string xmlFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../updateconfiguration.config");
- static UpdaterConfigurationView()
- {
- document.Load(xmlFileName);
- }
- /// <summary>
- /// 刷新配置文件信息
- /// </summary>
- public void Refresh()
- {
- document.RemoveAll();
- document.Load(xmlFileName);
- }
- /// <summary>
- /// 程序版本
- /// </summary>
- public string Version
- {
- get
- {
- return document.SelectSingleNode("applicationUpdater").Attributes["version"].Value;
- }
- set
- {
- document.SelectSingleNode("applicationUpdater").Attributes["version"].Value = value;
- document.Save(xmlFileName);
- }
- }
- /// <summary>
- /// 应用程序唯一标识
- /// </summary>
- public string ApplicationId
- {
- get
- {
- return document.SelectSingleNode("applicationUpdater").Attributes["applicationId"].Value;
- }
- set
- {
- document.SelectSingleNode("applicationUpdater").Attributes["applicationId"].Value = value;
- document.Save(xmlFileName);
- }
- }
- /// <summary>
- /// 远程更新文件的清单路径
- /// </summary>
- public string ManifestUri
- {
- get
- {
- return document.SelectSingleNode("applicationUpdater").Attributes["manifestUri"].Value;
- }
- set
- {
- document.SelectSingleNode("applicationUpdater").Attributes["manifestUri"].Value = value;
- document.Save(xmlFileName);
- }
- }
- /// <summary>
- /// 远程用户名
- /// </summary>
- public string ManifestName
- {
- get
- {
- return document.SelectSingleNode("applicationUpdater").Attributes["manifestName"].Value;
- }
- set
- {
- document.SelectSingleNode("applicationUpdater").Attributes["manifestName"].Value = value;
- document.Save(xmlFileName);
- }
- }
- /// <summary>
- /// 远程密码
- /// </summary>
- public string ManifestPasswd
- {
- get
- {
- return document.SelectSingleNode("applicationUpdater").Attributes["manifestPasswd"].Value;
- }
- set
- {
- document.SelectSingleNode("applicationUpdater").Attributes["manifestPasswd"].Value = value;
- document.Save(xmlFileName);
- }
- }
- /// <summary>
- /// 程序名称
- /// </summary>
- public string Title
- {
- get
- {
- return document.SelectSingleNode("applicationUpdater").Attributes["title"].Value;
- }
- set
- {
- document.SelectSingleNode("applicationUpdater").Attributes["title"].Value = value;
- document.Save(xmlFileName);
- }
- }
- }
- }
|