|
2 | 2 | using Microsoft.VisualBasic;
|
3 | 3 | using StudioCore.Core.Data;
|
4 | 4 | using StudioCore.Editors.TextEditor.Views;
|
| 5 | +using StudioCore.Platform; |
5 | 6 | using System;
|
6 | 7 | using System.Collections.Generic;
|
7 | 8 | using System.IO;
|
@@ -62,18 +63,25 @@ public static void PackageAll()
|
62 | 63 | ManifestHandler.CreateManisfestIfMissing();
|
63 | 64 | }
|
64 | 65 |
|
| 66 | + private static List<string> ExcludedTables = new List<string>(); |
65 | 67 |
|
66 | 68 | public static void ExportPTF()
|
67 | 69 | {
|
68 | 70 | var status = Warbox.TableEditor.FileSelectionView.GetSelectedDocumentStatus();
|
69 | 71 |
|
| 72 | + if(ExcludedTables.Contains(status.Name)) |
| 73 | + { |
| 74 | + PlatformUtils.Instance.MessageBox("This table does not support patching.", "Warning", MessageBoxButtons.OK); |
| 75 | + return; |
| 76 | + } |
| 77 | + |
70 | 78 | foreach (var entry in DataHandler.Tables)
|
71 | 79 | {
|
72 | 80 | var vanillaEntry = DataHandler.Vanilla_Tables.Where(e => e.Key.Name == entry.Key.Name).FirstOrDefault();
|
73 | 81 |
|
74 | 82 | if (entry.Key.Name == status.Name)
|
75 | 83 | {
|
76 |
| - (bool, string, XDocument) result = BuildPatchDocument(entry.Key, entry.Value, vanillaEntry.Value); |
| 84 | + (bool, string, XDocument) result = BuildOutputDocument(entry.Key, entry.Value, vanillaEntry.Value); |
77 | 85 | //(bool, string, XDocument) result = RemoveVanillaEntries(entry.Key, entry.Value, vanillaEntry.Value);
|
78 | 86 |
|
79 | 87 | if(result.Item1 && result.Item3 != null)
|
@@ -130,27 +138,99 @@ private static void SaveTable(string saveDir, ResourceDescriptor resDesc, XDocum
|
130 | 138 | }
|
131 | 139 | }
|
132 | 140 |
|
133 |
| - private static Dictionary<string, List<RemovalTag>> Removals = new(); |
134 |
| - |
135 |
| - private static (bool, string, XDocument) BuildPatchDocument(ResourceDescriptor resDesc, XDocument baseDoc, XDocument vanillaDoc) |
| 141 | + private static (bool, string, XDocument) BuildOutputDocument(ResourceDescriptor resDesc, XDocument baseDoc, XDocument vanillaDoc) |
136 | 142 | {
|
| 143 | + var tableDef = TableDefinition.Definitions.Where(e => e.Attribute("Name").Value == resDesc.BaseName).FirstOrDefault(); |
| 144 | + |
137 | 145 | var tempDoc = new XDocument(baseDoc);
|
| 146 | + var outputDoc = new XDocument(baseDoc); |
| 147 | + |
| 148 | + if (tableDef == null) |
| 149 | + { |
| 150 | + return (true, "Table is not defined in TableDefinitions.xml.", tempDoc); |
| 151 | + } |
138 | 152 |
|
139 |
| - var databaseTier = tempDoc.Elements().ToList(); |
140 |
| - var propertyGroupTier = tempDoc.Elements().Elements().ToList(); |
141 |
| - var propertyEntryTier = tempDoc.Elements().Elements().Elements().ToList(); |
| 153 | + // Clear all entries in the output doc |
| 154 | + XElement container = outputDoc.Elements().Elements().FirstOrDefault(); |
| 155 | + if(container == null) |
| 156 | + { |
| 157 | + return (true, "Failed to find XML container element", tempDoc); |
| 158 | + } |
| 159 | + |
| 160 | + container.Elements().Remove(); |
| 161 | + |
| 162 | + // This is used to link X entry (base) with Y entry (vanilla) so the attributes can then be compared |
| 163 | + var primaryKeyAttribute = tableDef.Attribute("RowNameKey"); |
| 164 | + |
| 165 | + // If the primary key is not defined at all, return. |
| 166 | + if (primaryKeyAttribute == null) |
| 167 | + { |
| 168 | + return (true, "RowNameKey is not set in TableDefinitions.xml for this table.", tempDoc); |
| 169 | + } |
142 | 170 |
|
143 |
| - foreach (var entry in propertyEntryTier) |
| 171 | + // If the primary key is blank, this table cannot be supported. |
| 172 | + if(primaryKeyAttribute.Value == "") |
144 | 173 | {
|
145 |
| - // Attributes on this tier |
146 |
| - var attributes = entry.Attributes().ToList(); |
| 174 | + return (true, "Patching is not supported for this table.", tempDoc); |
| 175 | + } |
147 | 176 |
|
148 |
| - foreach (var attribute in attributes) |
| 177 | + // Find entries that should be added to output doc |
| 178 | + var baseEntries = tempDoc.Elements().Elements().Elements().ToList(); |
| 179 | + var vanillaEntries = vanillaDoc.Elements().Elements().Elements().ToList(); |
| 180 | + |
| 181 | + foreach (var entry in baseEntries) |
| 182 | + { |
| 183 | + var keyAtttribute = entry.Attribute(primaryKeyAttribute.Value); |
| 184 | + |
| 185 | + if (keyAtttribute == null) |
| 186 | + continue; |
| 187 | + |
| 188 | + var primaryKey = keyAtttribute.Value; |
| 189 | + |
| 190 | + // Get the vanilla entry based on the primary key |
| 191 | + var vanillaEntry = vanillaEntries.Where( |
| 192 | + e => e.Attribute(primaryKeyAttribute.Value) != null && |
| 193 | + e.Attribute(primaryKeyAttribute.Value).Value == primaryKey).FirstOrDefault(); |
| 194 | + |
| 195 | + if (vanillaEntry == null) |
| 196 | + continue; |
| 197 | + |
| 198 | + var addEntry = false; |
| 199 | + |
| 200 | + // Element Value check |
| 201 | + if (entry.Value != vanillaEntry.Value) |
149 | 202 | {
|
150 |
| - var check = attribute.ToString(); |
151 |
| - var stop = ""; |
| 203 | + addEntry = true; |
| 204 | + // Add this entry to output doc |
152 | 205 | }
|
153 | 206 |
|
| 207 | + // Attribute Value check |
| 208 | + var baseAttributes = entry.Attributes().ToList(); |
| 209 | + var vanillaAttributes = vanillaEntry.Attributes().ToList(); |
| 210 | + |
| 211 | + foreach(var bAttribute in baseAttributes) |
| 212 | + { |
| 213 | + var attributeName = bAttribute.Name; |
| 214 | + var vanillaEqual = vanillaAttributes.Where(e => e.Name == attributeName).FirstOrDefault(); |
| 215 | + |
| 216 | + if (vanillaEqual == null) |
| 217 | + continue; |
| 218 | + |
| 219 | + if(bAttribute.Value != vanillaEqual.Value) |
| 220 | + { |
| 221 | + addEntry = true; |
| 222 | + // Add this entry to output doc |
| 223 | + } |
| 224 | + } |
| 225 | + |
| 226 | + // Add the entry to the output doc if there is a difference found |
| 227 | + if(addEntry) |
| 228 | + { |
| 229 | + container.Add(entry); |
| 230 | + } |
| 231 | + |
| 232 | + // TODO: add checking for sub list and sub-sub list attributes so we can add the parent element if they differ |
| 233 | + /* |
154 | 234 | // Inner tier 1
|
155 | 235 | var subListTier = entry.Elements().ToList();
|
156 | 236 | foreach (var subEntry in subListTier)
|
@@ -178,10 +258,13 @@ private static (bool, string, XDocument) BuildPatchDocument(ResourceDescriptor r
|
178 | 258 | }
|
179 | 259 | }
|
180 | 260 | }
|
| 261 | + */ |
181 | 262 | }
|
182 | 263 |
|
183 |
| - return (true, "", tempDoc); |
| 264 | + return (true, "", outputDoc); |
184 | 265 | }
|
| 266 | + |
| 267 | + private static Dictionary<string, List<RemovalTag>> Removals = new(); |
185 | 268 |
|
186 | 269 | // TODO: fix this so it works with nested elements
|
187 | 270 | private static (bool, string, XDocument) RemoveVanillaEntries(ResourceDescriptor resDesc, XDocument baseDoc, XDocument vanillaDoc)
|
|
0 commit comments