Exemple #1
0
        public TpsBlock(RandomAccess rx, int start, int end, bool ignorePageErrors)
        {
            Data   = rx ?? throw new ArgumentNullException(nameof(rx));
            Start  = start;
            End    = end;
            _pages = new List <TpsPage>();

            Data.PushPosition();
            Data.JumpAbsolute(Start);

            try
            {
                // Some blocks are 0 in length and should be skipped
                while (Data.Position < End)
                {
                    if (IsCompletePage())
                    {
                        try
                        {
                            var page = new TpsPage(Data);
                            _pages.Add(page);
                        }
                        catch (RunLengthEncodingException ex)
                        {
                            if (ignorePageErrors)
                            {
                                Debug.WriteLine($"Ignored RLE error: {ex.ToString()}");
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                    else
                    {
                        Data.JumpRelative(0x100);
                    }

                    NavigateToNextPage();
                }
            }
            finally
            {
                Data.PopPosition();
            }
        }