예제 #1
0
파일: Riff.cs 프로젝트: akinomyoga/afh
        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);
        }
예제 #2
0
파일: Riff.cs 프로젝트: akinomyoga/afh
        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);
        }
예제 #3
0
        public static ThumbsFile read(StreamAccessor accessor)
        {
            ThumbsFile     r    = new ThumbsFile();
            Riff::RiffFile riff = Riff::RiffFile.FromStream(accessor.Stream, true);
            StreamAccessor ac;

            foreach (Riff::Chunk chunk in riff.EnumerateChunksByName("head"))
            {
                ac = new StreamAccessor(chunk.Stream);
                if (VERSION != ac.ReadInt32(EncodingType.I4))
                {
                    throw new System.ApplicationException("ファイルフォーマットの version が異なります。");
                }
                break;
            }

            foreach (Riff::Chunk chunk in riff.EnumerateChunksByName("thms"))
            {
                r.thumbs = chunk.GetContent <ImageCollection>();
                break;
            }

            foreach (Riff::Chunk chunk in riff.EnumerateChunksByName("dirs"))
            {
                ac     = new StreamAccessor(chunk.Stream);
                r.dirs = ac.Read <DirectoryCollection>();
                break;
            }
            riff.Close();

            r.read_initialize();
            return(r);
        }
예제 #4
0
        /// <summary>
        /// ThumbsFile をファイルから読み込みます。
        /// 指定したファイルが存在しない場合は新しくファイルを作成します。
        /// </summary>
        /// <param name="filename">ファイル名を指定します。</param>
        /// <returns>作成した ThumbsFile のインスタンスを返します。</returns>
        public static ThumbsFile OpenFile(string filename)
        {
            ThumbsFile thumbsfile;

            if (System.IO.File.Exists(filename))
            {
                StreamAccessor accessor = new StreamAccessor(System.IO.File.OpenRead(filename));
                thumbsfile = accessor.Read <ThumbsFile>();
                accessor.Stream.Close();
            }
            else if (System.IO.Path.GetExtension(filename).ToLower() != ".thm" && System.IO.File.Exists(filename + ".thm"))
            {
                filename += ".thm";
                StreamAccessor accessor = new StreamAccessor(System.IO.File.OpenRead(filename));
                thumbsfile = accessor.Read <ThumbsFile>();
                accessor.Stream.Close();
            }
            else
            {
                thumbsfile        = new ThumbsFile();
                thumbsfile.dirs   = new DirectoryCollection(thumbsfile);
                thumbsfile.thumbs = new ImageCollection(thumbsfile);
            }
            thumbsfile.filename = filename;
            return(thumbsfile);
        }
예제 #5
0
        private static ImageDirectory read(StreamAccessor accessor)
        {
            ImageDirectory dir = new ImageDirectory(accessor.ReadString(EncodingType.NoSpecified));

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

            for (int i = 0; i < count; i++)
            {
                dir.images.Add(accessor.ReadInt32(EncodingType.I4));
            }

            dir.dirs = accessor.Read <DirectoryCollection>();
            return(dir);
        }
예제 #6
0
        private static ImageCollection read_chunk(StreamAccessor accessor)
        {
            int             c   = accessor.ReadInt32(EncodingType.I4);
            ImageCollection ret = new ImageCollection(c);

            ret.count = c;
            try{
                while (accessor.RestLength > 0)
                {
                    ret.register(accessor.Read <Thumb>());
                }
            }catch (System.Exception e) {
                afh.File.__dll__.log.WriteError(e, "ImageCollection 読み取り中のエラー");
            }
            return(ret);
        }
예제 #7
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);
        }