private static void CreateLast(ThreadArgs args, XmlMainInfo mainInfo) { var lastXml = new XmlDocument(); XmlDeclaration dec1 = lastXml.CreateXmlDeclaration("1.0", "UTF-8", null); lastXml.AppendChild(dec1); //创建根节点 XmlElement root = lastXml.CreateElement("AutoUpdater"); lastXml.AppendChild(root); XmlElement ver = lastXml.CreateElement("Version"); ver.InnerText = mainInfo.Version; root.AppendChild(ver); XmlElement url = lastXml.CreateElement("Url"); url.InnerText = string.Format("{0}/{1}", args.Url.Trim().Substring(0, args.Url.Trim().LastIndexOf("/")), mainInfo.Version + ".xml"); root.AppendChild(url); lastXml.Save(Path.Combine(args.SavePath, "Last.xml")); }
///<summary> ///</summary> ///<param name="obj"></param> private void CreateConfigInfo(object obj) { var args = obj as ThreadArgs; if (args == null) { return; } XmlMainInfo mainInfo = args.MainInfo; ExpansionInfo exInfo = args.ExInfo; _createFileCount = 0; Dictionary <UpdateDirInfo, List <UpdateFileInfo> > dirs; if (args.IsZipFile) { //初始化变量 ZipHelper.i = 0; ZipHelper.currentZipFolder = null; ZipHelper.zipFiles = null; ZipHelper.zipFiles = args.ExcludeInfo.Files; ZipHelper.Zip(args.MainInfo.AppName, Path.Combine(args.SavePath, mainInfo.Version) + ".zip", 6); dirs = new Dictionary <UpdateDirInfo, List <UpdateFileInfo> > { { new UpdateDirInfo( args.MainInfo.AppName.Substring(0, args.MainInfo.AppName.LastIndexOf("\\")), args.MainInfo.AppName.Substring(0, args.MainInfo.AppName.LastIndexOf("\\"))), new List <UpdateFileInfo> { new UpdateFileInfo(Path.Combine(args.SavePath, mainInfo.Version) + ".zip") } } }; } else { dirs = GetAllFiles(args.MainInfo.AppName.Substring(0, args.MainInfo.AppName.LastIndexOf("\\"))); } _createProgress = 1; OnXmlCreateProgress(new XmlCreateProgressArgs { ProgressType = CreateTyep.CreateXml, Msg = "正在创建配置文件!", Complete = false, FileCount = _createFileCount, Progress = _createProgress }); //CreateLast(args, mainInfo); var versionXml = new XmlDocument(); //建立Xml的定义声明 XmlDeclaration dec = versionXml.CreateXmlDeclaration("1.0", "UTF-8", null); versionXml.AppendChild(dec); //创建根节点 XmlElement autoUpdater = versionXml.CreateElement("AutoUpdater"); versionXml.AppendChild(autoUpdater); XmlNode main = versionXml.CreateElement("Main"); XmlElement version = versionXml.CreateElement("Version"); version.InnerText = mainInfo.Version; main.AppendChild(version); XmlElement IsMust = versionXml.CreateElement("IsMust"); IsMust.InnerText = mainInfo.IsMust; main.AppendChild(IsMust); XmlElement description = versionXml.CreateElement("Description"); description.InnerText = mainInfo.Description; main.AppendChild(description); XmlElement updateTime = versionXml.CreateElement("UpdateTime"); updateTime.InnerText = mainInfo.UpdateTime.ToString("yyyy-MM-dd"); main.AppendChild(updateTime); XmlElement appName = versionXml.CreateElement("AppName"); appName.InnerText = mainInfo.AppName.Trim().Substring(mainInfo.AppName.Trim().LastIndexOf("\\") + 1); main.AppendChild(appName); XmlElement type = versionXml.CreateElement("Type"); type.InnerText = mainInfo.UpdateType; main.AppendChild(type); autoUpdater.AppendChild(main); XmlNode expansion = versionXml.CreateElement("Expansion"); XmlElement beforeExecute = versionXml.CreateElement("BeforeExecute"); beforeExecute.SetAttribute("Name", ""); beforeExecute.SetAttribute("Args", ""); expansion.AppendChild(beforeExecute); XmlElement afterExecute = versionXml.CreateElement("AfterExecute"); afterExecute.SetAttribute("Name", ""); afterExecute.SetAttribute("Args", ""); expansion.AppendChild(afterExecute); autoUpdater.AppendChild(expansion); XmlElement fileList = versionXml.CreateElement("FileList"); autoUpdater.AppendChild(fileList); const string xPath = "Directory"; foreach (var item in dirs) { XmlNode parentDir; XmlElement xmlItem = null; if (!item.Key.IsEmpty) { if (item.Key.Parent.Length != 0) { XmlNode tempParentDir = fileList; for (int i = 0; i < item.Key.Parents.Count; i++) { tempParentDir = tempParentDir.SelectSingleNode(xPath + "[@Name=\"" + item.Key.Parents[i] + "\"]"); } parentDir = tempParentDir; } else { parentDir = fileList; } if (item.Key.Current.Length != 0) { xmlItem = versionXml.CreateElement("Directory"); xmlItem.SetAttribute("Name", item.Key.Current); } if (xmlItem != null) { if (item.Value.Count > 0) { NewFile(versionXml, item, xmlItem); } parentDir.AppendChild(xmlItem); } } else { parentDir = fileList; if (item.Value.Count > 0) { NewFile(versionXml, item, parentDir); } } } OnXmlCreateProgress(new XmlCreateProgressArgs { ProgressType = CreateTyep.CreateXml, Msg = "正在保存配置文件!", Complete = false, FileCount = _createFileCount, Progress = _createProgress }); _createProgress++; if (args.IsZipXml) { ZipHelper.Zip(Path.Combine(args.SavePath, mainInfo.Version) + ".xml", Path.Combine(args.SavePath, mainInfo.Version) + ".etc", 6); } else { versionXml.Save(Path.Combine(args.SavePath, mainInfo.Version) + ".xml"); } OnXmlCreateProgress(new XmlCreateProgressArgs { ProgressType = CreateTyep.CreateXml, Msg = "配置文件生成成功!", Complete = true, FileCount = _createFileCount, Progress = _createFileCount }); _createProgress = 0; OnXmlCreateProgress(new XmlCreateProgressArgs { ProgressType = CreateTyep.CreateFile, Msg = "正在发布程序文件!", Complete = false, FileCount = _createFileCount, Progress = _createProgress }); _createProgress++; //CopyFile(dirs, Path.Combine(args.SavePath, mainInfo.Version)); OnXmlCreateProgress(new XmlCreateProgressArgs { ProgressType = CreateTyep.CreateFile, Msg = "新版本发布成功!", Complete = true, FileCount = _createFileCount, Progress = _createFileCount }); Stop(); }