Exemple #1
0
        private void LoadDvbS(ChannelList list, string path, string mappingName)
        {
            if (!File.Exists(path))
            {
                return;
            }

            var data = File.ReadAllBytes(path);

            if (data.Length < 12)
            {
                return;
            }

            var version = chanLstBin.VersionMajor;

            if (version <= 11)
            {
                var checksum = BitConverter.ToUInt32(data, data.Length - 4);

                var crcObj = new Crc32(false, Crc32.NormalPoly);
                var crc    = ~crcObj.CalcCrc32(data, 0, data.Length - 4);
                if (checksum != crc)
                {
                    throw new FileLoadException("Invalid CRC32 in " + path);
                }
            }


            int recordSize  = BitConverter.ToInt32(data, 4);
            int recordCount = BitConverter.ToInt32(data, 8);

            if (recordSize == 0 && version != 1)
            {
                recordSize = recordCount == 0 ? 0 : (data.Length - 12) / recordCount;
            }

            if (chanLstBin.VersionMajor <= 11)
            {
                // 12 bytes header, then a "next/prev" table, then the service records, then a CRC32
                // the "next/prev" table is a ring-list, every entry consists of 2 ushorts with the next and previous channel, wrapping around on the ends
                if (data.Length != 12 + recordCount * 4 + recordCount * recordSize + 4)
                {
                    throw new FileLoadException("Unsupported file content: " + path);
                }
            }

            this.dataFilePaths.Add(path);

            var dvbStringDecoder = new DvbStringDecoder(this.DefaultEncoding);

            var mapping = new DataMapping(this.ini.GetSection(mappingName));

            mapping.SetDataPtr(data, 12 + (chanLstBin.VersionMajor <= 11 ? recordCount * 4 : 0));
            for (int i = 0; i < recordCount; i++, mapping.BaseOffset += recordSize)
            {
                var ch = LoadDvbsChannel(list, mapping, i, dvbStringDecoder);
                this.DataRoot.AddChannel(list, ch);
            }
        }
Exemple #2
0
        /// <summary>
        /// Dump this file data to another file.
        /// </summary>
        /// <param name="toFile">The destination file stream.</param>
        /// <returns>Length copied.</returns>
        public override long DumpData(FileStream toFile)
        {
            if (this.file == null || !this.file.CanRead)
            {
                throw new IOException("Source stream is not accessable!");
            }

            if (this.fileSize < this.extractSize)
            {
                // Compressed
                return(this.DecompressToFile(toFile));
            }
            else
            {
                // Not compressed
                byte[] content = StreamUtility.ReadBytesFromStream(this.file, this.fileOffset, (int)this.extractSize);
                Debug.WriteLine(String.Format("CRC for file {0} is {1:X4}", this.fileName, Crc32.CalcCrc32(content)));
                return(StreamUtility.CopyBlock(this.file, toFile, this.fileOffset, (int)this.extractSize));
            }
        }