/// <summary> /// Loads the data from file. /// </summary> /// <param name="contentPath">The content path to load the data from.</param> void Load(ContentPaths contentPath) { _npcChatDialogs.Clear(); var filePath = GetFilePath(contentPath); if (!File.Exists(filePath)) { _npcChatDialogs.Trim(); return; } var reader = GenericValueReader.CreateFromFile(filePath, _rootNodeName); var items = reader.ReadManyNodes(_chatDialogsNodeName, CreateDialog); for (var i = 0; i < items.Length; i++) { if (items[i] != null) { _npcChatDialogs[i] = items[i]; } } _npcChatDialogs.Trim(); }
/// <summary> /// Initializes a new instance of the <see cref="Skeleton"/> class. /// </summary> /// <param name="skeletonName">Name of the skeleton.</param> /// <param name="contentPath">The <see cref="ContentPaths"/> to load from.</param> public Skeleton(string skeletonName, ContentPaths contentPath) { var filePath = GetFilePath(skeletonName, contentPath); var reader = GenericValueReader.CreateFromFile(filePath, _rootNodeName); Read(reader); }
/// <summary> /// Initializes a new instance of the <see cref="DbConnectionSettings"/> class. /// </summary> /// <param name="fileName">The name of the settings file.</param> /// <param name="forceDefaultSettings">If true, the settings file in the settings directory /// will be used if they exists. If they don't, they will be copied over from the default /// settings path. If false, the default settings will always be used, and will never be copied /// over to the settings directory, forcing the default settings to be used.</param> public DbConnectionSettings(string fileName, bool forceDefaultSettings) { string destSettingsFile; if (forceDefaultSettings) { destSettingsFile = Path.GetFullPath(fileName); _filePath = destSettingsFile; } else { // Copy over the default settings file to the destination settings file // This way, project developers don't end up constantly overwriting each other's database settings destSettingsFile = DefaultFilePath; _filePath = destSettingsFile; if (!File.Exists(destSettingsFile)) { if (log.IsInfoEnabled) { log.InfoFormat("Settings file for local server settings copied to `{0}`.", destSettingsFile); } var copyPath = Path.GetFullPath(fileName); File.Copy(copyPath, destSettingsFile); _filePath = copyPath; } } // Read the values var reader = GenericValueReader.CreateFromFile(destSettingsFile, _rootNodeName); ((IPersistable)this).ReadState(reader); }
public void XmlTest() { var filePath = Path.GetTempFileName(); try { using ( var writer = GenericValueWriter.Create(format: GenericValueIOFormat.Xml, filePath: filePath, rootNodeName: "Root")) { writer.Write("Test", "asdf"); } var reader = GenericValueReader.CreateFromFile(filePath, "Root"); var s = reader.ReadString("Test"); Assert.AreEqual("asdf", s); } finally { if (File.Exists(filePath)) { File.Delete(filePath); } } }
public static void Load(ContentPaths contentPath, IContentManager cm) { if (IsLoaded) { return; } _isLoaded = true; var path = GetGrhDataFilePath(contentPath); if (cm == null) { throw new ArgumentNullException("cm"); } if (!File.Exists(path)) { throw new FileNotFoundException("GrhData data file not found.", path); } _isLoading = true; try { // Create the GrhData DArray if (_grhDatas == null) { _grhDatas = new DArray <GrhData>(256); } else { _grhDatas.Clear(); } _catDic.Clear(); _grhDatas.ItemAdded -= AddHandler; _grhDatas.ItemAdded += AddHandler; _grhDatas.ItemRemoved -= RemoveHandler; _grhDatas.ItemRemoved += RemoveHandler; // Read and add the GrhDatas in order by their type var reader = GenericValueReader.CreateFromFile(path, _rootNodeName); LoadGrhDatas(reader, _nonAnimatedGrhDatasNodeName, x => StationaryGrhData.Read(x, cm)); LoadGrhDatas(reader, _animatedGrhDatasNodeName, AnimatedGrhData.Read); LoadGrhDatas(reader, _autoAnimatedGrhDatasNodeName, x => AutomaticAnimatedGrhData.Read(x, cm)); // Trim down the GrhData array, mainly for the client since it will never add/remove any GrhDatas // while in the Client, and the Client is what counts, baby! _grhDatas.Trim(); } finally { _isLoading = false; } }
/// <summary> /// Loads audio values from file. /// </summary> /// <param name="fileName">The name of the file to load from.</param> /// <param name="rootNode">The name of the root node.</param> /// <returns>The loaded values.</returns> internal static IEnumerable <KeyValuePair <string, int> > LoadValues(string fileName, string rootNode) { var r = GenericValueReader.CreateFromFile(ContentPaths.Build.Data.Join(fileName + EngineSettings.DataFileSuffix), rootNode); var ret = r.ReadManyNodes("Items", ReadValue); return(ret); }
/// <summary> /// Loads the <see cref="SkillInfoManager"/> from file. /// </summary> /// <param name="filePath">The file path to load from.</param> public static SkillInfoManager Load(string filePath) { var r = GenericValueReader.CreateFromFile(filePath, _rootNodeName); var ret = new SkillInfoManager(); ret.Read(r); return(ret); }
/// <summary> /// Loads the <see cref="ParticleEffectManager"/> from file. /// </summary> /// <param name="contentPath">The <see cref="ContentPaths"/> to load from.</param> void Load(ContentPaths contentPath) { _effects.Clear(); var filePath = GetFilePath(contentPath); var reader = GenericValueReader.CreateFromFile(filePath, _rootNodeName); var readEffects = reader.ReadManyNodes(_particleEffectsNodeName, r => new ParticleEffect(r)); // Ensure the ParticleEffects were properly loaded into here Debug.Assert(readEffects.All(x => _effects[x.Name] == x)); }
/// <summary> /// Loads the cache from file. /// </summary> void Load() { lock (_cacheSync) { _cache.Clear(); if (!File.Exists(CacheDataFilePath)) { return; } var r = GenericValueReader.CreateFromFile(CacheDataFilePath, _rootNodeName); var items = r.ReadManyNodes(_cacheItemNodeName, x => new CacheItem(x)); foreach (var item in items) { _cache.Add(item.Hash, item); } _isDirty = false; _isOverflowing = _cache.Count > _maxCacheItems; } }
/// <summary> /// Initializes a new instance of the <see cref="SkeletonSet"/> class. /// </summary> /// <param name="skeletonSetName">Name of the <see cref="SkeletonSet"/>.</param> /// <param name="contentPath">The <see cref="ContentPaths"/> to load from.</param> public SkeletonSet(string skeletonSetName, ContentPaths contentPath) : this(GenericValueReader.CreateFromFile(GetFilePath(skeletonSetName, contentPath), _rootNodeName), contentPath) { }
/// <summary> /// Loads a <see cref="SchemaReader"/> from the specified file path. /// </summary> /// <param name="filePath">The file path.</param> /// <returns>The loaded <see cref="SchemaReader"/></returns> public static SchemaReader Load(string filePath) { var reader = GenericValueReader.CreateFromFile(filePath, _rootNodeName); return(new SchemaReader(reader)); }
/// <summary> /// Loads the settings from file, and applies loaded settings to the <see cref="Tool"/>s in this object. /// <see cref="Tool"/>s in this object that have no settings specified in the loaded file will have their values /// reset to default. /// </summary> /// <param name="filePath">The file to load from.</param> /// <returns>True if the settings were successfully loaded from the file; otherwise false.</returns> public bool TryLoad(string filePath) { try { if (!File.Exists(filePath)) { return(false); } var reader = GenericValueReader.CreateFromFile(filePath, _rootNodeName); // Read in the settings var toolKVPs = reader.ReadManyNodes(_toolSettingsNodeName, ReadKVP); var toolBarKVPS = reader.ReadManyNodes(_toolBarItemsNodeName, ReadToolBarItems); // Out with the old _toolSettings.Clear(); _toolBarOrder.Clear(); // And in with the new foreach (var kvp in toolKVPs) { try { _toolSettings.Add(kvp); } catch (Exception ex) { // When there is an error adding to the collection, just skip the item const string errmsg = "Failed to add item to _toolSettings dictionary. Key: {0}. Value: {1}. Exception: {2}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, kvp.Key, kvp.Value, ex); } Debug.Fail(string.Format(errmsg, kvp.Key, kvp.Value, ex)); } } foreach (var kvp in toolBarKVPS) { try { _toolBarOrder.Add(kvp); } catch (Exception ex) { // When there is an error adding to the collection, just skip the item const string errmsg = "Failed to add item to _toolBarOrder dictionary. Key: {0}. Value: {1}. Exception: {2}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, kvp.Key, kvp.Value, ex); } Debug.Fail(string.Format(errmsg, kvp.Key, kvp.Value, ex)); } } // Refresh all settings ResetTools(); } catch (Exception ex) { const string errmsg = "Failed to load settings from file `{0}`. Exception: {1}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, filePath, ex); } Debug.Fail(string.Format(errmsg, filePath, ex)); return(false); } return(true); }
/// <summary> /// Reloads the settings from the file. /// </summary> public void Reload() { var reader = GenericValueReader.CreateFromFile(FilePath, _rootNodeName); ((IPersistable)this).ReadState(reader); }