/// <summary> /// 移动文件夹 /// </summary> /// <param name="xmlInfo"></param> private void MoveFolder(XmlMainConfigInfo xmlInfo, string vername) { FileInfo f = new FileInfo(xmlInfo.savefile); //移动前。需要删除移动去的位置是否存在原由文件 FileInfo oldfile = new FileInfo(xmlInfo.oldfile); if (oldfile.Exists)//判断是否需要删除原由文件 { oldfile.Delete(); } f.MoveTo(xmlInfo.oldfile);//规则:code+版本名------- string thisFilePath = AppConfig.filePath + Common.Entities.Constants.TempName; //创建文件以versionname为名的文件夹在指定根目录下 string FilePath = AppConfig.filePath + xmlInfo.oldCode;//当前插件CODE文件夹 while (!Directory.Exists(FilePath)) { Directory.CreateDirectory(FilePath); } //规则:以第一个插件的CODE为主文件夹,以第一个插件的CODE+版本命名的版本文件夹 string thispath = Path.Combine(FilePath, Constants.UpdaterCode + "_FG$SP_" + vername);//当前移动的去的文件夹 //移动前删除新CODE下是否存在该版本文件夹 if (Directory.Exists(thispath)) { Directory.Delete(thispath, true); } Directory.Move(thisFilePath, thispath);//移动-------- }
/// <summary> /// 解析XML获取信息 /// </summary> /// <returns></returns> private XmlMainConfigInfo GetXmlInfo(string xmlpath) { XmlMainConfigInfo x = new XmlMainConfigInfo(); IList <ConfigInfoPC> listG = CommonMethods.GetMainEntityFromXMLPC(Path.Combine(xmlpath, Common.Entities.Constants.UpdaterName)); x.configList = listG; return(x); }
public ActionResult SaveFileInfo(VersionTrack ver, string IsAdd, string IsUpdate, FormCollection form) { var vmobject = new JsonReturnMessages(); string vid = form["VersionIds"].ToString(); XmlMainConfigInfo xmlInfo = null; try { SearchVersionTrack search = new SearchVersionTrack(); search.VID = vid; VersionTrack v = BoFactory.GetVersionTrackBo.GetVersionTrack(search)[0]; if (Request.Files.Count > 0) //若有上传文件 { xmlInfo = Decompressing(v.VersionName); //解压 } vid = BoFactory.GetVersionTrackBo.SaveUpdaterZipInfo(ver, xmlInfo, IsAdd, IsUpdate, base.CurrentUser.UserUId, form["VersionIds"].ToString()); if (Request.Files.Count > 0) //若有上传文件 { MoveFolder(xmlInfo, v.VersionName); //移动文件夹及文件 } } catch (Exception ex) { try { string thisFilePath = AppConfig.filePath + Common.Entities.Constants.TempName; while (Directory.Exists(thisFilePath))//先删除原由临时文件夹 { Directory.Delete(thisFilePath, true); } if (!string.IsNullOrEmpty(xmlInfo.savefile)) { FileInfo f = new FileInfo(xmlInfo.savefile);//删除原本保存的zip if (f.Exists) { f.Delete(); } } } catch (Exception fe) { vmobject.IsSuccess = false; vmobject.Msg = fe.Message; } vmobject.IsSuccess = false; vmobject.Msg = vmobject.Msg + "," + ex.Message; return(Json(vmobject, "text/html")); } vmobject.Msg = vid; vmobject.IsSuccess = true; return(Json(vmobject, "text/html")); }
/// <summary> /// 写入XML /// </summary> /// <param name="path"></param> private XmlMainConfigInfo InsertConfigXml(string Vid) { XmlMainConfigInfo xml = new XmlMainConfigInfo(); SearchVersionTrack searchv = new SearchVersionTrack(); SearchConfig serach = new SearchConfig(); searchv.VID = Vid; VersionTrack v = BoFactory.GetVersionTrackBo.GetVersionTrack(searchv)[0]; serach.PluginCode = v.PluginCode.ToString(); IList <ConfigInfoPC> listc = BoFactory.GetVersionTrackBo.GetConfigPCList(serach);//获取配置信息 xml.configList = listc; CommonMethods.WriteMaininfoConfigXml(listc, Path.Combine(v.FilePath.Trim(), Constants.UpdaterName)); return(xml); }
public ActionResult SavePublishInfo(string Vid, FormCollection form) { var vmobject = new JsonReturnMessages(); try { XmlMainConfigInfo x = InsertXml(Vid);//写入XML SearchVersionTrack search = new SearchVersionTrack(); search.VID = Vid; VersionTrack v = BoFactory.GetVersionTrackBo.GetVersionTrack(search)[0]; string[] codes = v.FilePath.Split(new string[] { "\\" }, StringSplitOptions.None); string name = codes[codes.Length - 2];//获取插件code Beyondbit.AutoUpdate.IPublisher pub = new Beyondbit.SmartBox.Publisher.SmartBoxPublisher(); if (Directory.Exists(Path.Combine(AppConfig.pubFolder, name + AppConfig.subFix)))//如果存在次文件夹 { pub.UpdateApplication(v.FilePath, name); } else { pub.CreateApplication(v.FilePath, name); } BoFactory.GetVersionTrackBo.UpdateUpdaterPlushVersionTracks(x, Vid, base.CurrentUser.UserUId);//更新状态 vmobject.IsSuccess = true; vmobject.Msg = "操作成功"; } catch (Exception ex) { vmobject.IsSuccess = false; vmobject.Msg = ex.Message; } return(Json(vmobject)); }
/// <summary> /// 写入XML /// </summary> /// <param name="path"></param> private XmlMainConfigInfo InsertXml(string Vid) { XmlMainConfigInfo xml = new XmlMainConfigInfo(); SearchVersionTrack searchv = new SearchVersionTrack(); SearchConfig serach = new SearchConfig(); searchv.VID = Vid; VersionTrack v = BoFactory.GetVersionTrackBo.GetVersionTrack(searchv)[0]; serach.PluginCode = v.PluginCode.ToString(); IList <ConfigTemp> listct = BoFactory.GetVersionTrackBo.GetConfigListTemp(serach);//获取配置信息 IList <ConfigInfoPC> listc = new List <ConfigInfoPC>(); foreach (ConfigTemp c in listct) { listc.Add(CommonMethods.ConvertToConfigInfoPC(c));//转换 } xml.configList = listc; CommonMethods.WriteMaininfoConfigXml(listc, Path.Combine(v.FilePath.Trim(), Constants.UpdaterName)); return(xml); }
/// <summary> /// 解压、获取信息 /// </summary> /// <returns></returns> private XmlMainConfigInfo Decompressing(string vername) { string thisFilePath = AppConfig.filePath + Common.Entities.Constants.TempName; while (!Directory.Exists(thisFilePath))//创建临时文件夹 { Directory.CreateDirectory(thisFilePath); } string zipPaht = AppConfig.SaveZipPath; while (!Directory.Exists(zipPaht))//创建存放zip文件的文件夹 { Directory.CreateDirectory(zipPaht); } string saveFile = Path.Combine(zipPaht, System.Guid.NewGuid().ToString() + ".zip"); Request.Files[0].SaveAs(saveFile); //保存zip去文件夹下 CommonMethods.Uncompress(saveFile, thisFilePath); //解压 XmlMainConfigInfo xmlInfo = new XmlMainConfigInfo(); xmlInfo.savefile = saveFile; xmlInfo = GetXmlInfo(thisFilePath); //获取解析出来的配置信息 xmlInfo.oldCode = Constants.UpdaterCode; //否则以第一个CODE为文件夹 //zip文件有第一个CODE+版本号命名 string oldfilepath = Path.Combine(zipPaht, Constants.UpdaterCode + "_FG$SP_" + vername + ".zip"); //重命名的zip文件 xmlInfo.savefile = saveFile; xmlInfo.oldfile = oldfilepath; return(xmlInfo); }