Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Invalid arguments.");
                WriteUsage();
                return;
            }

            // extract names from command line
            string sourceXmlFileName  = args[0];
            string diffgramFileName   = args[1];
            string patchedXmlFileName = args[2];

            Console.WriteLine("Patching " + sourceXmlFileName + " with " + diffgramFileName + "\n");

            FileStream patchedFile = new FileStream(patchedXmlFileName, FileMode.Create, FileAccess.Write);

            XmlPatch xmlPatch = new XmlPatch();

            try {
                xmlPatch.Patch(sourceXmlFileName, patchedFile, new XmlTextReader(diffgramFileName));
            }
            catch (Exception ex) {
                WriteError(ex.Message);
                return;
            }

            patchedFile.Close();

            Console.WriteLine("The patched document or fragment has been saved to " + patchedXmlFileName);
        }
Ejemplo n.º 2
0
        public void PatchList()
        {
            //Get project directory path
            var path = System.AppDomain.CurrentDomain.BaseDirectory.Replace("bin", "");

            string originalFile = $"{path}/sdn_xml/SDN.xml";
            String diffGramFile = $"{path}/sdn_xml/newSDN.xml";

            XmlDocument sourceDoc = new XmlDocument(new NameTable());

            //Load local SDN file
            sourceDoc.Load(originalFile);

            XmlTextReader diffgramReader = new XmlTextReader(diffGramFile);

            XmlPatch xmlpatch = new XmlPatch();

            //Patch the local SDN file with the cntent of the Diff
            xmlpatch.Patch(sourceDoc, diffgramReader);

            XmlTextWriter output = new XmlTextWriter(originalFile, Encoding.UTF8);

            output.Formatting = Formatting.Indented;

            //Save the file
            sourceDoc.Save(output);
            output.Close();
        }
Ejemplo n.º 3
0
        public void PatchUp(string originalFile, String diffgramFile, String outputFile)
        {
            XmlDocument sourceDoc = new XmlDocument(new NameTable());

            sourceDoc.Load(originalFile);

            using (XmlTextReader diffgramReader = new XmlTextReader(diffgramFile))
            {
                XmlPatch xmlpatch = new XmlPatch();
                xmlpatch.Patch(sourceDoc, diffgramReader);

                using (XmlTextWriter output = new XmlTextWriter(outputFile, Encoding.Unicode))
                {
                    sourceDoc.Save(output);
                }
            }
        }
Ejemplo n.º 4
0
        //reference: https://msdn.microsoft.com/en-us/library/aa302295.aspx
        //source:	 https://msdn.microsoft.com/en-us/library/aa302294.aspx
        public static void MergeXml(ref XmlNode sourceNode, XmlNode changedNode)
        {
            XmlDiff xmldiff = new XmlDiff(XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreXmlDecl |
                                          XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreNamespaces | XmlDiffOptions.IgnorePrefixes);

            MemoryStream  ms             = new MemoryStream();
            XmlTextWriter diffgramWriter = new XmlTextWriter(ms, Encoding.Default);
            bool          match          = xmldiff.Compare(sourceNode, changedNode, diffgramWriter);

            ms.Position = 0;

            using (XmlTextReader diffgramReader = new XmlTextReader(ms))
            {
                XmlPatch xmlpatch = new XmlPatch();
                xmlpatch.Patch(ref sourceNode, diffgramReader);
            }

            diffgramWriter.Close();
        }
Ejemplo n.º 5
0
        public static void PatchUp(string originalFile, String diffGramFile, String OutputFile)
        {
            XmlDocument sourceDoc = new XmlDocument(new NameTable());

            sourceDoc.Load(originalFile);

            XmlTextReader diffgramReader = new XmlTextReader(diffGramFile);

            XmlPatch myPatcher = new XmlPatch();

            myPatcher.Patch(sourceDoc, diffgramReader); /* If diff is from a different source the following exception is triggered:
                                                         * System.Exception: 'The XDL diffgram is not applicable to this XML document; the srcDocHash value does not match.'
                                                         */

            XmlTextWriter output = new XmlTextWriter(OutputFile, Encoding.UTF8);

            sourceDoc.Save(output);
            output.Close();
        }
Ejemplo n.º 6
0
    void OnUnzipProgress(float progress, int code)
    {
        if (code == 0)
        {
            progressBar.value = progress;
            unzipInfo.text    = string.Format("正在解压资源...{0:F2}%", 100f * progress);
            if (progress >= 1)
            {            //unzip ok
                List <XmlPatch.DFileInfo> fs = null;
                try
                {
                    XmlPatch patch   = new XmlPatch(Application.persistentDataPath + "/Res/");
                    bool     bcancel = false;
                    fs = patch.listDownFiles(onCheckFileProgress, ref bcancel, _resPart);
                }
                catch (Exception e)
                {
                    Log.e(e);
                    fs = null;
                }

                if (fs == null || fs.Count > 0)
                {
                    Log.e("unzip failed", Log.Tag.RES);
                    unzipInfo.text = "解压资源失败,请确保有足够的存储空间(>" + ToSize(_resZipSize) + ")后重启游戏再试";
                    quitBtn.gameObject.SetActive(true);
                    return;
                }

                File.WriteAllText(_unzipTagFile, "ok");
                ResLoad.setVersionPart(_resZipVersion, _resPart);
                Log.i("^_^ unzip ok", Log.Tag.RES);
                EventMgr.single.SendEvent(GRoot.EventResUnzip, true);
            }
        }
        else
        {        //unzip failed
            Log.e("unzip failed", Log.Tag.RES);
            unzipInfo.text = "解压资源失败,请确保有足够的存储空间(>" + ToSize(_resZipSize) + ")后重启游戏再试";
            quitBtn.gameObject.SetActive(true);
        }
    }
Ejemplo n.º 7
0
        public string Patch(string originalversion, string diffContent)
        {
            string newVersion = "";

            XmlDocument sourceDoc         = new XmlDocument(new NameTable());
            XmlReader   srOriginalVersion = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(originalversion)));
            XmlReader   srDiffContent     = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(diffContent)));

            sourceDoc.Load(srOriginalVersion);

            XmlPatch myPatcher = new XmlPatch();

            myPatcher.Patch(sourceDoc, srDiffContent);

            MemoryStream msNewVersionOutput = new MemoryStream();
            XmlWriter    newVersionWriter   = XmlWriter.Create(msNewVersionOutput);

            sourceDoc.Save(newVersionWriter);
            newVersionWriter.Close();

            newVersion = Encoding.UTF8.GetString(msNewVersionOutput.ToArray());

            return(newVersion);
        }
Ejemplo n.º 8
0
        private void Run(string test)
        {
            var patcher = new XmlPatch();
            var sourceFile = string.Format(@".\{0}\Base.xml", test);
            var patchFile = string.Format(@".\{0}\Diff.xml", test);
            var actual = patcher.Patch(sourceFile, patchFile);

            var expectedFile = string.Format(@".\{0}\Result.xml", test);
            var expectedDoc = new XmlDocument();
            expectedDoc.Load(expectedFile);

            Assert.Equal(expectedDoc.InnerXml, actual.InnerXml);
        }