示例#1
0
        public static object LoadResource(ResourcePtr Ptr)
        {
            if (!IsResourceLoaded(Ptr))
            {
                if (!ResourceExists(Ptr))
                {
                    throw new ArgumentException("Cannot find file: " + Ptr.ToString() + " In any search path!");
                }

                ResourceFactory factory = GetFactoryForResource(Ptr);

                if (factory == null)
                {
                    Logger.Error("Failed to find Factory for resource: {0}", Ptr.ToString());
                    return(null);
                }

                using (Stream stream = GetFileStream(Ptr))
                {
                    object resource = factory.GetResource(stream);
                    if (resource is IIsResource)
                    {
                        (resource as IIsResource).ResourcePtr = Ptr;
                    }
                    ResourceCache.Add(Ptr, resource);
                }
                Logger.Info("Loaded Resource {0}", Ptr.ToString());
            }

            return(ResourceCache[Ptr]);
        }
示例#2
0
        public static bool EmplaceInMemoryResource(ResourcePtr Ptr, object Resource)
        {
            if (ResourceCache.ContainsKey(Ptr))
            {
                return(false);
            }

            Logger.Info("Emplaced object: {0} into {1}", Resource.ToString(), Ptr.ToString());
            ResourceCache.Add(Ptr, Resource);
            return(true);
        }