Game Development Reference
In-Depth Information
The
XmlDocument
is responsible for creating new elements by calling
CreateEle-
ment()
, and each element can have multiple children, which are attached with the
AppendChild()
method. Notice the call to
ImportNode()
inside the loop? This
call is required to create a copy of an
XmlElement
created in a different
XmlDocu-
ment
object.
Once the entire
XmlDocument
object is ready, it is saved by creating an
XmlText-
Writer
. The formatting is set so that it makes for easier human reading and editing.
The last menu action is for building the Zip file that contains the entire Assets direc-
tory. For that, a helper class,
ZipFileUtility
, is needed.
private void buildProjectToolStripMenuItem_Click(object sender, EventArgs e)
{
ZipFileUtility.Create(m_AssetsDirectory,
m_ProjectDirectory + “\\Assets.zip”);
}
System.IO.Packaging
has a convenient class called
ZipPackaging
, which can
create or read Zip files, and will form the basis of the
ZipFileUtility
class.
class ZipFileUtility
{
public static void Create(string rootDirectoryName, string zipFileName)
{
DirectoryInfo rootDirectory = new DirectoryInfo(rootDirectoryName);
int rootDirLen = rootDirectory.FullName.Length;
using (Package package = ZipPackage.Open(zipFileName, FileMode.Create))
{
var stack = new Stack<string>();
stack.Push(rootDirectory.FullName);
while (stack.Count > 0)
{
var currentNode = stack.Pop();
var directoryInfo = new DirectoryInfo(currentNode);
foreach (var directory in directoryInfo.GetDirectories())
{
FileAttributes attributes =
File.GetAttributes(directory.FullName);
if ((attributes & FileAttributes.Hidden) == 0 &&
directory.Name != “Editor”)
{
stack.Push(directory.FullName);
}