using System; using System.Data; using System.Collections.Generic; using Woodpecker.Core; using Woodpecker.Storage; namespace Woodpecker.Game.Externals { /// /// Provides management and caching for external texts. /// public class externalManager { #region Fields /// /// A Dictionary (string, string) collection holding the external texts. /// private Dictionary Texts; #endregion #region Methods /// /// Wipes the current collection of external texts and re-loads them from the database. /// public void loadEntries() { if (this.Texts != null) this.Texts.Clear(); // Wipe old entries this.Texts = new Dictionary(); Logging.Log("Loading external_texts entries..."); Database dbClient = new Database(true, true); if (!dbClient.Ready) { Logging.Log("Failed to initialize external_texts! Database was not contactable!", Logging.logType.commonError); return; } foreach (DataRow dEntry in dbClient.getTable("SELECT * FROM external_texts").Rows) { string extKey = (string)dEntry["extkey"]; string extValue = (string)dEntry["extvalue"]; this.Texts.Add(extKey, extValue); } Logging.Log("Loaded " + this.Texts.Count + " external_texts entries."); } /// /// Returns a text entry for a given key. If the given key is not found in the collection, the key is returned. /// /// The key to retrieve the value of. public string getTextEntry(string Key) { if (this.Texts != null && this.Texts.ContainsKey(Key)) return this.Texts[Key]; else return Key; } #endregion } }