public void Save(string path, HFile hFile) { this.saveHeader(path, hFile.Header); this.saveFileType(path, hFile.FileTypes); this.saveFileList(path, hFile.Files); this.saveFooterData(path, hFile.FooterData); }
private static void unpack(string src, string dst, bool verbose) { HFile hfile = new HFile(); hfile.Load(src); if ((int)hfile.Header.Version[0] == 5) { Console.WriteLine("Game: Stacking"); } else if ((int)hfile.Header.Version[0] == 2) { Console.WriteLine("Game: Costume Quest"); } else { Program.error("Unknown version number. This file is not supported."); return; } Console.WriteLine(string.Format("File count: {0}", (object)hfile.Header.FileCount)); new PFile(hfile).Unpack(src, dst); new HFileInfo().Save(dst, hfile); }
public HFileInfo() { this.hFile = new HFile(); }
public void Pack(string path, string unpackPath, HFile hFile) { using (FileStream fileStream1 = new FileStream(path + ".~p", FileMode.Create)) { ConsoleProgressBar consoleProgressBar = new ConsoleProgressBar(hFile.Header.FileCount); try { consoleProgressBar.Start(); for (int index = 0; index < hFile.Files.Length; ++index) { consoleProgressBar.PerformStep(); using (MemoryStream memoryStream = new MemoryStream()) { string path1 = unpackPath + "\\" + hFile.Files[index].GetFilePath(); if (File.Exists(path1 + ".header")) { using (FileStream fileStream2 = new FileStream(path1 + ".header", FileMode.Open)) this.CopyStream((Stream)fileStream2, (Stream)memoryStream); } using (FileStream fileStream2 = new FileStream(path1, FileMode.Open)) { hFile.Files[index].ContentSize = (int)fileStream2.Length; if (hFile.Files[index].FileType.HasSizeHeader) { memoryStream.Write(BitConverter.GetBytes(hFile.Files[index].ContentSize), 0, 4); hFile.Files[index].ContentSize += 4; } this.CopyStream((Stream)fileStream2, (Stream)memoryStream); } memoryStream.Seek(0L, SeekOrigin.Begin); hFile.Files[index].Offset = fileStream1.Position; if (hFile.Files[index].IsCompressed()) { int num = this.compress((Stream)memoryStream, (Stream)fileStream1, 9); if (num < 0) { throw new Exception(); } hFile.Files[index].Size = num; } else { hFile.Files[index].Size = (int)memoryStream.Length; this.CopyStream((Stream)memoryStream, (Stream)fileStream1); } if ((int)hFile.Header.Version[1] == 1) { if (fileStream1.Length % 4L != 0L) { fileStream1.Write(new byte[4L - fileStream1.Length % 4L], 0, (int)(4L - fileStream1.Length % 4L)); } } else if (fileStream1.Length % 2048L != 0L) { int count = (int)(2048L * (fileStream1.Length / 2048L + 1L) - fileStream1.Length); fileStream1.Write(new byte[count], 0, count); } } } hFile.Header.DataFooterOffset = (ulong)fileStream1.Position; int num1 = (int)ushort.MaxValue - (int)(fileStream1.Length & (long)ushort.MaxValue); for (int index = 0; index <= num1; ++index) { fileStream1.WriteByte((byte)122); } } finally { consoleProgressBar.End(); } } }
public PFile(HFile header) { this.header = header; }
protected static byte[] convIntAs3Bytes(long l) { return(HFile.convIntAs3Bytes((int)l)); }