public PCCObject(String path) { lzo = new SaltLZOHelper(); fullname = path; BitConverter.IsLittleEndian = true; DebugOutput.PrintLn("Load file : " + path); pccFileName = Path.GetFullPath(path); MemoryTributary tempStream = new MemoryTributary(); if (!File.Exists(pccFileName)) throw new FileNotFoundException("PCC file not found"); using (FileStream fs = new FileStream(pccFileName, FileMode.Open, FileAccess.Read)) { FileInfo tempInfo = new FileInfo(pccFileName); tempStream.WriteFromStream(fs, tempInfo.Length); if (tempStream.Length != tempInfo.Length) { throw new FileLoadException("File not fully read in. Try again later"); } } tempStream.Seek(12, SeekOrigin.Begin); int tempNameSize = tempStream.ReadValueS32(); tempStream.Seek(64 + tempNameSize, SeekOrigin.Begin); int tempGenerator = tempStream.ReadValueS32(); tempStream.Seek(36 + tempGenerator * 12, SeekOrigin.Current); int tempPos = (int)tempStream.Position + 4; tempStream.Seek(0, SeekOrigin.Begin); header = tempStream.ReadBytes(tempPos); tempStream.Seek(0, SeekOrigin.Begin); if (magic != ZBlock.magic && magic.Swap() != ZBlock.magic) { DebugOutput.PrintLn("Magic number incorrect: " + magic); throw new FormatException("This is not a pcc file. The magic number is incorrect."); } if (bCompressed) { DebugOutput.PrintLn("File is compressed"); listsStream = lzo.DecompressPCC(tempStream, this); //Correct the header bCompressed = false; listsStream.Seek(0, SeekOrigin.Begin); listsStream.WriteBytes(header); // Set numblocks to zero listsStream.WriteValueS32(0); //Write the magic number listsStream.WriteBytes(new byte[] { 0xF2, 0x56, 0x1B, 0x4E }); // Write 4 bytes of 0 listsStream.WriteValueS32(0); } else { DebugOutput.PrintLn("File already decompressed. Reading decompressed data."); //listsStream = tempStream; listsStream = new MemoryTributary(); tempStream.WriteTo(listsStream); } tempStream.Dispose(); ReadNames(listsStream); ReadImports(listsStream); ReadExports(listsStream); LoadExports(); }
public ME2PCCObject(String path) { lzo = new SaltLZOHelper(); fullname = path; BitConverter.IsLittleEndian = true; DebugOutput.PrintLn("Load file : " + path); pccFileName = Path.GetFullPath(path); MemoryTributary tempStream = new MemoryTributary(); if (!File.Exists(pccFileName)) throw new FileNotFoundException("PCC file not found"); using (FileStream fs = new FileStream(pccFileName, FileMode.Open, FileAccess.Read)) { FileInfo tempInfo = new FileInfo(pccFileName); tempStream.WriteFromStream(fs, tempInfo.Length); if (tempStream.Length != tempInfo.Length) { throw new FileLoadException("File not fully read in. Try again later"); } } LoadHelper(tempStream); }
/// <summary> /// ME3PCCObject class constructor. It also load namelist, importlist and exportinfo (not exportdata) from pcc file /// </summary> /// <param name="pccFilePath">full path + file name of desired pcc file.</param> public ME3PCCObject(string filePath, bool TablesOnly = false) { pccFileName = Path.GetFullPath(filePath); BitConverter.IsLittleEndian = true; MemoryTributary tempStream = new MemoryTributary(); if (!File.Exists(pccFileName)) throw new FileNotFoundException("LET ME KNOW ABOUT THIS! filename: " + pccFileName); int trycout = 0; while (trycout < 50) { try { using (FileStream fs = new FileStream(pccFileName, FileMode.Open, FileAccess.Read)) { FileInfo tempInfo = new FileInfo(pccFileName); tempStream.WriteFromStream(fs, tempInfo.Length); if (tempStream.Length != tempInfo.Length) { throw new FileLoadException("File not fully read in. Try again later"); } } break; } catch (Exception e) { // KFreon: File inaccessible or someting Console.WriteLine(e.Message); DebugOutput.PrintLn("File inaccessible: " + filePath + ". Attempt: " + trycout); trycout++; System.Threading.Thread.Sleep(100); } } ME3PCCObjectHelper(tempStream, filePath, TablesOnly); }