/* * Query if given packed file can be deccoded. * 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.Instance.IsSupported(key)) { try { DBFileHeader header = PackedFileDbCodec.readHeader(packedFile); int maxVersion = DBTypeMap.Instance.MaxVersion(key); if (maxVersion != 0 && header.Version > maxVersion) { display = string.Format("{0}: needs {1}, has {2}", key, header.Version, DBTypeMap.Instance.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); }
/* * Create DBFile from the given PackedFile. */ public static DBFile Decode(PackedFile file) { PackedFileDbCodec codec = FromFilename(file.FullPath); return(codec.Decode(file.Data)); }