minify
XML minifier.
Merges and minifies MSFS model XML files by removing comments, whitespace and other non-functional content, and combining several files into one. Optionally obfuscates XML behavior templates.
Obfuscation replaces names of local variables, macros, templates and their parameters with obfuscated names to prevent the unauthorized use of your XML behavior code. Obfuscation is completely free: it adds no performance penalty.
Warning
Minification and obfuscation are destructive and it is not possible to restore processed files back to their original state.
Usage
msfs minify [-help] [-nobackup] [-comment str] [-dict file] [-inc xml [xml ...]] -src xml [xml ...] -out xml
- -nobackup
- Skip automatic backup of files before overwriting them. Backup copies are stored in Windows’ temporary folder.
- -comment <str>
- Comment to prepend to minified files (such as copyright statement, timestamp, version number, commit ID, or other similar information.
- -dict <file>
- Path to dictionary file that is used for obfuscation (the file will be created if doesn’t exist). Obfuscated symbols will be stored there, allowing you to obfuscate multiple files using the same symbols and maintaining their interoperability. If the path is left undefined, then obfuscation is not carried out.
- -inc <xml> [<xml> …]]
- If your XML file includes other files, you can use
-inc
to add one or more of them into symbol lookup tables to ensure that everything gets obfuscated. - -src <xml> [<xml> …]]
- XML file to minify and obfuscate. If multiple files are listed, then they are merged into a single file.
- -out <xml>
- Path to output XML file (will be created).
Examples
Template library
Let’s have two XML model behavior template files that we wish to combine into one.
The first file has several macros that define dawn/day/dusk/night and two visibility templates that make parts visible depending on the time of day, first.xml
:
<ModelBehaviors>
<Include ModelBehaviorFile="Asobo\Generic.xml"/>
<!-- This is XML comment -->
<Macro Name="Dawn">0</Macro>
<Macro Name="Day">1</Macro>
<Macro Name="Dusk">2</Macro>
<Macro Name="Night">3</Macro>
<Template Name="visible_at_dawn">
<UseTemplate Name="ASOBO_GT_Visibility_Code">
<VISIBILITY_CODE>(E:TIME OF DAY, enum) @Dawn ==</VISIBILITY_CODE>
</UseTemplate>
</Template>
<Template Name="visible_in_daytime">
<UseTemplate Name="ASOBO_GT_Visibility_Code">
<VISIBILITY_CODE>(E:TIME OF DAY, enum) @Day ==</VISIBILITY_CODE>
</UseTemplate>
</Template>
</ModelBehaviors>
The second file has a single template that sets a local variable (customizable) when object is on ground and has parking brake set, second.xml
:
<ModelBehaviors>
<Include ModelBehaviorFile="Asobo\Generic.xml"/>
<Template Name="set_is_parked">
<Parameters Type="Default">
<VAR>O:IS_PARKED</VAR>
</Parameters>
<UseTemplate Name="ASOBO_GT_Update">
<FREQUENCY>10</FREQUENCY>
<UPDATE_CODE>
(* Inline RPN comment *)
(A:SIM ON GROUND, bool) (A:BRAKE PARKING POSITION, bool) and if{
1 (>#VAR#)
} els{
0 (>#VAR#)
}
</UPDATE_CODE>
</UseTemplate>
</Template>
</ModelBehaviors>
You can combine them into merged.xml
by running:
msfs minify -comment "My template library" -src "first.xml" "second.xml" -out "merged.xml"
The resulting file will look like this:
<!-- My template library -->
<ModelBehaviors>
<Include ModelBehaviorFile="Asobo\Generic.xml" />
<Macro Name="Dawn">0</Macro>
<Macro Name="Day">1</Macro>
<Macro Name="Dusk">2</Macro>
<Macro Name="Night">3</Macro>
<Template Name="visible_at_dawn">
<UseTemplate Name="ASOBO_GT_Visibility_Code">
<VISIBILITY_CODE>(E:TIME OF DAY, enum) @Dawn ==</VISIBILITY_CODE>
</UseTemplate>
</Template>
<Template Name="visible_in_daytime">
<UseTemplate Name="ASOBO_GT_Visibility_Code">
<VISIBILITY_CODE>(E:TIME OF DAY, enum) @Day ==</VISIBILITY_CODE>
</UseTemplate>
</Template>
<Template Name="set_is_parked">
<Parameters Type="Default">
<VAR>O:IS_PARKED</VAR>
</Parameters>
<UseTemplate Name="ASOBO_GT_Update">
<FREQUENCY>10</FREQUENCY>
<UPDATE_CODE>(A:SIM ON GROUND, bool) (A:BRAKE PARKING POSITION, bool) and if{ 1 (>#VAR#) } els{ 0 (>#VAR#) }</UPDATE_CODE>
</UseTemplate>
</Template>
</ModelBehaviors>
Minification tool merged templates into a single file, removed XML and RPN comments, combined tags, and prepended a comment to the file.
This is extremely useful when dealing with a large number of templates: you can split them into separate source files and use the minification tool to build a single merged library file for distribution.
Obfuscation
If you wish to protect your intellectual property, you can also add obfuscation by defining a path to dictionary file (which will be created on first use, and re-used afterwards):
msfs minify -comment "My template library" -src "first.xml" "second.xml" -dict "mydictionary.json" -out "merged.xml"
Resulting file:
<!-- My template library -->
<ModelBehaviors>
<Include ModelBehaviorFile="Asobo\Generic.xml" />
<Macro Name="_M1_">0</Macro>
<Macro Name="_M2_">1</Macro>
<Macro Name="_M3_">2</Macro>
<Macro Name="_M4_">3</Macro>
<Template Name="_T1_">
<UseTemplate Name="ASOBO_GT_Visibility_Code">
<VISIBILITY_CODE>(E:TIME OF DAY, enum) @_M1_ ==</VISIBILITY_CODE>
</UseTemplate>
</Template>
<Template Name="_T2_">
<UseTemplate Name="ASOBO_GT_Visibility_Code">
<VISIBILITY_CODE>(E:TIME OF DAY, enum) @_M2_ ==</VISIBILITY_CODE>
</UseTemplate>
</Template>
<Template Name="_T3_">
<Parameters Type="Default">
<_P1_>O:_V1_</_P1_>
</Parameters>
<UseTemplate Name="ASOBO_GT_Update">
<FREQUENCY>10</FREQUENCY>
<UPDATE_CODE>(A:SIM ON GROUND, bool) (A:BRAKE PARKING POSITION, bool) and if{ 1 (>#_P1_#) } els{ 0 (>#_P1_#) }</UPDATE_CODE>
</UseTemplate>
</Template>
</ModelBehaviors>
Names of macros, templates (except Asobo), local variables and parameters have been obfuscated.
If you obfuscate other files that use this template library using the same shared dictionary, their corresponding names will be obfuscated the same way and the obfuscated copy will be able to use this obfuscated library file.
Obfuscation makes it much harder to pick your code apart and re-use it without authorization, particularly when you have large and complex templates that reference each other.