Esempio n. 1
0
        private AstroDigitalVideoStream(string fileName)
        {
            m_FileName = fileName;

            m_AdvFile = AdvFile.OpenFile(fileName);
            m_ImageSection = m_AdvFile.ImageSection;

            CheckAdvFileFormatInternal();
        }
Esempio n. 2
0
        public static AdvFile OpenFile(string fileName)
        {
            FileStream inputFile = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            BinaryReader fileReader = new BinaryReader(inputFile);

            uint magic = fileReader.ReadUInt32();

            if (magic != 0x46545346)
                throw new FormatException("Unknown or unsupported version of an FSTF file");

            byte dataFormatVer = fileReader.ReadByte();

            uint numFrames = fileReader.ReadUInt32();
            long indexTableOffset = fileReader.ReadInt64();
            long metadataSystemTableOffset = fileReader.ReadInt64();
            long metadataUserTableOffset = fileReader.ReadInt64();

            AdvFile rv = new AdvFile();

            rv.m_InputFile = inputFile;
            rv.m_FileReader = fileReader;
            rv.m_FileName = fileName;

            if (dataFormatVer >= 1)
            {
                byte sectionsCount = fileReader.ReadByte();

                var sectionDefs = new Dictionary<ulong, string>();

                for (int i = 0; i < sectionsCount; i++)
                {
                    string sectionType = fileReader.ReadAsciiString256();
                    ulong sectionHeaderOffset = fileReader.ReadUInt64();
                    sectionDefs.Add(sectionHeaderOffset, sectionType);
                }

                rv.m_NumberOfFrames = numFrames;
                foreach (uint offset in sectionDefs.Keys)
                {
                    inputFile.Seek(offset, SeekOrigin.Begin);
                    IAdvDataSection section = AdvSectionFactory.ConstructSection(sectionDefs[offset], fileReader);
                    rv.AddDataSection(section);
                }

                fileReader.BaseStream.Seek(metadataSystemTableOffset, SeekOrigin.Begin);
                #region read metadata

                uint propsCount = fileReader.ReadUInt32();
                for (int i = 0; i < propsCount; i++)
                {
                    string propName = fileReader.ReadAsciiString256();
                    string propValue = fileReader.ReadAsciiString256();
                    rv.AdvFileTags[propName] = propValue;
                }
                #endregion

                rv.m_RecoveryOffset = fileReader.BaseStream.Position;

                if (indexTableOffset > fileReader.BaseStream.Length || metadataUserTableOffset > fileReader.BaseStream.Length ||
                    indexTableOffset == 0 || metadataUserTableOffset == 0)
                {
                    rv.m_IsCorrupted = true;
                    return rv;
                }

                inputFile.Seek(indexTableOffset, SeekOrigin.Begin);
            }

            rv.m_Magic = magic;

            try
            {
                rv.m_Index = new AdvFramesIndex(fileReader);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                rv.m_IsCorrupted = true;
                return rv;
            }

            rv.InitialisePropertiesFromTags();

            return rv;
        }