コード例 #1
0
        public bool Open(string filename)
        {
            Header    = new Header(this);
            TOC       = new TOC(this);
            _filename = filename;

            bool encrypted = false;

            _stream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);

            var br = new BinaryReader(_stream);

            byte[] headerData = br.ReadBytes(0x14);

            if (BitConverter.ToUInt32(headerData, 0) != Header.MagicId)
            {
                encrypted = true;
            }

            if (encrypted)
            {
                headerData = DataUtil.Decrypt(headerData);
            }

            var headerMS = new MemoryStream(headerData);

            Header.Read(new BinaryReader(headerMS));

            headerMS.Close();

            if (Header.Identifier != Header.MagicId || Header.Version != Header.SupportedVersion)
            {
                _stream.Close();
                return(false);
            }

            byte[] tocData = br.ReadBytes(Header.TocSize);

            if (encrypted)
            {
                tocData = DataUtil.Decrypt(tocData);
            }

            var tocMS = new MemoryStream(tocData);

            TOC.Read(new BinaryReader(tocMS));

            tocMS.Close();

            return(true);
        }