예제 #1
0
        private static bool Extract(Stream input, Stream output)
        {
            var reader = new BinaryReader(input);
            var writer = new BinaryWriter(output);
            var header = new FileHeader();

            header.ReadFrom(reader);
            if (!header.IsValid)
            {
                return(false);
            }
            if (header.DecodedAllSize != input.Length)
            {
                return(false);
            }

            header.WriteTo(writer);

#if false
            Lzss.Extract(input, output);
#else
            var body = new byte[header.DecodedAllSize - header.Size];
            input.Read(body, 0, body.Length);
            output.Write(body, 0, body.Length);
#endif
            output.Flush();
            output.SetLength(output.Position);

            return(output.Position == header.DecodedAllSize);
        }
        protected override void ConvertBestShot(Stream input, Stream output)
        {
            using (var decoded = new MemoryStream())
            {
                var outputFile = output as FileStream;

                var reader = new BinaryReader(input);
                var header = new BestShotHeader();
                header.ReadFrom(reader);

                var key = new LevelScenePair(header.Level, header.Scene);
                if (this.bestshots == null)
                {
                    this.bestshots = new Dictionary <LevelScenePair, BestShotPair>(SpellCards.Count);
                }
                if (!this.bestshots.ContainsKey(key))
                {
                    this.bestshots.Add(key, new BestShotPair(outputFile.Name, header));
                }

                Lzss.Extract(input, decoded);

                decoded.Seek(0, SeekOrigin.Begin);
                using (var bitmap = new Bitmap(header.Width, header.Height, PixelFormat.Format24bppRgb))
                {
                    try
                    {
                        var permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
                        permission.Demand();

                        var bitmapData = bitmap.LockBits(
                            new Rectangle(0, 0, header.Width, header.Height),
                            ImageLockMode.WriteOnly,
                            bitmap.PixelFormat);

                        var source       = decoded.ToArray();
                        var sourceStride = 3 * header.Width;    // "3" means 24bpp.
                        var destination  = bitmapData.Scan0;
                        for (var sourceIndex = 0; sourceIndex < source.Length; sourceIndex += sourceStride)
                        {
                            Marshal.Copy(source, sourceIndex, destination, sourceStride);
                            destination = destination + bitmapData.Stride;
                        }

                        bitmap.UnlockBits(bitmapData);
                    }
                    catch (SecurityException e)
                    {
                        Console.WriteLine(e.ToString());
                    }

                    bitmap.Save(output, ImageFormat.Png);
                    output.Flush();
                    output.SetLength(output.Position);
                }
            }
        }
        private static bool Extract(Stream input, Stream output)
        {
            var reader = new BinaryReader(input);
            var writer = new BinaryWriter(output);

            var header = new Header();

            header.ReadFrom(reader);
            header.WriteTo(writer);

            var bodyBeginPos = output.Position;

            Lzss.Extract(input, output);
            output.Flush();
            output.SetLength(output.Position);

            return(header.DecodedBodySize == (output.Position - bodyBeginPos));
        }
        private static bool Extract(Stream input, Stream output)
        {
            var reader = new BinaryReader(input);
            var writer = new BinaryWriter(output);
            var header = new FileHeader();

            header.ReadFrom(reader);
            if (!header.IsValid)
            {
                return(false);
            }
            if (header.Size + header.EncodedBodySize != input.Length)
            {
                return(false);
            }

            header.WriteTo(writer);

            Lzss.Extract(input, output);
            output.Flush();
            output.SetLength(output.Position);

            return(output.Position == header.DecodedAllSize);
        }