wow, its like resource management!

git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1063 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
chrisf
2007-06-23 17:59:13 +00:00
parent 63caabee27
commit b2755e0260
10 changed files with 270 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace OpenRa.Core
{
static class ResourceCache
{
static Dictionary<string, IResource> items = new Dictionary<string, IResource>();
public static void Flush()
{
items.Clear();
}
public static IResource Get(string filename)
{
IResource r;
if (!items.TryGetValue(filename, out r))
items.Add(filename, r = Load(filename));
return r;
}
static IResource Load(string filename)
{
Converter<Stream, IResource> loader =
ResourceLoader.GetLoader(Path.GetExtension(filename));
if (loader == null)
return null;
Stream s = FileSystem.GetItem(filename);
if (s == null)
return null;
return loader(s);
}
}
}