Пример #1
0
        /// <summary>
        /// Releases all resources used by this instance.
        /// </summary>
        public void Dispose()
        {
            //Dispose
            ResourceMap.Dispose();

            //Clear
            fileNameLookup.Clear();
            tagPathLookup.Clear();
            TagResources.Clear();
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheResources"/> class.
        /// </summary>
        /// <param name="resourceMap">A resource map.</param>
        public CacheResources(HaloMap resourceMap)
        {
            //Set
            ResourceMap = resourceMap ?? throw new ArgumentNullException(nameof(resourceMap));
            string fileName = null;

            //Loop
            for (int i = 0; i < resourceMap.IndexEntries.Count; i++)
            {
                //Add to lookup
                tagPathLookup.Add($"{resourceMap.IndexEntries[i].Filename}.{resourceMap.IndexEntries[i].Root}", i);
                ITagGroup tagGroup = Abide.Tag.Cache.Generated.TagLookup.CreateTagGroup(resourceMap.IndexEntries[i].Root);
                fileName = $"{resourceMap.IndexEntries[i].Filename}.{tagGroup.Name}";
                fileNameLookup.Add(fileName, i);

                //Add resource
                TagGroupFiles.Add(new AbideTagGroupFile());
                TagResources.Add(new TagResourceInfo(resourceMap.IndexEntries[i].Filename, resourceMap.IndexEntries[i].Root, resourceMap.IndexEntries[i].Id)
                {
                    FileName = fileName
                });
            }

            //Load globals and sound cache file gestalt
            Globals.TagGroup = new Abide.Tag.Cache.Generated.Globals();
            SoundCacheFileGestalt.TagGroup = new Abide.Tag.Cache.Generated.SoundCacheFileGestalt();
            using (var stream = resourceMap.Globals.Data.GetVirtualStream())
                using (var reader = stream.CreateReader())
                {
                    //Goto globals
                    reader.BaseStream.Seek(resourceMap.IndexEntries.First.Address, SeekOrigin.Begin);
                    Globals.TagGroup.Read(reader);

                    //Goto sound cache file gestalt
                    reader.BaseStream.Seek(resourceMap.IndexEntries.Last.Address, SeekOrigin.Begin);
                    SoundCacheFileGestalt.TagGroup.Read(reader);
                }
        }