EasyZip User Guide

By: Nick Gravelyn
http://nick.gravelyn.com/code
nickgravelyn@gmail.com

Latest Installed Version: 1.3
EasyZip Homepage

Welcome to EasyZip, the easiest way to manage your XNA Game Studio 2.0 game's growing content sizes. EasyZip is an incredibly simple solution to automatically add all your content pipeline files into a convenient ZIP file and read these assets from the ZIP file at runtime. This process can reduce your built content sizes by up to 70%!


Latest Version Change Log/Known Issus

v1.3
Changes:
- Removed strong-name signing. Too many issues with it. (Users can download the source and sign their own version if desired)
- Added ExcludedExtensions to the ZipWriter to prevent XACT content from being put into the ZIP file.
- Added FileName property to ZipContentManager
- Removed all audio loading methods from ZipContentManager

Known Issues:
- Non content pipeline files cannot be added to zip file.

Getting Started

Since you already have EasyZip installed, you have most of the work out of the way. The next step to take advantage of the library is to either create a new XNA Game Studio 2.0 project or find an existing XNA Game Studio 2.0 project. After the project has been created, make sure it is not open in Visual Studio. Attempting to update a project that is open can lead to errors in the update process.

Once a project has been created or located, we can run the EasyZip Project Utility to modify the .csproj and .contentproj files that make up your game project. You can launch the EasyZip Project Utility from the Start Menu (All Programs -> EasyZip -> Project Utility). Once open, browse to the game project (.csproj) or type in the path.

Next choose the options you wish. You can have the Project Utiltiy create backup projects for you if you would like. This can be useful in case problems occur later. You can then select whether or not you want the ZIP file to maintain the folder structure. If this box is checked, any folders you create in your content project will be brought over to the ZIP file. If this box is unchecked, all your content will be placed in the ZIP file with no folders at all. You are always able to run the utility against your project again later to change this option.

Once you are presented with a message box informing you the update process was successful, you are ready to begin programming with EasyZip. The content project has all the instructions it needs to create the ZIP file and the game project has the proper references added to it.


Loading Content

Content loaded with EasyZip uses a derived ContentManager called ZipContentManager. This means the process of loading content with EasyZip is almost identical to using the standard ContentManager.

To begin using EasyZip in your code, add a new using statement for the EasyZip namespace:
using EasyZip;
Next declare a new ZipContentManager in your class:
ZipContentManager zipContent;
Next instantiate the ZipContentManager. The constructor is similart to the normal ContentManager constructor in that it requires an IServiceProvider instance (usually Game.Services). The constructor also requires a path to the ZIP file. The ZIP file created will always be next to your game executable and will have the same name as the content subproject. So by default the name is Content.ZIP:
zipContent = new ZipContentManager(Services, "Content.zip");
Lastly we just load content like we would any other ContentManager:
SpriteFont font = zipContent.Load<SpriteFont>("Arial");

Here is an entire Game class filled in to demonstrate the EasyZip capabilities:

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

using EasyZip;

namespace WindowsGame1
{
	public class Game1 : Microsoft.Xna.Framework.Game
	{
		ZipContentManager zipContent;
		GraphicsDeviceManager graphics;
		SpriteBatch spriteBatch;
		SpriteFont font;

		public Game1()
		{
			graphics = new GraphicsDeviceManager(this);
			Content.RootDirectory = "Content";

			zipContent = new ZipContentManager(Services, "Content.zip");
		}

		protected override void LoadContent()
		{
			spriteBatch = new SpriteBatch(GraphicsDevice);
			font = zipContent.Load<SpriteFont>(@"Arial");
		}

		protected override void Draw(GameTime gameTime)
		{
			graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

			spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
			spriteBatch.DrawString(
				font, 
				"Hello EasyZip!", 
				new Vector2(100), 
				Color.White);
			spriteBatch.End();

			base.Draw(gameTime);
		}
	}
}

API Reference

This section details the API of the ZipContentManager class that are not a part of the default ContentManager.

public ZipContentManager(IServiceProvider serviceProvider, string zipFile)
Creates a new ZipContentManager that loads files from the given ZIP file. The default constructor enforces case sensitivity for asset names and file names.
ZipContentManager zipContent = new ZipContentManager(
	Services, 
	"Content.zip");
public ZipContentManager(IServiceProvider serviceProvider, string zipFile, bool caseSensitive)
Creates a new ZipContentManager that loads files from the given ZIP file with the ability to explicitly set case sensitivity for file names.
ZipContentManager zipContent = new ZipContentManager(
	Services, 
	"Content.zip", 
	false);
public string[] GetAssetNames()
Returns an array of the asset names of the content inside the ZIP file.
string[] files = zipContent.GetAssetNames();
foreach (string file in files)
{
	Console.WriteLine(file);
}
public string[] GetAssetNamesFromDirectory(string directory)
Returns an array of asset names from a specific directory within the ZIP file.
string[] files = zipContent.GetAssetNamesFromDirectory("Textures");
List<Texture2D> textures = new List<Texture2D>();
foreach (string file in files)
{
	textures.Add(zipContent.Load<Texture2D>(file));
}
public Stream GetFileStream(string filename)
Returns a Stream for any file inside the ZIP file.
Stream stream = zipContent.GetFileStream("somefile.txt");
using (StreamReader reader = new StreamReader(stream))
{
	Console.WriteLine(reader.ReadLine());
}

Change Log/Known Issues

v1.3
Changes:
- Removed strong-name signing. Too many issues with it. (Users can download the source and sign their own version if desired)
- Added ExcludedExtensions to the ZipWriter to prevent XACT content from being put into the ZIP file.
- Added FileName property to ZipContentManager
- Removed all audio loading methods from ZipContentManager

Known Issues:
- Non content pipeline files cannot be added to zip file.
v1.2
Changes:
- Zip file no longer generated if content files have not been rebuilt.
- EasyZip assemblies are now signed with a strong-name key file.
- Project Updater uses its running directory to determine the installation directory of EasyZip.
- Open Sourced EasyZip!

Known Issues:
- Build process still creates empty "Content" folder in output directory.
- Non content pipeline files cannot be added to zip file.
v1.1
Changes:
- Shortened version number
- Changed "Project Updater" to "Project Utility"
- Made Project Utility able to upgrade projects from older versions of EasyZip
- Removed all the message boxes from Project Utility
- Fixed bug when trying to build ZIP after the output directory has been deleted
- Added option to not create backup project files
- Added option to choose whether or not ZIP file should maintain the content folder structure

Known Issues:
- Build process still creates empty "Content" folder in output directory.
- Non content pipeline files cannot be added to zip file.
v1.0.0
Changes:
- (Initial Release)

Known Issues:
- Build process still creates empty "Content" folder in output directory.
- Non content pipeline files cannot be added to zip file.