/// <summary> /// Gets a file. /// </summary> /// <param name="name">The name of the file to get.</param> /// <returns>The file.</returns> public T Get(string name) { name = name.ToLowerInvariant(); lock (Cache) { if (Cache.ContainsKey(name)) { return(Cache[name]); } if (EntriesByName.ContainsKey(name)) { var fullPath = UseContent? ("Content/" + EntriesByName[name]):(UseTS1?Path.Combine(ContentManager.TS1BasePath, EntriesByName[name]):ContentManager.GetPath(EntriesByName[name])); using (var reader = File.OpenRead(fullPath)) { T item; if (Codec == null) { item = (T)SmartCodec.Decode(reader, Path.GetExtension(fullPath)); } else { item = Codec.Decode(reader); } if (item is IFileInfoUtilizer) { ((IFileInfoUtilizer)item).SetFilename(Path.GetFileName(fullPath)); } Cache.Add(name, item); return(item); } } return(default(T)); } }
/// <summary> /// Gets a file. /// </summary> /// <param name="name">The name of the file to get.</param> /// <returns>The file.</returns> public T Get(string name) { name = name.ToLowerInvariant(); lock (Cache) { if (Cache.ContainsKey(name)) { return(Cache[name]); } if (EntriesByName.ContainsKey(name)) { var fullPath = ContentManager.GetPath(EntriesByName[name]); using (var reader = File.OpenRead(fullPath)) { var item = Codec.Decode(reader); Cache.Add(name, item); return(item); } } return(default(T)); } }