Skip to content

Commit 67153e9

Browse files
committed
chore(XMLDiff): add RunXMLDiff.bat script and documentation for integration with VSCode; update cspell.json
1 parent 7e3e238 commit 67153e9

File tree

4 files changed

+182
-0
lines changed

4 files changed

+182
-0
lines changed

XmlDiffExample.cs

Whitespace-only changes.

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
],
88
"words": [
99
"advancedelectronics",
10+
"aiscripts",
1011
"assignedcontrolled",
1112
"bbcode",
1213
"defaultorder",

forVSCode/RunXMLDiff.bat

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
@echo off
2+
setlocal
3+
4+
REM Check if the required parameters are provided
5+
if "%~1"=="" (
6+
echo Error: Full path to the modified file is mandatory.
7+
exit /b 1
8+
)
9+
if "%~2"=="" (
10+
echo Error: Full path to XMLDiff.exe utility is mandatory.
11+
exit /b 1
12+
)
13+
14+
set "ModifiedFilePath=%~1"
15+
set "XMLDiffPath=%~2"
16+
set "OriginalFilesPath=%~3"
17+
18+
REM Extract the type and filename from the modified file path
19+
for %%I in ("%ModifiedFilePath%") do set "ModifiedFileName=%%~nxI"
20+
for %%I in ("%ModifiedFilePath%") do set "ModifiedDirectory=%%~dpI"
21+
for %%I in ("%ModifiedDirectory:~0,-1%") do set "Type=%%~nxI"
22+
set "Type=%Type:.modified=%"
23+
set "TargetFilePath=%ModifiedFilePath:.modified=%"
24+
25+
REM Determine the original file path
26+
if not "%OriginalFilesPath%"=="" (
27+
set "OriginalFilePath=%OriginalFilesPath%\%Type%\%ModifiedFileName%"
28+
) else (
29+
set "OriginalFilePath=%ModifiedFilePath:.modified=.original%"
30+
)
31+
32+
REM Check existence of XMLDiff.exe
33+
if not exist "%XMLDiffPath%" (
34+
echo Error: XMLDiff.exe not found at path: %XMLDiffPath%
35+
exit /b 1
36+
)
37+
38+
REM Check existence of modified file
39+
if not exist "%ModifiedFilePath%" (
40+
echo Error: Modified file not found at path: %ModifiedFilePath%
41+
exit /b 1
42+
)
43+
44+
REM Check existence of original file
45+
if not exist "%OriginalFilePath%" (
46+
echo Error: Original file not found at path: %OriginalFilePath%
47+
exit /b 1
48+
)
49+
50+
REM Check existence of target file directory
51+
for %%I in ("%TargetFilePath%") do set "TargetDirectory=%%~dpI"
52+
if not exist "%TargetDirectory%" (
53+
echo Error: Target directory not found at path: %TargetDirectory%
54+
exit /b 1
55+
)
56+
57+
REM Run XMLDiff.exe
58+
"%XMLDiffPath%" -o "%OriginalFilePath%" -m "%ModifiedFilePath%" -d "%TargetFilePath%"
59+
if errorlevel 1 (
60+
echo Error: XMLDiff.exe failed with exit code: %errorlevel%
61+
exit /b 1
62+
)
63+
64+
echo XMLDiff completed successfully. Output file: %TargetFilePath%
65+
endlocal

forVSCode/XMLDIffwithVSCode.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Using XMLDIff with Visual Studio Code
2+
3+
## Introduction
4+
5+
This document describes how to use XMLDiff with Visual Studio Code.
6+
7+
## Prerequisites
8+
9+
- Visual Studio Code
10+
- XMLDiff.exe and RunXMLDiff.bat from this repository
11+
- VSCode extension (Run on Save)[https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave] by (emeraldwalk)[https://marketplace.visualstudio.com/publishers/emeraldwalk]
12+
13+
## Steps
14+
15+
1. Prepare a folders structure like the following:
16+
17+
```plaintext
18+
RootExtensionFolder
19+
│ XMLDiffAndPatch
20+
│ │ XMLDiff.exe
21+
│ RunXMLDiff.bat
22+
│ aiscripts
23+
│ aiscripts.modified
24+
│ aiscripts.original
25+
│ md
26+
│ md.modified
27+
│ md.original
28+
```
29+
30+
2. You can scipt creation `*.original` folders, if you will use the `extracted` files folder.
31+
3. Copy the `RunXMLDiff.bat` file to the root of your project.
32+
4. Copy the `XMLDiff.exe` file to the `XMLDiffAndPatch` folder in the root of your project.
33+
5. Install the VSCode extension (Run on Save)[https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave] by (emeraldwalk)[https://marketplace.visualstudio.com/publishers/emeraldwalk]
34+
6. Open the settings of the extension by pressing `Ctrl + ,` and search for `runOnSave.commands`
35+
7. Add the following configuration to the settings:
36+
7.1 In case of not to use the "Extracted" files folder, i.e. with `*.original` folders:
37+
38+
```json
39+
"commands": [
40+
{
41+
"match": "\\.modified\\\\.+?\\.xml$",
42+
"cmd": "${workspaceFolder}\\RunXMLDiff.bat ${file} ${workspaceFolder}\\XMLDiffAndPatch\\XMLDiff.exe
43+
}
44+
]
45+
```
46+
47+
7.2. With the `extracted` folder, which is outside the project folder:
48+
49+
```json
50+
"commands": [
51+
{
52+
"match": "\\.modified\\\\.+?\\.xml$",
53+
"cmd": "${workspaceFolder}\\RunXMLDiff.bat ${file} ${workspaceFolder}\\XMLDiffAndPatch\\XMLDiff.exe" ${workspaceFolder}\\..\\extracted"
54+
}
55+
]
56+
57+
8. Save the settings and close the settings tab.
58+
59+
Now you can modify the `*.modified` files and the `RunXMLDiff.bat` will be executed automatically on save.
60+
61+
You can check an output in the `OUTPUT` tab in the VSCode, selecting the `Run on Save` item in the dropdown list.
62+
63+
## Description of the RunXMLDiff.bat
64+
65+
`RunXMLDiff.bat` is a batch script that compares a modified XML file with its original version using the `XMLDiff.exe` utility. The script takes the paths to the modified file, the XMLDiff utility, and optionally the path to the original files as input. It then constructs the appropriate paths, checks for the existence of necessary files and directories, and runs the XMLDiff utility to generate a diff file.
66+
67+
### Usage
68+
69+
```batch
70+
RunXMLDiff.bat <ModifiedFilePath> <XMLDiffPath> [OriginalFilesPath]
71+
```
72+
73+
#### Parameters
74+
75+
- `<ModifiedFilePath>`: The full path to the modified XML file. This parameter is mandatory.
76+
- `<XMLDiffPath>`: The full path to the `XMLDiff.exe` utility. This parameter is mandatory.
77+
- `[OriginalFilesPath]`: The full path to the directory containing the original XML files. This parameter is optional.
78+
79+
#### Example
80+
81+
```batch
82+
RunXMLDiff.bat "C:\path\to\md.modified\file.xml" "C:\path\to\XMLDiff.exe" "C:\path\to\original\files"
83+
```
84+
85+
#### How It Works
86+
87+
1. **Extract Type and Filename**: The script extracts the type (e.g., `aiscript` or `md`) and filename from the modified file path.
88+
2. **Determine Target File Path**: The script constructs the target file path by removing `.modified` from the modified file path.
89+
3. **Determine Original File Path**:
90+
- If the `OriginalFilesPath` is provided, the original file path is constructed as `OriginalFilesPath\type\filename`.
91+
- If the `OriginalFilesPath` is not provided, the original file path is constructed by replacing `.modified` with `.original` in the modified file path.
92+
4. **Check Existence**:
93+
- The script checks for the existence of `XMLDiff.exe`, the modified file, the original file, and the target file directory.
94+
5. **Run XMLDiff**: If all checks pass, the script runs `XMLDiff.exe` with the appropriate parameters to generate the diff file.
95+
96+
### Error Handling
97+
98+
The script will output error messages and exit with a non-zero status code if any of the following conditions are met:
99+
100+
- `XMLDiff.exe` is not found at the specified path.
101+
- The modified file is not found at the specified path.
102+
- The original file is not found at the constructed path.
103+
- The target file directory does not exist.
104+
105+
### Output
106+
107+
If the script runs successfully, it will output a message indicating that the XMLDiff operation completed successfully and provide the path to the generated diff file.
108+
109+
### Notes
110+
111+
- Ensure that the `XMLDiff.exe` utility is accessible and has the necessary permissions to execute.
112+
- The script assumes that the modified file path follows the convention where the last folder in the path is of the form `type.modified`.
113+
114+
### License
115+
116+
This script is provided "as-is" without any warranty. Use it at your own risk.

0 commit comments

Comments
 (0)