[TOOLS] XML diff and patch for X4: Foundations

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

User avatar
ChemODun
Posts: 436
Joined: Mon, 12. Feb 07, 21:58
x4

Re: [TOOLS] XML diff and patch for X4: Foundations

Post by ChemODun »

Duncaroos wrote: Mon, 24. Feb 25, 16:02 Great! Thanks for the improvements thus far.

Few comments:
  1. Is it possible for the log/executable to record replace / remove actions that were completed?
Yes. Sure, will check.
Duncaroos wrote: Mon, 24. Feb 25, 16:02
  • The append to log command [-a true] seems to not be working. When I ran example 2 with this new command line, the log only shows the first execution and nothing gets appended.
-a - is a modifier for the log key. I.e. without

Code: Select all

-l
it will not affecting on anything. So simple use

Code: Select all

-la
. True is not needed at all
Duncaroos wrote: Mon, 24. Feb 25, 16:02
  • I wanted to try out the directory option for XMLPatch, and I came across this error:

    Code: Select all

    Warn Original file does not exist for diff file 'C:\Users\Dunc\Desktop\Example 3\SWI\V0.85\ware data\Tool\diff\diff wares - COH.xml'. Skipping.
    I believe I have all the original, diff, and output directories set correctly, but could you let me know what's the issue? I added a few notes to the .bat binary file to explain my madness.
    https://drive.google.com/drive/folders/ ... sp=sharing
    ...
  • Working more with the SWI mod wares.xml diff, it seems that the patch is not handling replacement of sub-elements correctly:
Will check too
Multiply entropy by absolute zero

Freedom in space
User avatar
ChemODun
Posts: 436
Joined: Mon, 12. Feb 07, 21:58
x4

Re: [TOOLS] XML diff and patch for X4: Foundations

Post by ChemODun »

[0.2.16] - 2025-02-25
  • Fixed
    • Fixed issue with element replacements
  • Improved
    • Logging information
Multiply entropy by absolute zero

Freedom in space
User avatar
ChemODun
Posts: 436
Joined: Mon, 12. Feb 07, 21:58
x4

Re: [TOOLS] XML diff and patch for X4: Foundations

Post by ChemODun »

Duncaroos wrote: Mon, 24. Feb 25, 16:02
  • Working more with the SWI mod wares.xml diff, it seems that the patch is not handling replacement of sub-elements correctly:
Regarding folder mode, the logic is next:
- it's going thru the diff folder and trying to find the file with the same name in the original one.
- if found - trying to apply diff, and create to the file with the same name in output folder.
It's mode to massive patch all originals by all diffs, i.e. applying the mod folder structure on original game folder structure...

You need you can solve only via bat files
Multiply entropy by absolute zero

Freedom in space
User avatar
Duncaroos
Posts: 719
Joined: Wed, 4. Jan 12, 22:23
x4

Re: [TOOLS] XML diff and patch for X4: Foundations

Post by Duncaroos »

I think I am understanding more.

From your initial post, it sounded like the directory option would look at each file in the original directory, and apply all diffs (located in the diff directory) to each of the original files, then have an output folder with the updated files named after the original files.
ChemODun wrote: Mon, 30. Dec 24, 18:03 The logic will be a next:
  • all input parameters are directories - the tools will apply the diff or patch to all XML files in the directories.
  • it will recursively gro thru the diff or changed XML files in the directories, respectively to the tool.
  • for each diff or changed files will be checked a corresponding original XML file in the original directory with the same relative path.
  • if the original XML file is not found - the diff or changed file will be skipped.
  • if the original XML file is found - the diff or changed file will be patched with the original XML file and created a new patched XML file in the output directory with the same relative path.
I think point 1 may need some revisiting. point 3 is likely something I didn't fully understand but may just need to say that the diff/modified xml file needs to be the same name maybe? I guess from your clarification, the directory option is to allow you to mass update each XML against ONE diff/modified file named exactly like the original (like below) - right?

Code: Select all

original dir:
file1.xml
file2.xml
file3.xml

