protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { try { //合并升级信息 MergeUpgradeInfo(); //获取官方升级版本列表,并存放到本地upgrade/versionlist.config中 AutoUpdate autoUpdate = new AutoUpdate(); string fileContnet = autoUpdate.GetVersionList(); StreamWriter writer = new StreamWriter(Utils.GetMapPath(BaseConfigs.GetForumPath.ToLower() + "config/upgradeini.config")); writer.Write(fileContnet.Replace("\n", "\r\n")); writer.Close(); //取本地更新版本号与官方的最新版本号比较,如果官方有更新,则提示有升级 XmlDocument lastupdate = new XmlDocument(); lastupdate.Load(Utils.GetMapPath(BaseConfigs.GetForumPath.ToLower() + "config/localupgradeini.config")); DateTime build = StrToDateTime(lastupdate.SelectSingleNode("/localupgrade/requiredupgrade").InnerText); XmlDocument currentupdate = new XmlDocument(); currentupdate.LoadXml(fileContnet); XmlNodeList items = currentupdate.SelectNodes("/versionlist/" + BaseConfigs.GetDbType.ToLower() + "/requiredupgrade/item"); XmlNode lastItem = items.Item(items.Count - 1); DateTime version = StrToDateTime(lastItem["version"].InnerText); isNew = version > build; if (isNew) { info.Text = "<span style='font-size:20px;padding:0px 0px 15px 0px;display:block;'>检测到最新版本:" + lastItem["versiondescription"].InnerText + "</span>" + "<div style='border: 1px dotted rgb(219, 221, 211);background: #FFFFCC'>" + lastItem["description"].InnerText + "</div>"; string script = "var versionList = ["; foreach (XmlNode item in items) { if (StrToDateTime(item.FirstChild.InnerText) > build) { script += "{\"version\":\"" + item["version"].InnerText + "\",\"versiondescription\":\"" + item["versiondescription"].InnerText + "\",\"link\":\"" + item["link"].InnerText + "\"},"; } } script = script.TrimEnd(',') + "];"; base.RegisterStartupScript("", "<script>" + script + "</script>"); } else { info.Text = "暂无新版本可更新!"; base.RegisterStartupScript("", "<script>var versionList = []; </script>"); } } catch { info.Text = "升级发生异常,请稍后再试……"; } } }
protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { try { //合并升级信息 MergeUpgradeInfo(); //获取官方升级版本列表,并存放到本地upgrade/versionlist.config中 AutoUpdate autoUpdate = new AutoUpdate(); string fileContnet = autoUpdate.GetVersionList(); StreamWriter writer = new StreamWriter(Utils.GetMapPath(BaseConfigs.GetForumPath.ToLower() + "config/upgradeini.config")); writer.Write(fileContnet.Replace("\n", "\r\n")); writer.Close(); //取本地更新版本号与官方的最新版本号比较,如果官方有更新,则提示有升级 XmlDocument lastupdate = new XmlDocument(); lastupdate.Load(Utils.GetMapPath(BaseConfigs.GetForumPath.ToLower() + "config/localupgradeini.config")); //DateTime build = StrToDateTime(lastupdate.SelectSingleNode("/localupgrade/optionalupgrade/item").InnerText); XmlNodeList local = lastupdate.SelectNodes("/localupgrade/optionalupgrade/dnt" + Utils.GetAssemblyVersion() + "/item"); XmlDocument currentupdate = new XmlDocument(); currentupdate.LoadXml(fileContnet); XmlNodeList service = currentupdate.SelectNodes("/versionlist/" + BaseConfigs.GetDbType.ToLower() + "/optionalupgrade/dnt" + Utils.GetAssemblyVersion() + "/item"); int i = 0; string script = ""; foreach (XmlNode serviceitem in service) { bool exist = false; foreach (XmlNode localitem in local) { if (serviceitem.FirstChild.InnerText == localitem.InnerText) { exist = true; break; } } if (!exist) { isNew = true; info.Text += "<input type='checkbox' value='" + serviceitem["version"].InnerText + "' id='checkbox" + i + "' checked='checked'><label for='checkbox" + i + "'>" + serviceitem["versiondescription"].InnerText + "</label>"; info.Text += "<p style='border: 1px dotted rgb(219, 221, 211); background: rgb(255, 255, 204);font-size:12px;padding:0px 0px 0px 15px;'>" + serviceitem["description"].InnerText + "</p>"; script += "{\"version\":\"" + serviceitem["version"].InnerText + "\",\"versiondescription\":\"" + serviceitem["versiondescription"].InnerText + "\",\"link\":\"" + serviceitem["link"].InnerText + "\"},"; i++; } } if (!isNew) { info.Text = "暂无更新"; } else { base.RegisterStartupScript("", "<script>var versionList = [" + script.TrimEnd(',') + "]</script>"); } } catch { info.Text = "升级发生异常,请稍后再试……"; } } }
private void LoadUpgradeInfo() { if (!IsPostBack) { try { //合并升级信息 MergeUpgradeInfo(); //获取官方升级版本列表,并存放到本地upgrade/versionlist.config中 AutoUpdate autoUpdate = new AutoUpdate(); string fileContnet = autoUpdate.GetVersionList(); StreamWriter writer = new StreamWriter(Utils.GetMapPath(BaseConfigs.GetForumPath.ToLower() + "config/upgradeini.config")); writer.Write(fileContnet.Replace("\n", "\r\n")); writer.Close(); //取本地更新版本号与官方的最新版本号比较,如果官方有更新,则提示有升级 XmlDocument lastupdate = new XmlDocument(); lastupdate.Load(Utils.GetMapPath(BaseConfigs.GetForumPath.ToLower() + "config/localupgradeini.config")); DateTime build = StrToDateTime(lastupdate.SelectSingleNode("/localupgrade/requiredupgrade").InnerText); XmlDocument currentupdate = new XmlDocument(); currentupdate.LoadXml(fileContnet); XmlNodeList items = currentupdate.SelectNodes("/versionlist/" + BaseConfigs.GetDbType.ToLower() + "/requiredupgrade/item"); XmlNode lastItem = items.Item(items.Count - 1); //DateTime version = StrToDateTime(items.Item(items.Count - 1).FirstChild.InnerText); DateTime version = StrToDateTime(lastItem["version"].InnerText); isNew = version > build; if (isNew) { //upgradeInfo = "检测到最新版本:" + version.ToShortDateString() + "<br />" + items.Item(items.Count - 1).LastChild.InnerText + "<br />"; upgradeInfo = "<span style='font-size:16px;'>检测到最新版本:" + lastItem["versiondescription"].InnerText + "</span><br /><span style='padding:3px 0px 3px 10px;display:block;'>" + lastItem["description"].InnerText + "</span>"; } XmlNodeList local = lastupdate.SelectNodes("/localupgrade/optionalupgrade/dnt" + Utils.GetAssemblyVersion() + "/item"); XmlNodeList service = currentupdate.SelectNodes("/versionlist/" + BaseConfigs.GetDbType.ToLower() + "/optionalupgrade/dnt" + Utils.GetAssemblyVersion() + "/item"); string hotfix = ""; foreach (XmlNode serviceitem in service) { bool exist = false; foreach (XmlNode localitem in local) { if (serviceitem.FirstChild.InnerText == localitem.InnerText) { exist = true; break; } } if (!exist) { isHotFix = true; hotfix += serviceitem["versiondescription"].InnerText + "<br />"; } } if (hotfix != "") { upgradeInfo += "<span style='font-size:16px;'>检测到最新补丁:</span><br /><span style='padding:3px 0px 3px 10px;display:block;'>" + hotfix + "</span>"; } if (isNew || isHotFix) { base.RegisterStartupScript("", "<script type='text/javascript'>\r\nshowInfo();\r\n</script>\r\n"); } } catch { ; } } }
private void SaveFile(string dbtype, bool isrequired, string version, string filename) { AutoUpdate autoUpdate = new AutoUpdate(); byte[] context = autoUpdate.GetFile(dbtype,isrequired,version,filename); if(context.Length == 0) { return; } if(!Directory.Exists(Utils.GetMapPath(upgradedir))) { Directory.CreateDirectory(Utils.GetMapPath(upgradedir)); } FileStream fs = new FileStream(Utils.GetMapPath(upgradedir + "/" + filename), FileMode.Create); fs.Write(context,0,context.Length); fs.Close(); }