/// <summary> /// Create a file pack, join all the files from PackFileInfoCollection into a single file /// </summary> public static bool Pack(PackFileInfoCollection Collection, string PackDestination) { String FileInfo = Collection.CreateFileInfo(); Byte[] InfoBytes = System.Text.Encoding.Default.GetBytes(FileInfo); int InfoBytesSize = InfoBytes.Length; Byte[] ByteInfoBytesSize = System.Text.Encoding.Default.GetBytes(InfoBytesSize.ToString()); Console.WriteLine("Packing package file " + PackDestination); //Fix Array Size to 4 if (ByteInfoBytesSize.Length < 4) { int d = 4 - ByteInfoBytesSize.Length; Byte[] temp = ByteInfoBytesSize; ByteInfoBytesSize = new Byte[4]; for (int i = 3; i >= 0; i += -1) { if (i - d >= 0) { ByteInfoBytesSize[i] = temp[i - d]; } else { ByteInfoBytesSize[i] = 0; } } } if (System.IO.File.Exists(PackDestination)) { System.IO.File.Delete(PackDestination); } System.IO.FileStream packFile = new System.IO.FileStream(PackDestination, System.IO.FileMode.CreateNew); //Write InfoByteSize as Bytes[] packFile.Write(ByteInfoBytesSize, 0, 4); //Write Info as Bytes[] packFile.Write(InfoBytes, 0, InfoBytes.Length); //Write Files as Bytes[] foreach (string File in Collection.FileList) { Console.WriteLine("- Packing: " + System.IO.Path.GetFileName(File)); Byte[] FileBytes = System.IO.File.ReadAllBytes(File); packFile.Write(FileBytes, 0, FileBytes.Length); } packFile.Close(); return true; }
/// <summary> /// Create a file pack, join all the files from PackFileInfoCollection into a single file /// </summary> public static bool Pack(PackFileInfoCollection Collection, string PackDestination) { String FileInfo = Collection.CreateFileInfo(); Byte[] InfoBytes = System.Text.Encoding.Default.GetBytes(FileInfo); int InfoBytesSize = InfoBytes.Length; Byte[] ByteInfoBytesSize = System.Text.Encoding.Default.GetBytes(InfoBytesSize.ToString()); Console.WriteLine("Packing package file " + PackDestination); //Fix Array Size to 4 if (ByteInfoBytesSize.Length < 4) { int d = 4 - ByteInfoBytesSize.Length; Byte[] temp = ByteInfoBytesSize; ByteInfoBytesSize = new Byte[4]; for (int i = 3; i >= 0; i += -1) { if (i - d >= 0) { ByteInfoBytesSize[i] = temp[i - d]; } else { ByteInfoBytesSize[i] = 0; } } } if (System.IO.File.Exists(PackDestination)) { System.IO.File.Delete(PackDestination); } System.IO.FileStream packFile = new System.IO.FileStream(PackDestination, System.IO.FileMode.CreateNew); //Write InfoByteSize as Bytes[] packFile.Write(ByteInfoBytesSize, 0, 4); //Write Info as Bytes[] packFile.Write(InfoBytes, 0, InfoBytes.Length); //Write Files as Bytes[] foreach (string File in Collection.FileList) { Console.WriteLine("- Packing: " + System.IO.Path.GetFileName(File)); Byte[] FileBytes = System.IO.File.ReadAllBytes(File); packFile.Write(FileBytes, 0, FileBytes.Length); } packFile.Close(); return(true); }