Example #1
0
        public List <string> CheckForMissingChapters()
        {
            var       srcToTitle            = ToC.BuildScrToTitleMap();
            var       titles                = new List <string>();
            int       previousChapterNumber = Epub.NoChapterNum;
            Signature previousSignature     = new Signature();

            foreach (var item in Opf.Spine)
            {
                string title = null;
                srcToTitle.TryGetValue(item.AbsolutePath, out title);
                int  currentChapterNumber = title.ExtractProbableChapterNumber();
                bool missing = ((currentChapterNumber != Epub.NoChapterNum) &&
                                (previousChapterNumber != Epub.NoChapterNum) &&
                                (currentChapterNumber != (previousChapterNumber + 1)));
                previousChapterNumber = currentChapterNumber;
                if (missing)
                {
                    titles.Add($"Might be a missing chapter before \"{title}\"");
                }
                var    sig           = item.RawBytes.ToXhtml().CalcSignature();
                string possibleError = item.CheckForErrors(sig, previousSignature);
                if (possibleError != null)
                {
                    titles.Add(possibleError);
                }
                previousSignature = sig;
            }
            return(titles);
        }
Example #2
0
        public void SortSpineByChapterNumber()
        {
            var srcToTitle = ToC.BuildScrToTitleMap();

            int Comparison(EpubItem x, EpubItem y)
            {
                string title = null;

                srcToTitle.TryGetValue(x.AbsolutePath, out title);
                int xChapterNumber = title.ExtractProbableChapterNumber();

                title = null;
                srcToTitle.TryGetValue(y.AbsolutePath, out title);
                int yChapterNumber = title.ExtractProbableChapterNumber();

                return(xChapterNumber - yChapterNumber);
            }

            Opf.Spine.Sort(Comparison);
            ToC.GenerateToCFromChapters(Opf.Spine, srcToTitle);
        }