Пример #1
0
        public static Dictionary <uint, string> GetFilesByRoot(string rootHash)
        {
            var root = NGDP.GetRoot("http://cdn.blizzard.com/tpr/wow/", rootHash, true);

            var fileList = new Dictionary <uint, string>();

            using (var connection = new MySqlConnection(SettingsManager.connectionString))
            {
                connection.Open();
                using (var cmd = connection.CreateCommand())
                {
                    cmd.CommandText = "SELECT id, filename from wow_rootfiles WHERE filename IS NOT NULL ORDER BY id DESC";
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            fileList.Add(uint.Parse(reader["id"].ToString()), reader["filename"].ToString());
                        }
                    }
                }
            }

            var returnNames = new Dictionary <uint, string>();

            foreach (var entry in root.entriesFDID)
            {
                if (fileList.TryGetValue(entry.Key, out string filename))
                {
                    returnNames.Add(entry.Key, filename);
                }
            }
            return(returnNames);
        }
Пример #2
0
        public static async Task <Dictionary <uint, string> > GetFilesByRoot(string rootHash)
        {
            var root = await NGDP.GetRoot(rootHash, true);

            var fileList = new Dictionary <uint, string>();

            using (var connection = new MySqlConnection(SettingsManager.connectionString))
            {
                await connection.OpenAsync();

                using var cmd    = connection.CreateCommand();
                cmd.CommandText  = "SELECT id, filename from wow_rootfiles WHERE filename IS NOT NULL ORDER BY id DESC";
                using var reader = await cmd.ExecuteReaderAsync();

                while (await reader.ReadAsync())
                {
                    fileList.Add(uint.Parse(reader["id"].ToString()), reader["filename"].ToString());
                }
            }

            var returnNames = new Dictionary <uint, string>();

            foreach (var entry in root.entriesFDID)
            {
                if (fileList.TryGetValue(entry.Key, out string filename))
                {
                    returnNames.Add(entry.Key, filename);
                }
            }
            return(returnNames);
        }
