示例#1
0
        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)));
        }
示例#2
0
文件: MixFile.cs 项目: OpenRA/OpenRA
        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;
        }
示例#3
0
		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 (GlobalFileSystem.Exists("global mix database.dat"))
			{
				var db = new XccGlobalDatabase(GlobalFileSystem.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));
		}