Example #1
0
        public override void SetBufferContents(Rectangle region, BufferCell fill)
        {
            ConsoleControl.CONSOLE_SCREEN_BUFFER_INFO cONSOLESCREENBUFFERINFO;
            uint num = 0;

            if (region.Right >= region.Left)
            {
                if (region.Bottom >= region.Top)
                {
                    SafeFileHandle bufferInfo = ConsoleHostRawUserInterface.GetBufferInfo(out cONSOLESCREENBUFFERINFO);
                    int            x          = cONSOLESCREENBUFFERINFO.BufferSize.X;
                    int            y          = cONSOLESCREENBUFFERINFO.BufferSize.Y;
                    ushort         wORD       = ConsoleControl.ColorToWORD(fill.ForegroundColor, fill.BackgroundColor);
                    Coordinates    coordinate = new Coordinates(0, 0);
                    if (region.Left != -1 || region.Right != -1 || region.Top != -1 || region.Bottom != -1)
                    {
                        if (region.Left >= x || region.Top >= y || region.Right < 0 || region.Bottom < 0)
                        {
                            ConsoleHostRawUserInterface.tracer.WriteLine("region outside boundaries", new object[0]);
                            return;
                        }
                        else
                        {
                            int num1 = Math.Max(0, region.Left);
                            int num2 = Math.Min(x - 1, region.Right);
                            int num3 = num2 - num1 + 1;
                            coordinate.X = num1;
                            int num4 = Math.Max(0, region.Top);
                            int num5 = Math.Min(y - 1, region.Bottom);
                            coordinate.Y = num4;
                            if (ConsoleControl.IsCJKOutputCodePage(out num))
                            {
                                Rectangle rectangle = new Rectangle(0, 0, 1, num5 - num4);
                                int       num6      = this.LengthInBufferCells(fill.Character);
                                if (coordinate.X > 0)
                                {
                                    BufferCell[,] bufferCellArray = new BufferCell[rectangle.Bottom + 1, 2];
                                    ConsoleControl.ReadConsoleOutputCJK(bufferInfo, num, new Coordinates(coordinate.X - 1, coordinate.Y), rectangle, ref bufferCellArray);
                                    int num7 = 0;
                                    while (num7 <= rectangle.Bottom)
                                    {
                                        if (bufferCellArray[num7, 0].BufferCellType != BufferCellType.Leading)
                                        {
                                            num7++;
                                        }
                                        else
                                        {
                                            throw PSTraceSource.NewArgumentException("fill");
                                        }
                                    }
                                }
                                if (num2 != x - 1)
                                {
                                    BufferCell[,] bufferCellArray1 = new BufferCell[rectangle.Bottom + 1, 2];
                                    ConsoleControl.ReadConsoleOutputCJK(bufferInfo, num, new Coordinates(num2, coordinate.Y), rectangle, ref bufferCellArray1);
                                    if (num3 % 2 != 0)
                                    {
                                        int num8 = 0;
                                        while (num8 <= rectangle.Bottom)
                                        {
                                            if (!(bufferCellArray1[num8, 0].BufferCellType == BufferCellType.Leading ^ num6 == 2))
                                            {
                                                num8++;
                                            }
                                            else
                                            {
                                                throw PSTraceSource.NewArgumentException("fill");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        int num9 = 0;
                                        while (num9 <= rectangle.Bottom)
                                        {
                                            if (bufferCellArray1[num9, 0].BufferCellType != BufferCellType.Leading)
                                            {
                                                num9++;
                                            }
                                            else
                                            {
                                                throw PSTraceSource.NewArgumentException("fill");
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (num6 == 2)
                                    {
                                        throw PSTraceSource.NewArgumentException("fill");
                                    }
                                }
                                if (num3 % 2 == 1)
                                {
                                    num3++;
                                }
                            }
                            for (int i = num4; i <= num5; i++)
                            {
                                coordinate.Y = i;
                                ConsoleControl.FillConsoleOutputCharacter(bufferInfo, fill.Character, num3, coordinate);
                                ConsoleControl.FillConsoleOutputAttribute(bufferInfo, wORD, num3, coordinate);
                            }
                            return;
                        }
                    }
                    else
                    {
                        if (x % 2 != 1 || !ConsoleControl.IsCJKOutputCodePage(out num) || this.LengthInBufferCells(fill.Character) != 2)
                        {
                            int num10 = x * y;
                            ConsoleControl.FillConsoleOutputCharacter(bufferInfo, fill.Character, num10, coordinate);
                            ConsoleControl.FillConsoleOutputAttribute(bufferInfo, wORD, num10, coordinate);
                            return;
                        }
                        else
                        {
                            throw PSTraceSource.NewArgumentException("fill");
                        }
                    }
                }
                else
                {
                    object[] objArray = new object[2];
                    objArray[0] = "region.Bottom";
                    objArray[1] = "region.Top";
                    throw PSTraceSource.NewArgumentException("region", "ConsoleHostRawUserInterfaceStrings", "InvalidRegionErrorTemplate", objArray);
                }
            }
            else
            {
                object[] objArray1 = new object[2];
                objArray1[0] = "region.Right";
                objArray1[1] = "region.Left";
                throw PSTraceSource.NewArgumentException("region", "ConsoleHostRawUserInterfaceStrings", "InvalidRegionErrorTemplate", objArray1);
            }
        }