/// <summary> /// Loads a pack archive from a file /// </summary> /// <param name="filename"></param> /// <returns></returns> public static PackArchive FromFile(string filename) { PackArchive file = new PackArchive(); file.Filename = filename; System.IO.FileStream PackFile = new System.IO.FileStream(filename, System.IO.FileMode.Open); Byte[] Buffer = null; //Read File Info Size Buffer = new Byte[4]; PackFile.Read(Buffer, 0, 4); Byte[] ByteInfoBytesSize = Buffer; //Fix original array size from size 4 while (ByteInfoBytesSize[0] == 0) { Byte[] temp = ByteInfoBytesSize; ByteInfoBytesSize = new Byte[ByteInfoBytesSize.Length - 1]; for (int i = 0; i <= ByteInfoBytesSize.Length - 1; i++) { ByteInfoBytesSize[i] = temp[i + 1]; } } int InfoSize = int.Parse(System.Text.Encoding.Default.GetString(ByteInfoBytesSize)); //Read File Info Buffer = new Byte[InfoSize]; PackFile.Read(Buffer, 0, InfoSize); String FileInfo = System.Text.Encoding.Default.GetString(Buffer); String[] Files = FileInfo.Split('|'); foreach (String File in Files) { PackEntry pe = new PackEntry(); String FileName = File.Split(';')[0]; int FileByteSize = int.Parse(File.Split(';')[1]); Buffer = new Byte[FileByteSize]; PackFile.Read(Buffer, 0, FileByteSize); pe.Filename = FileName; pe.Data = Buffer; file.Entries.Add(pe); } PackFile.Close(); return(file); }
/// <summary> /// Loads a pack archive from a file /// </summary> /// <param name="filename"></param> /// <returns></returns> public static PackArchive FromFile(string filename) { PackArchive file = new PackArchive(); file.Filename = filename; System.IO.FileStream PackFile = new System.IO.FileStream(filename, System.IO.FileMode.Open); Byte[] Buffer = null; //Read File Info Size Buffer = new Byte[4]; PackFile.Read(Buffer, 0, 4); Byte[] ByteInfoBytesSize = Buffer; //Fix original array size from size 4 while (ByteInfoBytesSize[0] == 0) { Byte[] temp = ByteInfoBytesSize; ByteInfoBytesSize = new Byte[ByteInfoBytesSize.Length - 1]; for (int i = 0; i <= ByteInfoBytesSize.Length - 1; i++) { ByteInfoBytesSize[i] = temp[i + 1]; } } int InfoSize = int.Parse(System.Text.Encoding.Default.GetString(ByteInfoBytesSize)); //Read File Info Buffer = new Byte[InfoSize]; PackFile.Read(Buffer, 0, InfoSize); String FileInfo = System.Text.Encoding.Default.GetString(Buffer); String[] Files = FileInfo.Split('|'); foreach (String File in Files) { PackEntry pe = new PackEntry(); String FileName = File.Split(';')[0]; int FileByteSize = int.Parse(File.Split(';')[1]); Buffer = new Byte[FileByteSize]; PackFile.Read(Buffer, 0, FileByteSize); pe.Filename = FileName; pe.Data = Buffer; file.Entries.Add(pe); } PackFile.Close(); return file; }