Beispiel #1
0
        private static void genAutoUpdater(string version, string comment, string minimumRequiredVersion)
        {
            if (enableAliyun)
            {
                ossHelper.OssConfig = new OssConfig()
                {
                    AccessId = accessId, AccessKey = accessKey, BucketName = bucketName
                };
                ossHelper.Delete(prefix);
            }

            #region client

            XmlDocument    clientDoc     = new XmlDocument();
            XmlDeclaration clientxmldecl = clientDoc.CreateXmlDeclaration("1.0", "utf-8", null);
            clientDoc.AppendChild(clientxmldecl);
            XmlElement clientConfig = clientDoc.CreateElement("Config");
            clientDoc.AppendChild(clientConfig);

            //XmlElement clientEnabled = clientDoc.CreateElement("Enabled");
            //clientEnabled.InnerText = "true";
            //clientConfig.AppendChild(clientEnabled);
            XmlElement clientServerUrl = clientDoc.CreateElement("ServerUrl");
            if (type == 0)
            {
                clientServerUrl.InnerText = clientAutoUpdaterUrl + autoUpdaterUrl;
            }
            else
            {
                clientServerUrl.InnerText = clientAutoUpdaterUrl;
            }
            Console.WriteLine(type);
            clientConfig.AppendChild(clientServerUrl);
            XmlElement clientVersion = clientDoc.CreateElement("Version");
            clientVersion.InnerText = version;
            clientConfig.AppendChild(clientVersion);
            XmlElement clientType = clientDoc.CreateElement("Type");
            clientType.InnerText = type + "";
            clientConfig.AppendChild(clientType);
            XmlElement clientRoot = clientDoc.CreateElement("UpdateFileList");

            var f = File.CreateText(autoUpdaterUrl);
            f.WriteLine(url + prefix + serverXmlName);
            f.Close();

            #endregion

            //创建文档对象
            XmlDocument doc = new XmlDocument();

            //创建根节点
            XmlElement root = doc.CreateElement("config");

            XmlElement versionE = doc.CreateElement("version");
            versionE.InnerText = version;
            XmlElement commentE = doc.CreateElement("comment");
            commentE.InnerText = comment;

            XmlElement minimumRequiredVersionE = doc.CreateElement("minimumrequiredversion");
            minimumRequiredVersionE.InnerText = minimumRequiredVersion;

            XmlElement updateFilesE = doc.CreateElement("updateFiles");
            //头声明
            XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", "utf-8", null);
            doc.AppendChild(xmldecl);
            //获取当前目录对象
            DirectoryInfo dicInfo = new DirectoryInfo(currentDirectory);
            //调用递归方法组装xml文件
            PopuAllDirectory(doc, updateFilesE, clientDoc, clientRoot, dicInfo);
            root.AppendChild(versionE);
            root.AppendChild(minimumRequiredVersionE);
            root.AppendChild(commentE);
            root.AppendChild(updateFilesE);
            //追加节点
            doc.AppendChild(root);
            //保存文档

            doc.Save(serverXmlName);
            Console.WriteLine(serverXmlName + " 保存成功");
            clientConfig.AppendChild(clientRoot);
            if (enableClient)
            {
                clientDoc.Save(clientPath + clientXmlName);
                Console.WriteLine(clientPath + clientXmlName + " 保存成功");
                if (enableAliyun)
                {
                    ossHelper.UpLoad(clientPath + clientXmlName, prefix + clientPath + clientXmlName);
                }
            }

            if (enableAliyun)
            {
                ossHelper.UpLoad(serverXmlName, prefix + serverXmlName);
            }

            encryptRunTimeConfig();
        }