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); }
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); }
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);
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); }
public static async Task <Dictionary <uint, string> > GetFilesByBuild(string buildConfig) { var config = await Config.GetBuildConfig(buildConfig); var rootHash = ""; using (var connection = new MySqlConnection(SettingsManager.connectionString)) { await connection.OpenAsync(); using var cmd = connection.CreateCommand(); cmd.CommandText = "SELECT root_cdn FROM wow_buildconfig WHERE hash = @hash"; cmd.Parameters.AddWithValue("@hash", buildConfig); using var reader = await cmd.ExecuteReaderAsync(); while (await reader.ReadAsync()) { rootHash = reader["root_cdn"].ToString(); } } if (NGDP.encodingDictionary.TryGetValue(config.root, out var rootEntry)) { rootHash = rootEntry.ToHexString().ToLower(); } if (rootHash == "") { EncodingFile encoding; if (config.encodingSize == null || config.encodingSize.Count() < 2) { encoding = await NGDP.GetEncoding(config.encoding[1].ToHexString(), 0); } else { encoding = await NGDP.GetEncoding(config.encoding[1].ToHexString(), int.Parse(config.encodingSize[1])); } if (encoding.aEntries.TryGetValue(config.root, out var bakRootEntry)) { rootHash = bakRootEntry.eKey.ToHexString().ToLower(); } else { throw new KeyNotFoundException("Root encoding key not found!"); } } return(await GetFilesByRoot(rootHash)); }
public static Dictionary <uint, string> GetFilesByBuild(string buildConfig) { var config = Config.GetBuildConfig("http://cdn.blizzard.com/tpr/wow/", buildConfig); var rootHash = ""; using (var connection = new MySqlConnection(SettingsManager.connectionString)) { connection.Open(); using (var cmd = connection.CreateCommand()) { cmd.CommandText = "SELECT root_cdn FROM wow_buildconfig WHERE hash = @hash"; cmd.Parameters.AddWithValue("@hash", buildConfig); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { rootHash = reader["root_cdn"].ToString(); } } } } if (rootHash == "") { EncodingFile encoding; if (config.encodingSize == null || config.encodingSize.Count() < 2) { encoding = NGDP.GetEncoding("http://cdn.blizzard.com/tpr/wow/", config.encoding[1].ToHexString(), 0); } else { encoding = NGDP.GetEncoding("http://cdn.blizzard.com/tpr/wow/", config.encoding[1].ToHexString(), int.Parse(config.encodingSize[1])); } if (encoding.aEntries.TryGetValue(config.root, out var rootEntry)) { rootHash = rootEntry.eKey.ToHexString().ToLower(); } else { throw new KeyNotFoundException("Root encoding key not found!"); } } return(GetFilesByRoot(rootHash)); }
public async Task <ActionResult> Diff(string from, string to) { var installFrom = await NGDP.GetInstall(from, true); var installTo = await NGDP.GetInstall(to, true); var installFromDict = new Dictionary <string, InstallFileEntry>(); foreach (var entry in installFrom.entries) { installFromDict.Add(entry.name, entry); } var installToDict = new Dictionary <string, InstallFileEntry>(); foreach (var entry in installTo.entries) { installToDict.Add(entry.name, entry); } var fromEntries = installFromDict.Keys.ToHashSet(); var toEntries = installToDict.Keys.ToHashSet(); var commonEntries = fromEntries.Intersect(toEntries); var removedEntries = fromEntries.Except(commonEntries); var addedEntries = toEntries.Except(commonEntries); var modifiedFiles = new List <InstallFileEntry>(); foreach (var entry in commonEntries) { var originalFile = installFromDict[entry]; var patchedFile = installToDict[entry]; if (originalFile.contentHash.Equals(patchedFile.contentHash)) { continue; } modifiedFiles.Add(patchedFile); } return(Json(new { added = addedEntries, modified = modifiedFiles, removed = removedEntries })); }
public async Task <ActionResult> DumpByHash(string hash) { var install = await NGDP.GetInstall(hash, true); return(Json(install.entries)); }
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())); }
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); }