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
{
///
/// 本地版本号
///
public string LocalVersion { get; set; }
///
/// 最后更新时间
///
public string LastUdpate { get; set; }
///
/// server.xml文件地址
///
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);
}
}
}