コード例 #1
0
ファイル: PNGPreset.cs プロジェクト: Repflez/COM3D2.PNGPreset
        public static bool PresetLoadHook(CharacterMgr mgr, out CharacterMgr.Preset result, BinaryReader br,
                                          string fileName)
        {
            result = null;

            if (fileName == null ||
                !Path.GetExtension(fileName).Equals(".png", StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            var stream = br.BaseStream;

            var buf = new byte[IEND_MAGIC.Length];

            var pos = 0;

            for (;; stream.Position = ++pos)
            {
                var len = stream.Read(buf, 0, buf.Length);

                if (len != IEND_MAGIC.Length)
                {
                    return(true);
                }

                if (BytesEqual(buf, IEND_MAGIC))
                {
                    break;
                }
            }

            // Skip CRC
            stream.Position += 4;

            var prevPos = stream.Position;

            if (br.ReadString() != "CM3D2_PRESET")
            {
                return(true);
            }

            stream.Position = prevPos;

            result             = mgr.PresetLoad(br, null);
            result.strFileName = fileName;

            return(true);
        }