Exists() public method

public Exists ( string filename ) : bool
filename string
return bool
Beispiel #1
0
        public IEnumerable <string> AllFileNames()
        {
            var lookup = new Dictionary <uint, string>();

            if (context.Exists("global mix database.dat"))
            {
                var db = new XccGlobalDatabase(context.Open("global mix database.dat"));
                foreach (var e in db.Entries)
                {
                    var hash = IdxEntry.HashFilename(e, PackageHashType.CRC32);
                    if (!lookup.ContainsKey(hash))
                    {
                        lookup.Add(hash, e);
                    }
                }
            }

            return(index.Keys.Select(k => lookup.ContainsKey(k) ? lookup[k] : "{0:X}".F(k)));
        }
Beispiel #2
0
        Dictionary <string, PackageEntry> ParseIndex(Dictionary <uint, PackageEntry> entries)
        {
            var classicIndex         = new Dictionary <string, PackageEntry>();
            var crcIndex             = new Dictionary <string, PackageEntry>();
            var allPossibleFilenames = new HashSet <string>();

            // 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)
                {
                    var db = new XccLocalDatabase(GetContent(kv.Value));
                    foreach (var e in db.Entries)
                    {
                        allPossibleFilenames.Add(e);
                    }

                    break;
                }
            }

            // Load the global mix database
            // TODO: This should be passed to the mix file ctor
            if (context.Exists("global mix database.dat"))
            {
                using (var db = new XccGlobalDatabase(context.Open("global mix database.dat")))
                {
                    foreach (var e in db.Entries)
                    {
                        allPossibleFilenames.Add(e);
                    }
                }
            }

            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);
        }