/// <summary> /// Returns the first found entries path hash containing the given filename. /// </summary> public static uint GetPathHash(string filename) { FilenameDatabaseEntry entry = GetEntry(filename); if (entry == null) { return(0); } return(entry.HashPath); }
/// <summary> /// Returns the first found entries filename matching the given hashes. /// </summary> public static string GetFilename(uint hash, uint pathHash = 0) { FilenameDatabaseEntry entry = GetEntry(hash, pathHash); if (entry == null) { return(""); } return(entry.Path); }
/// <summary> /// Initializes the filename database from the cached GZip compressed json dump from the resources. /// Will be called once automatically when not initializing the database manually. /// </summary> public static void Initialize() { if (m_initialized) { return; } string json = ""; //Decompress cached GZip compressed json dump from resources. using (MemoryStream stream = new MemoryStream(Resources.FilenameDatabase)) { using (GZipStream streamGZip = new GZipStream(stream, CompressionMode.Decompress)) { using (StreamReader reader = new StreamReader(streamGZip)) { json = reader.ReadToEnd(); } } } //Read json and populate filename database m_entries.Clear(); JSONNode rootNode = JSON.Parse(json); foreach (JSONNode node in rootNode.AsArray) { FilenameDatabaseEntry newEntry = new FilenameDatabaseEntry(); foreach (KeyValuePair <string, JSONNode> entry in node.Linq) { if (entry.Key == "Hash") { newEntry.Hash = (uint)entry.Value.AsLong; } if (entry.Key == "HashPath") { newEntry.HashPath = (uint)entry.Value.AsLong; } if (entry.Key == "Path") { newEntry.Path = entry.Value.Value; } } m_entries.Add(newEntry); } m_initialized = true; Console.WriteLine("Filename database initialized: {0} entries.", m_entries.Count); }