Example #1
0
            Dictionary <string, PackageEntry> ParseIndex(Dictionary <uint, PackageEntry> entries, HashSet <string> allPossibleFilenames)
            {
                var classicIndex = new Dictionary <string, PackageEntry>();
                var crcIndex     = new Dictionary <string, PackageEntry>();

                // Try and find a local mix database
                var dbNameClassic = PackageEntry.HashFilename("local mix database.dat", PackageHashType.Classic);
                var dbNameCRC     = PackageEntry.HashFilename("local mix database.dat", PackageHashType.CRC32);

                foreach (var kv in entries)
                {
                    if (kv.Key == dbNameClassic || kv.Key == dbNameCRC)
                    {
                        using (var content = GetContent(kv.Value))
                        {
                            var db = new XccLocalDatabase(content);
                            foreach (var e in db.Entries)
                            {
                                allPossibleFilenames.Add(e);
                            }
                        }

                        break;
                    }
                }

                foreach (var filename in allPossibleFilenames)
                {
                    var          classicHash = PackageEntry.HashFilename(filename, PackageHashType.Classic);
                    var          crcHash     = PackageEntry.HashFilename(filename, PackageHashType.CRC32);
                    PackageEntry e;

                    if (entries.TryGetValue(classicHash, out e))
                    {
                        classicIndex.Add(filename, e);
                    }

                    if (entries.TryGetValue(crcHash, out e))
                    {
                        crcIndex.Add(filename, e);
                    }
                }

                var bestIndex = crcIndex.Count > classicIndex.Count ? crcIndex : classicIndex;

                var unknown = entries.Count - bestIndex.Count;

                if (unknown > 0)
                {
                    Log.Write("debug", "{0}: failed to resolve filenames for {1} unknown hashes".F(Name, unknown));
                }

                return(bestIndex);
            }
Example #2
0
            Dictionary <string, PackageEntry> ParseIndex(Dictionary <uint, PackageEntry> entries, string[] globalFilenames)
            {
                var classicIndex = new Dictionary <string, PackageEntry>();
                var crcIndex     = new Dictionary <string, PackageEntry>();
                IEnumerable <string> allPossibleFilenames = globalFilenames;

                // Try and find a local mix database
                var dbNameClassic = PackageEntry.HashFilename("local mix database.dat", PackageHashType.Classic);
                var dbNameCRC     = PackageEntry.HashFilename("local mix database.dat", PackageHashType.CRC32);

                foreach (var kv in entries)
                {
                    if (kv.Key == dbNameClassic || kv.Key == dbNameCRC)
                    {
                        using (var content = GetContent(kv.Value))
                        {
                            var db = new XccLocalDatabase(content);
                            allPossibleFilenames = allPossibleFilenames.Concat(db.Entries);
                        }

                        break;
                    }
                }

                foreach (var filename in allPossibleFilenames.Distinct())
                {
                    var classicHash = PackageEntry.HashFilename(filename, PackageHashType.Classic);
                    var crcHash     = PackageEntry.HashFilename(filename, PackageHashType.CRC32);

                    if (entries.TryGetValue(classicHash, out var e))
                    {
                        classicIndex.Add(filename, e);
                    }

                    if (entries.TryGetValue(crcHash, out e))
                    {
                        crcIndex.Add(filename, e);
                    }
                }

                var bestIndex = crcIndex.Count > classicIndex.Count ? crcIndex : classicIndex;

                var unknown = entries.Count - bestIndex.Count;

                if (unknown > 0)
                {
                    Log.Write("debug", $"{Name}: failed to resolve filenames for {unknown} unknown hashes");
                }

                return(bestIndex);
            }
Example #3
0
 public Stream GetContent(PackageEntry entry)
 {
     return(SegmentStream.CreateWithoutOwningStream(s, dataStart + entry.Offset, (int)entry.Length));
 }