예제 #1
0
        public override int Run(string[] remainingArguments)
        {
            if (remainingArguments[1] != "-")
            {
                input = File.OpenRead(remainingArguments[1]);
            }

            switch (remainingArguments[0])
            {
            case "brainloller":
                using (StreamWriter writer = new StreamWriter(output))
                {
                    writer.Write(Brainloller.Decode(new Bitmap(input)));
                }
                return(0);

            case "braincopter":
                using (StreamWriter writer = new StreamWriter(output))
                {
                    writer.Write(Braincopter.Decode(new Bitmap(input)));
                }
                return(0);

            default:
                throw new ConsoleHelpAsException("Unrecognized language.");
            }
        }
예제 #2
0
        public override int Run(string[] remainingArguments)
        {
            if (remainingArguments[1] != "-")
            {
                input = File.OpenRead(remainingArguments[1]);
            }

            switch (remainingArguments[0])
            {
            case "brainfuck":
                using (StreamWriter sw = new StreamWriter(output))
                    sw.Write(Brainfuck.Encode(input));
                return(0);

            case "brainloller":
                if (width == 0)
                {
                    throw new ConsoleHelpAsException("Width is a required option when encoding with Brainloller.");
                }
                using (StreamReader reader = new StreamReader(input))
                {
                    string code   = reader.ReadToEnd();
                    Bitmap newBmp = Brainloller.Encode(code, width, Color.Firebrick);
                    newBmp.Save(output, System.Drawing.Imaging.ImageFormat.Png);
                }
                return(0);

            case "braincopter":
                if (orig_image == null)
                {
                    throw new ConsoleHelpAsException("Original image is required when encoding with Braincopter.");
                }
                using (StreamReader reader = new StreamReader(input))
                {
                    string code     = reader.ReadToEnd();
                    Bitmap original = new Bitmap(orig_image);
                    Bitmap newBmp   = Braincopter.Encode(original, code);
                    newBmp.Save(output, System.Drawing.Imaging.ImageFormat.Png);
                }
                return(0);

            default:
                throw new ConsoleHelpAsException("Unrecognized language.");
            }
        }