Code: Select all

modified/diff dir:
file1.xml
file2.xml
file3.xml
Playing X4+All_DLC on:
CPU: Ryzen 5 5600X; RAM: 4x8GB DDR4 3200MHz; GPU: GTX 1070 8GB, Driver v536.23, DirectX 12.0; OS: Win10 Home 22H2 (19045.4780); Monitor: Single Acer S232HL 1920x1080

Duncaroo's Empire Logistics Tool (v0.23 Beta) - {{Vanilla Economy - Direct link}} {{Economy Overhaul Mod Version - Direct link}}
User avatar
ChemODun
Posts: 436
Joined: Mon, 12. Feb 07, 21:58
x4

Re: [TOOLS] XML diff and patch for X4: Foundations

Post by ChemODun »

Duncaroos wrote: Tue, 25. Feb 25, 15:59 I think I am understanding more.

From your initial post, it sounded like the directory option would look at each file in the original directory, and apply all diffs (located in the diff directory) to each of the original files, then have an output folder with the updated files named after the original files.
ChemODun wrote: Mon, 30. Dec 24, 18:03 The logic will be a next:
  • all input parameters are directories - the tools will apply the diff or patch to all XML files in the directories.
  • it will recursively gro thru the diff or changed XML files in the directories, respectively to the tool.
  • for each diff or changed files will be checked a corresponding original XML file in the original directory with the same relative path.
  • if the original XML file is not found - the diff or changed file will be skipped.
  • if the original XML file is found - the diff or changed file will be patched with the original XML file and created a new patched XML file in the output directory with the same relative path.
I think point 1 may need some revisiting. point 3 is likely something I didn't fully understand but may just need to say that the diff/modified xml file needs to be the same name maybe? I guess from your clarification, the directory option is to allow you to mass update each XML against ONE diff/modified file named exactly like the original (like below) - right?

Code: Select all

original dir:
file1.xml
file2.xml
file3.xml

Code: Select all

modified/diff dir:
file1.xml
file2.xml
file3.xml
Yes, will add the clarification about the same names
Multiply entropy by absolute zero

Freedom in space
User avatar
ChemODun
Posts: 436
Joined: Mon, 12. Feb 07, 21:58
x4

Re: [TOOLS] XML diff and patch for X4: Foundations

Post by ChemODun »

In principle it possible to add mode with one original file and folder as a diff parameter - in this case it will thru the files in directory, sorted by names, and apply them step by step
Not sure is it reasonable
Multiply entropy by absolute zero

Freedom in space
User avatar
ChemODun
Posts: 436
Joined: Mon, 12. Feb 07, 21:58
x4

Re: [TOOLS] XML diff and patch for X4: Foundations

Post by ChemODun »

Duncaroos wrote: Tue, 25. Feb 25, 15:59 I think I am understanding more.
If output XML is a directory

If the output XML is a directory, the tool will create a new XML file with the same name as the original XML file in the output directory.
For example, if the original XML file is vanilla.xml and the output directory is output, the tool will create a new XML file output/vanilla.xml.

How to apply a tools to a directories

Applying XMLDiff to directories

You can apply the XMLDiff tool to directories. In this case, the tool will traverse the directory structure and create diff files for XML files with identical names and relative paths. The process is as follows:
  • If all input parameters are directories, the tool will create diff files for all XML files in the directories.
  • The tool will recursively go through the directory structure, using modified files as a "keys" for it
  • For each changed file, the corresponding original XML file in the original directory with the same relative path will be checked.
  • If the original XML file is not found, the operation will be skipped.
  • If the original XML file is found, the diff file will be created in the output directory with the same relative path.
Example:

Code: Select all

XMLDiff.exe -o vanilla_dir -m modified_dir -d diff_dir
Applying XMLPatch to directories

