示例#1
0
        public void CanPatchVanillaUI()
        {
            throw new NotImplementedException("need to be reworked for new backup foirmat");
            var subject = new PatchDataLoader();
            var dllLoader = new DataLoader();

            var uiDataLoader = new UIDataLoader();

            var patchPath = Path.Combine(Directory.GetCurrentDirectory(), "TestData", "CorePatches.xml");
            var uiPath = Path.Combine(Directory.GetCurrentDirectory(), "TestData", "skin1.xml");

            var loaded = subject.LoadData(patchPath);

            foreach (var definition in loaded.Definitions)
            {
                foreach (var uiPatch in definition.UIPatches)
                {
                    Assert.IsTrue(uiPatch.FilePath.EndsWith("xml")); //need to extend tests for other files

                    var doc = uiDataLoader.FixAndLoadXml(uiPath);

                    var nodeToPatch = doc.XPathSelectElement(uiPatch.XPath);

                    Assert.IsTrue(nodeToPatch != null);

                    var nr = new XmlNodeReader(uiPatch.Data);

                    var patchedNode = XElement.Load(nr).Descendants().FirstOrDefault();
                    //patchedNode = patchedNode.Descendants().FirstOrDefault();

                    if (uiPatch.PatchMode == UIPatchMode.Replace)
                    {
                        var parent = nodeToPatch.Parent;
                        var prevNode = nodeToPatch.PreviousNode;

                        var backup = new XComment(string.Format("__sotsos_backup__|{0}|__sotsos_backup__", nodeToPatch.ToString()));
                        patchedNode.Add(backup);
                        nodeToPatch.Remove();

                        if (prevNode != null)
                        {
                            prevNode.AddAfterSelf(patchedNode);
                        }
                        else
                        {
                            parent.Add(patchedNode);
                        }
                    }

                    var wr = doc.CreateWriter();

                    using (var writer = XmlWriter.Create(uiPath))
                    {
                        doc.WriteTo(writer);
                    }

                }
            }
        }
示例#2
0
        public void ValidatePatchXpaths()
        {
            var subject = new PatchDataLoader();
            var dllLoader = new DataLoader();

            var uiDataLoader = new UIDataLoader();

            var patchPath = Path.Combine(Directory.GetCurrentDirectory(), "TestData", "CorePatches.xml");
            var uiPath = Path.Combine(Directory.GetCurrentDirectory(), "TestData", "skin1.xml");

            var loaded = subject.LoadData(patchPath);

            foreach (var definition in loaded.Definitions.Where(d => d.UIPatches != null && d.UIPatches.Any(u => u.FilePath.EndsWith("skin1.xml"))))
            {
                foreach (var uiPatch in definition.UIPatches)
                {
                    Assert.IsTrue(uiPatch.FilePath.EndsWith("skin1.xml")); //need to extend tests for other files

                    var doc = uiDataLoader.FixAndLoadXml(uiPath);

                    var xpathNode = doc.XPathSelectElement(uiPatch.XPath);

                    Assert.IsTrue(xpathNode != null);

                }
            }
        }