public void FromHolder_Test__FileHeaderIsConsistent() { MegFileHolder megFileHolder = new MegFileHolder(BASE_PATH, "test"); megFileHolder.Content.Add(new MegFileDataEntry("data/xml/campaignfiles.xml")); megFileHolder.Content.Add(new MegFileDataEntry("data/xml/gameobjectfiles.xml")); MegFileBuilder builder = new MegFileBuilder(m_fileSystem); MegFile megFile = builder.FromHolder(megFileHolder); Assert.IsNotNull(megFile); Assert.IsNotNull(megFile.Header); Assert.IsNotNull(megFile.FileContentTable); Assert.IsNotNull(megFile.FileNameTable); Assert.AreEqual(2u, megFile.Header.NumFiles); Assert.AreEqual(2u, megFile.Header.NumFileNames); Assert.AreEqual(40, megFile.FileContentTable.Size); Assert.AreEqual(58, megFile.FileNameTable.Size); Assert.IsTrue(megFile.FileNameTable.MegFileNameTableRecords[0].FileName.Equals("data/xml/gameobjectfiles.xml", StringComparison.InvariantCultureIgnoreCase)); Assert.IsTrue(megFile.FileNameTable.MegFileNameTableRecords[1].FileName.Equals("data/xml/campaignfiles.xml", StringComparison.InvariantCultureIgnoreCase)); }
public void FromHolder_Test__FileHeaderIsBinaryEquivalent() { MegFileHolder megFileHolder = new MegFileHolder(TestConstants.BASE_PATH, "FromHolder_Test__FileHeaderIsBinaryEquivalent"); megFileHolder.Content.Add(new MegFileDataEntry("data/xml/campaignfiles.xml", TestConstants.FILE_PATH_CAMPAIGNFILES)); megFileHolder.Content.Add(new MegFileDataEntry("data/xml/gameobjectfiles.xml", TestConstants.FILE_PATH_GAMEOBJECTFILES)); MegFileBuilder builder = new MegFileBuilder(m_fileSystem); MegFile megFile = builder.FromHolder(megFileHolder); Assert.IsNotNull(megFile); m_fileSystem.File.WriteAllBytes( m_fileSystem.Path.Combine(TestConstants.BASE_PATH, megFileHolder.FullyQualifiedName), megFile.ToBytes()); byte[] readMegFile = m_fileSystem.File.ReadAllBytes(m_fileSystem.Path.Combine(TestConstants.BASE_PATH, megFileHolder.FullyQualifiedName)); Assert.AreEqual(TestConstants.CONTENT_MEG_FILE_HEADER.Length, readMegFile.Length); for (int i = 0; i < TestConstants.CONTENT_MEG_FILE_HEADER.Length; i++) { Assert.AreEqual(TestConstants.CONTENT_MEG_FILE_HEADER[i], readMegFile[i]); } }
private static void UnpackFile(string targetDirectory, MegFileContentTableRecord megFileContentTableRecord, MegFile megFile, BinaryReader reader) { byte[] file = new byte[megFileContentTableRecord.FileSizeInBytes]; string fileName = megFile.FileNameTable.MegFileNameTableRecords[Convert.ToInt32(megFileContentTableRecord.FileNameTableRecordIndex)].FileName; reader.BaseStream.Seek(Convert.ToInt32(megFileContentTableRecord.FileStartOffsetInBytes), SeekOrigin.Begin); reader.Read(file, 0, file.Length); string path = Path.Combine(targetDirectory, fileName); PathUtility.CreatePath(Path.GetDirectoryName(path)); using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Create))) { writer.Write(file); } }