public IEnumerable <uint> ClassicHashes() { foreach (var filename in Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly)) { yield return(PackageEntry.HashFilename(Path.GetFileName(filename), PackageHashType.Classic)); } }
public IEnumerable <uint> ClassicHashes() { foreach (ZipEntry entry in pkg) { yield return(PackageEntry.HashFilename(entry.Name, PackageHashType.Classic)); } }
public IEnumerable <uint> ClassicHashes() { foreach (var filename in index.Keys) { yield return(PackageEntry.HashFilename(filename, PackageHashType.Classic)); } }
public D2kSoundResources(string filename, int priority) { this.filename = filename; this.priority = priority; s = FileSystem.Open(filename); s.Seek(0, SeekOrigin.Begin); filenames = new List <string>(); var headerLength = s.ReadUInt32(); while (s.Position < headerLength + 4) { var name = s.ReadASCIIZ(); var offset = s.ReadUInt32(); var length = s.ReadUInt32(); var hash = PackageEntry.HashFilename(name, PackageHashType.Classic); if (!index.ContainsKey(hash)) { index.Add(hash, new PackageEntry(hash, offset, length)); } filenames.Add(name); } }
public IEnumerable <string> AllFileNames() { var lookup = new Dictionary <uint, string>(); if (Exists("local mix database.dat")) { var db = new XccLocalDatabase(GetContent("local mix database.dat")); foreach (var e in db.Entries) { var hash = PackageEntry.HashFilename(e, type); if (!lookup.ContainsKey(hash)) { lookup.Add(hash, e); } } } if (FileSystem.Exists("global mix database.dat")) { var db = new XccGlobalDatabase(FileSystem.Open("global mix database.dat")); foreach (var e in db.Entries) { var hash = PackageEntry.HashFilename(e, type); if (!lookup.ContainsKey(hash)) { lookup.Add(hash, e); } } } return(index.Keys.Select(k => lookup.ContainsKey(k) ? lookup[k] : "{0:X}".F(k))); }
public IEnumerable <uint> AllFileHashes() { foreach (ZipEntry entry in pkg) { yield return(PackageEntry.HashFilename(entry.Name)); } }
static Stream GetFromCache(Cache <uint, List <IFolder> > index, string filename) { var folder = index[PackageEntry.HashFilename(filename)] .Where(x => x.Exists(filename)) .OrderBy(x => x.Priority) .FirstOrDefault(); if (folder != null) { return(folder.GetContent(filename)); } return(null); }
static Stream GetFromCache(PackageHashType type, string filename) { var index = type == PackageHashType.CRC32 ? crcHashIndex : classicHashIndex; var folder = index[PackageEntry.HashFilename(filename, type)] .Where(x => x.Exists(filename)) .OrderBy(x => x.Priority) .FirstOrDefault(); if (folder != null) { return(folder.GetContent(filename)); } return(null); }
public void Write(Dictionary <string, byte[]> contents) { // Cannot modify existing mixfile - rename existing file and // create a new one with original content plus modifications FileSystem.Unmount(this); // TODO: Add existing data to the contents list if (index.Count > 0) { throw new NotImplementedException("Updating mix files unfinished"); } // Construct a list of entries for the file header uint dataSize = 0; var items = new List <PackageEntry>(); foreach (var kv in contents) { uint length = (uint)kv.Value.Length; uint hash = PackageEntry.HashFilename(Path.GetFileName(kv.Key)); items.Add(new PackageEntry(hash, dataSize, length)); dataSize += length; } // Write the new file s.Seek(0, SeekOrigin.Begin); using (var writer = new BinaryWriter(s)) { // Write file header writer.Write((ushort)items.Count); writer.Write(dataSize); foreach (var item in items) { item.Write(writer); } writer.Flush(); // Copy file data foreach (var file in contents) { s.Write(file.Value); } } }
void ParseFile(BinaryReader reader) { reader.ReadBytes(7); var CompressedSize = reader.ReadUInt32(); reader.ReadBytes(12); var ChunkSize = reader.ReadUInt16(); reader.ReadBytes(4); var NameLength = reader.ReadByte(); var FileName = new String(reader.ReadChars(NameLength)); var hash = PackageEntry.HashFilename(FileName); index.Add(hash, new PackageEntry(hash, AccumulatedData, CompressedSize)); AccumulatedData += CompressedSize; // Skip to the end of the chunk reader.ReadBytes(ChunkSize - NameLength - 30); }
uint?FindMatchingHash(string filename) { var hash = PackageEntry.HashFilename(filename, type); if (index.ContainsKey(hash)) { return(hash); } // Maybe we were given a raw hash? uint raw; if (!uint.TryParse(filename, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out raw)) { return(null); } if ("{0:X}".F(raw) == filename && index.ContainsKey(raw)) { return(raw); } return(null); }
public bool Exists(string filename) { return(index.ContainsKey(PackageEntry.HashFilename(filename))); }
public Stream GetContent(string filename) { return(GetContent(PackageEntry.HashFilename(filename))); }
public Stream GetContent(string filename) { return(GetContent(PackageEntry.HashFilename(filename, PackageHashType.Classic))); }