Exemple #1
0
        private static new RiffFile read(StreamAccessor accessor)
        {
            if ("RIFF" != accessor.ReadString(EncodingType.CC4))
            {
                throw new System.ApplicationException("指定したデータは RIFF データではありません。");
            }

            RiffFile ret  = new RiffFile();
            uint     size = accessor.ReadUInt32(EncodingType.U4);

            ret.type = accessor.ReadString(EncodingType.CC4);

            ret.chunks = new Gen::List <Chunk>();
            StreamAccessor acChunks = new StreamAccessor(accessor.ReadSubStream(size - 4));

            try{
                while (acChunks.RestLength > 0)
                {
                    ret.chunks.Add(acChunks.Read <Chunk>());
                }
            }finally{
                acChunks.Stream.Close();
            }
            return(ret);
        }
Exemple #2
0
        internal static List read(StreamAccessor accessor)
        {
            List ret = new List();

            if ("LIST" != accessor.ReadString(EncodingType.CC4))
            {
                throw new System.ApplicationException("読み込もうとしているデータは LIST チャンクではないです。");
            }

            uint size = accessor.ReadUInt32(EncodingType.U4);

            ret.type = accessor.ReadString(EncodingType.CC4);

            ret.chunks = new Gen::List <Chunk>();
            StreamAccessor acChunks = new StreamAccessor(accessor.ReadSubStream(size - 4));

            try{
                while (acChunks.RestLength > 0)
                {
                    ret.chunks.Add(acChunks.Read <Chunk>());
                }
            }finally{
                acChunks.Stream.Close();
            }
            return(ret);
        }
Exemple #3
0
        private static Chunk read(StreamAccessor accessor)
        {
            string name = accessor.ReadString(EncodingType.CC4);

            if (name == "LIST")
            {
                accessor.Stream.Seek(-4, System.IO.SeekOrigin.Current);
                return(List.read(accessor));
            }

            Chunk ret = new Chunk(name);

            uint size = accessor.ReadUInt32(EncodingType.U4);

            ret._stream = accessor.ReadSubStream(size);

            return(ret);
        }
Exemple #4
0
            protected override FileDataCached Read(StreamAccessor accessor)
            {
                FileDataCached ret = (FileDataCached)System.Activator.CreateInstance(target_type, true);

                ret.InitializeForRead();

                long pos_bef = accessor.Position;

                try {
                    ret.Read(accessor);
                } catch (FileDataCached.NullReturn) {
                    return(null);
                }
                long pos_aft = accessor.Position;

                accessor.Stream.Position = pos_bef;
                ret.stream  = accessor.ReadSubStream(pos_aft - pos_bef);
                ret.changed = false;
                return(ret);
            }
Exemple #5
0
        private static DirectoryCollection read(StreamAccessor accessor)
        {
            DirectoryCollection ret = new DirectoryCollection();

            uint           size   = accessor.ReadUInt32(EncodingType.U4);
            StreamAccessor acdirs = new StreamAccessor(accessor.ReadSubStream(size));

            try{
                while (acdirs.RestLength > 0)
                {
                    ImageDirectory item = acdirs.Read <ImageDirectory>();
                    ret.Add(item);
                    ret.paths[item.name] = item;
                }
            }catch (afh.File.StreamOverRunException) {
            }catch (System.Exception e) {
                afh.File.__dll__.log.WriteError(e, ".thm 内の画像ディレクトリを読込中にエラーが発生しました。");
            }

            return(ret);
        }
Exemple #6
0
        public static Tag ReadFromStream(StreamAccessor accessor, out int tagsize)
        {
            Tag tag = new Tag();

            bool unsync;
            int  size;

            try{
                size    = tag.ReadTagHeader(accessor, out unsync);
                tagsize = size + 10;
            }catch (System.Exception e) {
                __dll__.log.WriteError(e, "TagHeader の読込に失敗しました。");
                tagsize = 0;
                return(null);
            }

            System.IO.Stream str = accessor.ReadSubStream((long)size);
            StreamAccessor   acc_str;

            if (unsync)
            {
                System.IO.Stream stream = ID3Utils.ID3ResolveUnsync(str);
                str.Close();
                acc_str = new StreamAccessor(stream);
            }
            else
            {
                acc_str = new StreamAccessor(str);
            }

            if (tag.has_ext)
            {
                uint crc32;
                int  padding;
                try{
                    tag.ReadExtHeader(acc_str, out crc32, out padding);
                }catch (Exception exception2) {
                    exception = exception2;
                    __dll__.log.WriteError(exception, "ExtendedHeader の読込に失敗しました。");
                    return(null);
                }
                if (tag.hascrc)
                {
                    long crc_start = acc_str.Stream.Position;
                    long crc_len   = (acc_str.Stream.Length - crc_start) - padding;
                    if (crc_len < 0L)
                    {
                        __dll__.log.WriteError(string.Format("Extended Header-Padding Size の値が不正です。大きすぎます:{0}", padding));
                        return(null);
                    }
                    if (crc32 != ID3Utils.CalculateCRC32(acc_str.Stream, crc_start, crc_len))
                    {
                        __dll__.log.WriteError("ファイルの CRC32 値が一致しませんでした。");
                        return(null);
                    }
                }
            }
            tag.frames = new afh.Collections.DictionaryP <string, Frame>();
            while (true)
            {
                Frame val = acc_str.Read <Frame>(EncodingType.NoSpecified);
                if (val == Frame.EndOfFrames)
                {
                    acc_str.Stream.Close();
                    return(tag);
                }
                tag.frames.Add(val.FrameId, val);
            }
        }