1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using System.Web.Hosting;
- using System.Xml;
- namespace MAutoUpdate
- {
- public class LocalInfo
- {
- /// <summary>
- /// 本地版本号
- /// </summary>
- public string LocalVersion { get; set; }
- /// <summary>
- /// 最后更新时间
- /// </summary>
- public string LastUdpate { get; set; }
- /// <summary>
- /// server.xml文件地址
- /// </summary>
- public string ServerUpdateUrl { get; set; }
- public string LocalIgnoreVersion { get; set; }
- private string url = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Local.xml");
- //private string url = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "Local.xml");
- public LocalInfo(string localAddress)
- {
- url = Path.Combine(localAddress, "Local.xml");
- }
- public void SaveReg(string subKey)
- {
- RegistryKey Key;
- Key = Registry.CurrentUser;
- //Key = Key.OpenSubKey("SOFTWARE\\GoodMES\\Update");
- Key = Key.OpenSubKey(subKey, true);
- foreach (var item in this.GetType().GetProperties())
- {
- Key.SetValue(item.Name.ToString(), this.GetType().GetProperty(item.Name.ToString()).GetValue(this, null).ToString());
- }
- }
- public void LoadReg(string subKey)
- {
- //获取本地配置文件
- RegistryKey Key;
- Key = Registry.CurrentUser;
- Key = Key.OpenSubKey(subKey);
- foreach (var item in this.GetType().GetProperties())
- {
- this.GetType().GetProperty(item.Name.ToString()).SetValue(this, Key.GetValue(item.Name.ToString()).ToString(), null);
- }
- Key.Close();
- }
- public void LoadXml(int _type)
- {
- XmlDocument xdoc = new XmlDocument();
- xdoc.Load(url);
- var root = xdoc.DocumentElement;
- var listNodes = root.SelectNodes("/LocalUpdate");
- foreach (XmlNode item in listNodes)
- {
- RemoteInfo remote = new RemoteInfo();
- foreach (XmlNode pItem in item.ChildNodes)
- {
- if (pItem.Name == "LocalVersion" && _type == 1)
- {
- GetType().GetProperty(pItem.Name).SetValue(this, "1.0.0.1", null);
- }
- else
- GetType().GetProperty(pItem.Name).SetValue(this, pItem.InnerText, null);
- }
- }
- }
- public void SaveXml()
- {
- XmlDocument xdoc = new XmlDocument();
- xdoc.Load(url);
- var root = xdoc.DocumentElement;
- var listNodes = root.SelectNodes("/LocalUpdate");
- foreach (XmlNode item in listNodes)
- {
- foreach (XmlNode pItem in item.ChildNodes)
- {
- // Key.SetValue(item.Name.ToString(), this.GetType().GetProperty(item.Name.ToString()).GetValue(this, null).ToString());
- pItem.InnerText = this.GetType().GetProperty(pItem.Name.ToString()).GetValue(this, null).ToString();
- }
- }
- xdoc.Save(url);
- }
- }
- }
|