微信小程序本地存储与登录页面处理实例详细讲解
628
2022-11-10
CS程序发布版本后提示自动升级功能
public UpdateManager() { //1.初始化对象属性 this.LastUpdateInfo = new UpdateInfo(); this.NowUpdateInfo = new UpdateInfo(); //2.给属性赋值 this.GetLastUpdateInfo(); this.GetNewUpdateInfo(); } //属性 public UpdateInfo LastUpdateInfo { get; set; } public UpdateInfo NowUpdateInfo { get; set; } //是否需要更新,根据时间 public bool IsUpdate { get { DateTime dt1 = Convert.ToDateTime(this.LastUpdateInfo.UpdateTime); DateTime dt2 = Convert.ToDateTime(this.NowUpdateInfo.UpdateTime); return dt2 > dt1; } } //存放更新文件的临时目录 public string TempFilePath { get { string newTempPath = Environment.GetEnvironmentVariable("Temp") +"\updatefiles"; if (!Directory.Exists(newTempPath)) Directory.CreateDirectory(newTempPath); return newTempPath; } } //从本地获取上次更新的信息,并封装到属性(对比作用) private void GetLastUpdateInfo() { FileStream myFiles = new FileStream("UpdateList.xml", FileMode.Open); XmlTextReader xmlReader = new XmlTextReader(myFiles); while (xmlReader.Read()) { switch (xmlReader.Name) { case "URLAddress": this.LastUpdateInfo.UpdateFileUrl = xmlReader.GetAttribute("URL"); break; case "Version": this.LastUpdateInfo.Version = xmlReader.GetAttribute("Num"); break; case "UpdateTime": this.LastUpdateInfo.UpdateTime =Convert.ToDateTime( xmlReader.GetAttribute("Date")); break; default: break; } xmlReader.Close(); myFiles.Close(); } } //从服务器-最新的更新信息并封装到属性 private void GetNewUpdateInfo() { //-最新的跟新目录到临时目录 string newXmlTempPath = TempFilePath + "\UpdateList.xml"; WebClient objClient = new WebClient(); objClient.DownloadFile( this.LastUpdateInfo.UpdateFileUrl + "\UpdateList.xml", newXmlTempPath); //封装更新的信息 FileStream myfile = new FileStream(newXmlTempPath,FileMode.Open); XmlTextReader xmlReader = new XmlTextReader(myfile); this.NowUpdateInfo.FileList = new List
xml配置:
-
public class UpdateInfo { public string Version { get; set; } public DateTime UpdateTime { get; set; } public string UpdateFileUrl { get; set; } //跟新文件的信息列表(和listView的显示对应) public List
public partial class Form1 : Form { private UpdateManager objUpdateManager = new UpdateManager(); public Form1() { InitializeComponent(); Init(); } private void Init() { this.btnFinshed.Visible = false; objUpdateManager.ShowUpdateProgressDelegate = this.ShowUpdateProgress; List
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~