Ejemplo n.º 1
0
        // ---------- From here onwards, we shall read the unique resource files ---------- //

        public static ResourceClass.IResource ReadIResourceFile(bool headerOnly,
                                                                ChitinKey ckey, ResourceStruct.DelegateResourceFileReader resourceFileReader)
        {
            string overrideFile =
                ApplicationService.FindOverrideFile(ckey.name, ckey.resourceType);

            FileStream fileStream;
            int        fileOffset;
            int        fileSize;

            if (overrideFile != null) // Found it in override, so just use it
            {
                fileStream = Utils.ReadFileStream(overrideFile);
                fileOffset = 0;
                fileSize   = 0;
            }
            else if (ckey.isBiffed) // Load from biff file
            {
                ChitinBiff cbiff = ApplicationRuntime.ChitinIndex.CbiffCollection[ckey.biffIndex];

                if ((fileStream = ReadChitinBiffFile(cbiff)) == null)
                {
                    return(null);
                }

                if (ckey.resourceType != ResourceStruct.ResourceType.RTypeGTIS)
                {
                    fileOffset = cbiff.fileList[ckey.ckeyIndex].offset;
                    fileSize   = cbiff.fileList[ckey.ckeyIndex].size;
                }
                else
                {
                    fileOffset = cbiff.tileList[ckey.tileIndex].tileOffset;
                    fileSize   = cbiff.tileList[ckey.tileIndex].tileSize;
                }
            }
            else
            {
                return(null);
            }

            try
            {
                // apply the delegate here
                return(resourceFileReader(headerOnly, ckey, fileStream, fileOffset, fileSize));
            }
            catch (Exception e)
            {
                throw new ArgumentException(e.Message);
                //return null;
            }
        }
Ejemplo n.º 2
0
        private static ResourceClass.IResource LoadResourceFile(bool refresh, bool headerOnly,
                                                                ChitinKey ckey, ResourceStruct.DelegateResourceFileReader resourceFileReader)
        {
            ResourceClass.IResource irFile;

            if (refresh)
            {
                // clear the cache copy if it exists, especially during edits.
                cache.RemoveFromCache(ckey.name, ckey.resourceType);
            }
            else
            {
                // check if in cache, then retrieve the cache version
                irFile = cache.IsCached(ckey.name, ckey.resourceType);
                if (irFile != null)
                {
                    return(irFile);
                }
            }

            irFile = FileReader.ReadIResourceFile(headerOnly, ckey, resourceFileReader);
            if (irFile != null)
            {
                if ((irFile.ResourceType() != ResourceStruct.ResourceType.RTypeGTIS) &&
                    (irFile.ResourceType() != ResourceStruct.ResourceType.RTypeGWED))
                {
                    if (!headerOnly)
                    {
                        cache.PushInCache(irFile);
                    }
                }

                return(irFile);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
 public static ResourceClass.IResource LoadResourceFile(ChitinKey ckey,
                                                        ResourceStruct.DelegateResourceFileReader resourceFileReader)
 {
     return(LoadResourceFile(false, false, ckey, resourceFileReader));
 }