Пример #3
0
        public async Task <ActionResult> DiffApi(string from, string to, int start = 0)
        {
            Logger.WriteLine("Serving root diff for root " + from + " => " + to);

            if (BuildDiffCache.Get(from, to, out ApiDiff diff))
            {
                Logger.WriteLine("Serving cached diff for root " + from + " => " + to);

                return(Json(new
                {
                    added = diff.added.Count(),
                    modified = diff.modified.Count(),
                    removed = diff.removed.Count(),
                    data = diff.all.ToArray()
                }));
            }

            var filedataids = await Database.GetAllFiles();

            var rootFrom = await NGDP.GetRoot(from, true);

            var rootTo = await NGDP.GetRoot(to, true);

            var rootFromEntries = rootFrom.entriesFDID;
            var rootToEntries   = rootTo.entriesFDID;

            var fromEntries = rootFromEntries.Keys.ToHashSet();
            var toEntries   = rootToEntries.Keys.ToHashSet();

            var commonEntries  = fromEntries.Intersect(toEntries);
            var removedEntries = fromEntries.Except(commonEntries);
            var addedEntries   = toEntries.Except(commonEntries);
Пример #4
0
        public async Task <int> Get(string rootcdn)
        {
            Logger.WriteLine("Serving filedataid count for root_cdn " + rootcdn);
            var root = await NGDP.GetRoot(rootcdn, true);

            return(root.entriesFDID.Count);
        }
Пример #5
0
        public string Diff(string from, string to)
        {
            Logger.WriteLine("Serving root diff for root " + from + " => " + to);
            var result = new List <string>();
            var csv    = false;

            if (Request.Query.ContainsKey("csv"))
            {
                csv = true;
                result.Add("Action;Name;FileDataID");
            }

            var filedataids = Database.GetKnownFiles(true);

            var rootFrom = NGDP.GetRoot(Path.Combine(CDN.cacheDir, "tpr", "wow"), from, true);
            var rootTo   = NGDP.GetRoot(Path.Combine(CDN.cacheDir, "tpr", "wow"), to, true);

            var rootFromEntries = rootFrom.entriesFDID;
            var rootToEntries   = rootTo.entriesFDID;

            var fromEntries = rootFromEntries.Keys.ToHashSet();
            var toEntries   = rootToEntries.Keys.ToHashSet();

            var commonEntries  = fromEntries.Intersect(toEntries);
            var removedEntries = fromEntries.Except(commonEntries);
            var addedEntries   = toEntries.Except(commonEntries);

            Action <RootEntry, string> print = delegate(RootEntry entry, string action)
            {
                var md5 = entry.md5.ToHexString().ToLower();

                var fileName = filedataids.ContainsKey(entry.fileDataID) ? filedataids[entry.fileDataID] : "Unknown File: " + entry.fileDataID;

                if (csv)
                {
                    result.Add(string.Format("{0};{1};{2}", action, fileName, entry.fileDataID));
                }
                else
                {
                    if (entry.lookup == 0)
                    {
                        result.Add(string.Format("[{0}] <b>{1}</b> (content md5: {2}, FileData ID: {3})", action, fileName, md5, entry.fileDataID));
                    }
                    else
                    {
                        var lookup = entry.lookup.ToString("x").PadLeft(16, '0');
                        result.Add(string.Format("[{0}] <b>{1}</b> (lookup: {2}, content md5: {3}, FileData ID: {4})", action, fileName, lookup, md5, entry.fileDataID));
                    }
                }
            };

            foreach (var id in addedEntries)
            {
                var       toEntry = rootToEntries[id];
                RootEntry?toPrio  = toEntry.FirstOrDefault(subentry =>
                                                           subentry.contentFlags.HasFlag(ContentFlags.LowViolence) == false && (subentry.localeFlags.HasFlag(LocaleFlags.All_WoW) || subentry.localeFlags.HasFlag(LocaleFlags.enUS))
                                                           );

                var addedEntry = (toPrio.Value.fileDataID != 0) ? toPrio.Value : toEntry.First();
                print(addedEntry, "ADDED");
            }

            foreach (var id in removedEntries)
            {
                var       fromEntry = rootFromEntries[id];
                RootEntry?fromPrio  = fromEntry.FirstOrDefault(subentry =>
                                                               subentry.contentFlags.HasFlag(ContentFlags.LowViolence) == false && (subentry.localeFlags.HasFlag(LocaleFlags.All_WoW) || subentry.localeFlags.HasFlag(LocaleFlags.enUS))
                                                               );
                var removedEntry = (fromPrio.Value.fileDataID != 0) ? fromPrio.Value : fromEntry.First();

                print(removedEntry, "REMOVED");
            }

            foreach (var id in commonEntries)
            {
                var fromEntry = rootFromEntries[id];
                var toEntry   = rootToEntries[id];

                RootEntry?fromPrio = fromEntry.FirstOrDefault(subentry =>
                                                              subentry.contentFlags.HasFlag(ContentFlags.LowViolence) == false && (subentry.localeFlags.HasFlag(LocaleFlags.All_WoW) || subentry.localeFlags.HasFlag(LocaleFlags.enUS))
                                                              );

                var originalFile = (fromPrio.Value.fileDataID != 0) ? fromPrio.Value : fromEntry.First();

                RootEntry?toPrio = toEntry.FirstOrDefault(subentry =>
                                                          subentry.contentFlags.HasFlag(ContentFlags.LowViolence) == false && (subentry.localeFlags.HasFlag(LocaleFlags.All_WoW) || subentry.localeFlags.HasFlag(LocaleFlags.enUS))
                                                          );

                var patchedFile = (toPrio.Value.fileDataID != 0) ? toPrio.Value : toEntry.First();


                if (originalFile.md5.Equals(patchedFile.md5))
                {
                    continue;
                }

                print(patchedFile, "MODIFIED");
            }

            result.Sort();
            return(string.Join('\n', result.ToArray()));
        }
Пример #6
0
 public int Get(string rootcdn)
 {
     Logger.WriteLine("Serving filedataid count for root_cdn " + rootcdn);
     return(NGDP.GetRoot(Path.Combine(SettingsManager.cacheDir, "tpr", "wow"), rootcdn, true).entriesFDID.Count);
 }