/* * Notify single pack file having been loaded. */ private void OnPackedFileLoaded(PackedFile packed) { if (this.PackedFileLoaded != null) { this.PackedFileLoaded(packed); } }
/* * Decode pack file at the given path. */ public PackFile Open(string packFullPath) { PackFile file; long sizes = 0; using (var reader = new BinaryReader(new FileStream(packFullPath, FileMode.Open), Encoding.ASCII)) { PFHeader header = ReadHeader(reader); file = new PackFile(packFullPath, header); OnHeaderLoaded(header); long offset = file.Header.DataStart; for (int i = 0; i < file.Header.FileCount; i++) { uint size = reader.ReadUInt32(); sizes += size; if (file.Header.HasAdditionalInfo) { header.AdditionalInfo = reader.ReadInt64(); } string packedFileName = IOFunctions.ReadZeroTerminatedAscii(reader); // this is easier because we can use the Path methods // under both Windows and Unix packedFileName = packedFileName.Replace('\\', Path.DirectorySeparatorChar); PackedFile packed = new PackedFile(file.Filepath, packedFileName, offset, size); file.Add(packed); offset += size; this.OnPackedFileLoaded(packed); } } this.OnFinishedLoading(file); file.IsModified = false; return(file); }
public static DBFileHeader readHeader(PackedFile file) { using (MemoryStream stream = new MemoryStream(file.Data, (int)0, (int)file.Size)) { return(readHeader(stream)); } }
/* * Query if given packed file can be decoded. * Is not entirely reliable because it only reads the header and checks if a * type definition is available for the given GUID and/or type name and version. * The actual decode tries out all available type infos for that type name * but that is less efficient because it has to read the whole file at least once * if successful. */ public static bool CanDecode(PackedFile packedFile, out string display) { bool result = true; string key = DBFile.Typename(packedFile.FullPath); if (DBTypeMap.IsSupported(key)) { try { DBFileHeader header = PackedFileDbCodec.readHeader(packedFile); int maxVersion = DBTypeMap.MaxVersion(key); if (maxVersion != 0 && header.Version > maxVersion) { display = string.Format("{0}: needs {1}, has {2}", key, header.Version, DBTypeMap.MaxVersion(key)); result = false; } else { display = string.Format("Version: {0}", header.Version); } } catch (Exception x) { display = string.Format("{0}: {1}", key, x.Message); } } else { display = string.Format("{0}: no definition available", key); result = false; } return(result); }
private static DataTable GetDataTable(String tableKey) { PackedFile currentPackedFile = currentPackFile.Files[0]; PackedFile replacementPackedFile = currentPackedFile; DBFile test = PackedFileDbCodec.Decode(currentPackedFile); test.Entries[0][0].Value = "dicks and or butts"; Encode(new MemoryStream(replacementPackedFile.Data), test); //currentPackFile.Files[0] = currentPackedFile; //currentPackFile.Files[0] = null; currentPackFile.Files.Remove(currentPackedFile); currentPackFile.Files.Add(replacementPackedFile); return(new DataTable()); }
/* * Create DBFile from the given PackedFile. */ public static DBFile Decode(PackedFile file) { PackedFileDbCodec codec = FromFilename(file.FullPath); return(codec.Decode(file.Data)); }
/* * Retrieve codec for the given PackedFile. */ public static PackedFileDbCodec GetCodec(PackedFile file) { return(new PackedFileDbCodec(DBFile.Typename(file.FullPath))); }