The LZMA Content Manager loads content for an XNA game either from individually LZMA-compressed content files or from a LZMA archive containing multiple content files. In a real-world application, LZMA compression has trimmed the game's size to about 66% of the size achieved by XNA's built-in content compression without any noticeable impact on loading performance.

Compressing your Content

To compress you game content files, it is important to first disable XNA's built-in content compression. Otherwise, the LZMA algorithm has shown to not provide any significant gains.

After your game is built, the Nuclex ContentCompressor can be run on your game assets. To compress content files individually, navigate to your game's output directory and use the following command line:

\path\to\Nuclex.ContentCompressor *.xnb

The tool automatically works recursively. If you want it to delete the original files after it has compressed them, append the --delete parameter. Don't worry, the *.xnb files are rebuilt when you compile your project, but if you've got them in compressed form, you don't actually need them in uncompressed form, so the --delete parameter is useful when you do your final build before shipping.

If you want to compress your content files into one big archive, invoke the ContentCompressor like this:

\path\to\Nuclex.ContentCompressor --package MyPackage.npk *.xnb

As before, the tool will work recursively and you can use the --delete parameter to delete the original files after compression.

In all cases, instead of *.xnb, you can also specify a text file containing a list of files to process by appending an @ to the file name like this:

\path\to\Nuclex.ContentCompressor --package MyPackage.npk @FilesToCompress.txt


The LzmaContentManager is almost a drop-in-replacement for the normal ContentManager.

If you compressed your content files individually, just construct it normally:
LzmaContentManager contentManager = new LzmaContentManager(Game.Services);
If you compressed your content files into a single package, specify the package the content manager should open:
LzmaContentManager contentManager = new LzmaContentManager(
  Game.Services, "MyPackage.npk"
You can then use the LZMA Content Manager like you would use the normal content manager. For content nested in subdirectories, the package will use the '/' (forward slash, not backward slash) character to separate directory levels. This is because the forward slash works well on windows, but if Mono.Xna or a similar project ever manages to reach a usable state, the forward slash will work everywhere and doesn't need manual Path.DirectorySeparatorChar fiddling.

Last edited Sep 12, 2009 at 6:41 PM by Cygon, version 5


pierznj Apr 13, 2012 at 5:48 AM 
Note that the command line format above does not work. I had to look in the source code to see that it should be, not --package MyPackage.npk *.xnb, but /package:MyPackage.npk *.xnb