/// <summary> /// 数据状态信息 /// </summary> public string OutWrite() { StringBuilder sr = new StringBuilder(); sr.Append(AdminUI.AdminBoxStart(true)); sr.Append(HtmlUI.TableStart("onCenter")); sr.Append(HtmlUI.TrStart()); sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("CurrVer")) + HtmlUI.CreateTd(SiteCfg.SystemVersionFull)); sr.Append(HtmlUI.TrFinal()); try { UpgradeCheck uc = new UpgradeCheck(SiteCfg.Version); sr.Append(HtmlUI.TrStart()); if (uc.Version == SiteCfg.SystemVersionFull) { sr.Append(HtmlUI.CreateTh() + HtmlUI.CreateTd(SiteDat.GetLan("MsgIsLatestVer"))); } else { sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("ToVer")) + HtmlUI.CreateTd(uc.Version)); } sr.Append(HtmlUI.TrStart()); sr.Append(HtmlUI.CreateTh() + HtmlUI.CreateTd(uc.XmlUri)); sr.Append(HtmlUI.TrFinal()); sr.Append(HtmlUI.TrFinal()); if (!string.IsNullOrEmpty(uc.Intro)) { sr.Append(HtmlUI.TrStart()); sr.Append(HtmlUI.CreateTh() + HtmlUI.CreateTd(uc.Intro)); sr.Append(HtmlUI.TrFinal()); } sr.Append(HtmlUI.TableFinal()); sr.Append(AdminUI.AdminBoxFinal()); sr.Append(AdminUI.AdminBoxStart()); sr.Append(HtmlUI.TableStart("onCenter")); int i = 0; foreach (UpgradeFileEntity vItem in uc.GetFileList) { i++; sr.Append(HtmlUI.TrStart()); sr.Append(HtmlUI.CreateTh(i == 1 ? SiteDat.GetLan("UpgradeList") : string.Empty) + HtmlUI.CreateTd(vItem.FilePath)); sr.Append(HtmlUI.TrFinal()); } i = 0; foreach (UpgradeFileEntity vItem in uc.GetRemoveList) { i++; sr.Append(HtmlUI.TrStart()); sr.Append(HtmlUI.CreateTh(i == 1 ? SiteDat.GetLan("RemoveList") : string.Empty) + HtmlUI.CreateTd(vItem.FilePath)); sr.Append(HtmlUI.TrFinal()); } if (uc.Version != SiteCfg.SystemVersionFull) { string upPackUri = uc.PackFile; if (!upPackUri.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase)) { upPackUri = string.Format("{0}_GF/{1}/{2}", SiteCfg.UpdateHost, SiteCfg.Version, uc.PackFile); } sr.Append(HtmlUI.TrStart()); sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("ManualUpdate")) + HtmlUI.CreateTd(HtmlUI.Link(SiteDat.GetLan("GetUpgradePack"), upPackUri, null, true))); sr.Append(HtmlUI.TrFinal()); sr.Append(HtmlUI.TrStart()); sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("ChkToken")) + HtmlUI.CreateTd(HtmlUI.Input("upgradeToken", "upgradeToken", 20, null, null))); sr.Append(HtmlUI.TrFinal()); sr.Append(HtmlUI.TrStart()); sr.Append(HtmlUI.CreateTh() + HtmlUI.CreateTd(HtmlUI.HiddenInput("upgradeVer", "upgradeVer", SiteCfg.Version) + HtmlUI.Button("upgradeBegin", SiteDat.GetLan("BtnUpgrade")))); sr.Append(HtmlUI.TrFinal()); sr.Append(HtmlUI.TrStart()); sr.Append(HtmlUI.CreateTh() + HtmlUI.CreateTd("<div class=\"preBox\"><div id=\"preDemo\" class=\"preNum\" style=\"width:0%;\"></div></div><div id=\"upgradeState\"></div>")); sr.Append(HtmlUI.TrFinal()); } } catch (Exception err) { sr.Append(HtmlUI.TrStart()); sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("GetUpgradeError")) + HtmlUI.CreateTd(err.Message)); sr.Append(HtmlUI.TrFinal()); } sr.Append(HtmlUI.TableFinal()); sr.Append(AdminUI.AdminBoxFinal()); return sr.ToString(); }
protected void Page_Load(object sender, EventArgs e) { string root = HttpContext.Current.Server.MapPath("/"); if (SiteCfg.Token == SiteFun.Post("token")) { string ver = SiteFun.Post("ver"); if (string.IsNullOrEmpty(ver)) { Response.Write("Version error..."); } else { string offFilePath = Path.Combine(root, "app_offline.htm"); try { UpgradeCheck uc = new UpgradeCheck(ver); //Common/Temp/Upgrade string packDir = Path.Combine(SiteCfg.Router, "Common/Temp/Upgrade"); if (!Directory.Exists(packDir)) { Directory.CreateDirectory(packDir); } //1.1.0.gzip string packName = ver + ".gzip"; //Common/Temp/Upgrade/1.1.0.gzip string packFile = Path.Combine(packDir, packName); switch (SiteFun.Query("act")) { case "down": { UpgradeDown down = new UpgradeDown(ver, uc.PackFile, packFile); down.Down(); break; } case "inst": { File.WriteAllText(offFilePath, string.Format("{0} v{1} to {2} upgrading...", SiteCfg.System, SiteCfg.Version, uc.Version)); if (!string.IsNullOrEmpty(uc.SQL)) { DataBase.Conn = SiteCfg.Conn; string[] sqls = uc.SQL.Split(new string[] { ";\n" }, StringSplitOptions.None); new DataBase().ExecSql(sqls); } //common/temp/upgrade/1.0.0 string deDir = Path.Combine(packDir, ver); if (!Directory.Exists(deDir)) { Directory.CreateDirectory(deDir); } GZipResult result = new GZip().Decompress(packDir, deDir, packName); //复制文件 foreach (string file in Directory.GetFiles(deDir)) { FileInfo fi = new FileInfo(file); string copyPath = Path.Combine(SiteCfg.Router, fi.Name); if (file.EndsWith("Web.config", true, null)) { copyPath = Path.Combine(root, fi.Name); } File.Copy(file, copyPath, true); } SiteIO sio = new SiteIO(); //复制文件夹 foreach (string dir in Directory.GetDirectories(deDir)) { DirectoryInfo di = new DirectoryInfo(dir); string copyPath = Path.Combine(SiteCfg.Router, di.Name); if (dir.EndsWith("\\bin", true, null)) { Path.Combine(root, di.Name); } sio.CopyFolder(dir, copyPath); } //移除文件或文件夹 foreach (UpgradeFileEntity item in uc.GetRemoveList) { string fileName = Path.Combine(SiteCfg.Router, item.FilePath); if (item.FilePath.ToUpper() == "BIN" || item.FilePath.StartsWith("bin/", true, null) || item.FilePath.EndsWith("Web.config", true, null)) { fileName = Path.Combine(root, item.FilePath); } FileInfo info = new FileInfo(fileName); if (info.Attributes == FileAttributes.Directory) { Directory.Delete(fileName, true); } else { File.Delete(fileName); } } //File.Delete(Path.Combine(root, offFileName)); if (Directory.Exists(packDir)) { Directory.Delete(packDir, true); } } break; } Response.Write("1"); } catch (Exception err) { Response.Write(err.Message); } if (File.Exists(offFilePath)) { File.Delete(offFilePath); } } } else { Response.Write("Token error..."); } }