Esempio n. 1
0
            // 'file_source' should be an open new instance of the file source
            public BLIData(Main main, IFileSource file_source, long filepos_ = 0, long fileend_ = long.MaxValue, bool reload_ = false, int build_issue_ = 0)
            {
                build_issue = build_issue_;

                // Use a fixed file end so that additions to the file don't muck this
                // build up. Reducing the file size during this will probably cause an
                // exception but oh well...
                file               = file_source.NewInstance().Open();
                fileend            = Math.Min(file.Stream.Length, fileend_);
                filepos            = Math_.Clamp(filepos_, 0, fileend);
                filepos_line_index = LineIndex(main.m_line_index, filepos);

                max_line_length  = main.Settings.MaxLineLength;
                file_buffer_size = main.m_bufsize;
                line_cache_count = main.m_line_cache_count;
                line_index_count = main.m_line_index.Count;
                ignore_blanks    = main.Settings.IgnoreBlankLines;

                // We have to reload if 'filepos' moves outside the current cached range because
                // we don't know how many lines there are between the new 'filepos' and the nearest
                // edge of the cached data.
                reload = reload_ || !filepos_line_index.Within(0, line_cache_count);

                // Find the byte range of the file currently loaded
                cached_whole_line_range = main.LineStartIndexRange;

                // Get a copy of the filters to apply
                filters = new List <IFilter>();
                filters.AddRange(main.m_filters);
                if (main.m_quick_filter_enabled)
                {
                    filters.AddRange(main.m_highlights.ToList <IFilter>());
                    filters.Add(Filter.RejectAll);                     // Add a RejectAll so that non-highlighted means discard
                }

                // Get a copy of the transforms
                transforms = main.m_transforms.ToList();

                Debug.Assert(main.m_encoding != null);
                Debug.Assert(main.m_row_delim != null);
                bool certain, autodetect;

                // If the settings say auto detect encoding, and this is a reload
                // then detect the encoding, otherwise use what it is currently set to
                certain    = false;
                autodetect = main.Settings.Encoding.Length == 0;
                encoding   = reload_ && autodetect
                                        ? GuessEncoding(file_source, out certain)
                                        : (Encoding)main.m_encoding.Clone();

                if (certain)
                {
                    main.m_encoding = (Encoding)encoding.Clone();
                }

                // If the settings say auto detect the row delimiters, and this is a reload
                // then detect them, otherwise use what is currently set
                certain    = false;
                autodetect = main.Settings.RowDelimiter.Length == 0;
                row_delim  = reload_ && autodetect
                                        ? GuessRowDelimiter(file_source, encoding, main.Settings.MaxLineLength, out certain)
                                        : (byte[])main.m_row_delim.Clone();

                if (certain)
                {
                    main.m_row_delim = (byte[])row_delim.Clone();
                }

                col_delim = (byte[])main.m_col_delim.Clone();
            }