コード例 #1
0
        private void Load()
        {
            if (_hasLoadedBefore)
            {
                throw new FileLoadException("Already loaded this file.");
            }
            _hasLoadedBefore = true;

            _generalSections = new List <GeneralSection>();

            var bytes     = File.ReadAllBytes(_filePath);
            var nextIndex = 0L;

            while (nextIndex < bytes.Length)
            {
                GeneralSection section;
                nextIndex = GeneralSection.Create(bytes, nextIndex, out section);
                switch (section.SectionAsString)
                {
                case "DIDX":
                    _didx   = new DidxSection(section);
                    section = _didx;
                    break;

                case "DATA":
                    _data   = new DataSection(section, _didx.Items);
                    section = _data;
                    break;

                case "HIRC":
                    _hirc   = new HircSection(section);
                    section = _hirc;
                    break;
                }
                section.Process();
                _generalSections.Add(section);
            }
            var memoryStream = new MemoryStream();

            foreach (var generalSection in _generalSections)
            {
                var bytesToWrite = generalSection.ToBytes();
                memoryStream.Write(bytesToWrite, 0, bytesToWrite.Length);
            }
            var memoryStreamBuffer = memoryStream.ToArray();

            for (int i = 0; i < memoryStream.Length; i++)
            {
                if (memoryStreamBuffer[i] != bytes[i])
                {
                    throw new Exception("Weeeep!");
                }
            }
        }