You can apply the XMLPatch tool to directories. In this case, the tool will traverse the directory structure and apply the patch to XML files with identical names and relative paths. The process is as follows:
  • If all input parameters are directories, the tool will apply the patch to all XML files in the directories.
  • The tool will recursively go through the directory structure, using diff files as a "keys" for it
  • For each diff file, the corresponding original XML file in the original directory with the same relative path will be checked.
  • If the original XML file is not found, the operation will be skipped.
  • If the original XML file is found, the diff file will be patched with the original XML file, and a new patched XML file will be created in the output directory with the same relative path.
Example:

Code: Select all

XMLPatch.exe -o vanilla_dir -d diff_dir -u modified_dir
Multiply entropy by absolute zero

Freedom in space
User avatar
ChemODun
Posts: 436
Joined: Mon, 12. Feb 07, 21:58
x4

Re: [TOOLS] XML diff and patch for X4: Foundations

Post by ChemODun »

[0.2.17] - 2025-02-25
  • Fixed
    • Added checks to prevent duplicate elements during addition
Multiply entropy by absolute zero

Freedom in space
User avatar
ChemODun
Posts: 436
Joined: Mon, 12. Feb 07, 21:58
x4

Re: [TOOLS] XML diff and patch for X4: Foundations

Post by ChemODun »

[0.2.20] - 2025-02-27
  • Fixed
    • XMLDiff: wrong attribute selection for the path
    • XMLDiff: fixed issue with not applied --append-to-log option
    • XMLDiff: fixed issue with wrong changed attributes count detection
    • XMLDiff: fixed usage or remove/add instead of replace for elements
    • XMLPatch: skip the diff file without diff elements
  • Improved
    • Both utilities: --log-to-file option now requires a log level (error, warn, info, debug) as a parameter
Multiply entropy by absolute zero

Freedom in space
User avatar
ChemODun
Posts: 436
Joined: Mon, 12. Feb 07, 21:58
x4

Re: [TOOLS] XML diff and patch for X4: Foundations

Post by ChemODun »

[0.2.26] - 2025-06-16
  • Improved:
    • XMLDiff: added in-line comments processing for the add elements in the modified XML file. It allows to define the position attribute of the add element in the diff file.
[0.2.25] - 2025-03-31
  • Fixed:
    • XMLDiff: fixed issue missed root element attributes comparison
    • XMLDiff: fixed usage of the removed element path for the further diff operations
    • XMLDiff: fixed incorrect index number when addressing the elements in XPath
    • XMLDiff: fixed identification elements via sibling keyword in XPath
[0.2.24] - 2025-03-17
  • Improved:
    • Both utilities: result folder will be created in recursive processing as it made now for the single file.
    • XMLDiff: sibling keyword usage in XPath for the elements.
    • XMLDiff: XPath generation when the element has child elements, which can unique identify it.
  • Changed:
    • XMLDiff: --only-full-path option replaced by --anywhere-is-allowed. And default behavior is to use full path.
    • Both utilities: log level of console will not be more detailed than for the log file.
    • Both utilities: the unknown options will be ignored.
  • Fixed:
    • XMLDiff: doubling the first attribute in XPath for the elements, if more than one attribute is used.
[0.2.23] - 2025-03-15
  • Fixed:
    • XMLDiff: fixed issue with the last sub element comparison (index out of range)
[0.2.22] - 2025-03-10
  • Improved
    • XMLDiff: The first attribute of elements in XPath will be always added to make a diff more clear.
    • XMLDiff: If one attribute is not enough to define the element, the next one will be added to the XPath, iteratively.
    • XMLDiff: Added the short description of integration with VSCode via RunXMLDiff.bat script and appropriate extension to make a diffs "on the fly" during editing XML files (modified ones).
[0.2.21] - 2025-03-03
  • Fixed
    • XMLDiff: fixed issue with text nodes differing
    • XMLDiff: improved "pos" definition logic
    • XMLDiff: improved logging information
  • Added
    • XMLPatch: added --allow-doubles option, useful for scripts patching
    • XMLPatch: added comments processing, now comments will be added to the resulting XML file
Multiply entropy by absolute zero

Freedom in space

Return to “X4: Foundations - Scripts and Modding”