wasStitchNET – Blame information for rev 7
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
7 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 // |
||
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
||
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
||
5 | /////////////////////////////////////////////////////////////////////////// |
||
6 | |||
7 | using System.Collections.Generic; |
||
8 | using System.Linq; |
||
9 | using System.Xml.Linq; |
||
10 | using System.Xml.XPath; |
||
11 | |||
12 | namespace wasStitchNET.Patchers |
||
13 | { |
||
14 | public static class XML |
||
15 | { |
||
16 | public static XDocument PatchConfiguration(XDocument cfg, XDocument nfg, HashSet<string> configuredTags) |
||
17 | { |
||
18 | /*foreach (var e in nfg.Descendants() |
||
19 | .Where(e => !configuredTags.Contains(e.Name.LocalName) && |
||
20 | !e.Ancestors().Any(o => configuredTags.Contains(o.Name.LocalName))))*/ |
||
21 | foreach (var e in nfg.Descendants() |
||
22 | .Where(e => configuredTags.Contains(e.Name.LocalName))) |
||
23 | { |
||
24 | // Select the element in the current configuration that is found in the default configuration. |
||
25 | var cfgElement = cfg.XPathSelectElement(e.GetAbsoluteXPath()); |
||
26 | switch (cfgElement != null) |
||
27 | { |
||
28 | // Element found in current configuration. |
||
29 | case true: |
||
30 | // Only set the element value if it has no descendants. |
||
31 | if (!cfgElement.Descendants().Any()) |
||
32 | cfgElement.Value = e.Value; |
||
33 | break; |
||
34 | // Element not found in the current configuration. |
||
35 | default: |
||
36 | // Find the first existing parent of the default configuration in the current configuration. |
||
37 | var parent = e.Parent; |
||
38 | XElement cfgParentElement = null; |
||
39 | do |
||
40 | { |
||
41 | cfgParentElement = cfg.XPathSelectElement(parent.GetAbsoluteXPath()); |
||
42 | parent = e.Parent; |
||
43 | } while (cfgParentElement == null); |
||
44 | |||
45 | // Add the default configuration parent to the current configuration. |
||
46 | cfgParentElement = nfg.XPathSelectElement(cfgParentElement.GetAbsoluteXPath()); |
||
47 | break; |
||
48 | } |
||
49 | } |
||
50 | return cfg; |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | |||
55 | |||
56 | |||
57 | |||
58 |