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 DeleteItems(List <EpubItem> items)
 {
     foreach (var item in items)
     {
         Opf.DeleteItem(item);
         ToC.DeleteItem(item);
     }
 }
Example #3
0
 public void InsertChapter(EpubItem chapter, TocEntry tocEntry, EpubItem preceedingItem)
 {
     Opf.InsertChapter(new List <EpubItem>()
     {
         chapter
     }, preceedingItem);
     ToC.InsertChapter(new List <TocEntry>()
     {
         tocEntry
     }, preceedingItem);
 }
Example #4
0
        public void WriteFile(string fileName)
        {
            using (ZipFile zip = new ZipFile(System.Text.Encoding.UTF8))
            {
                AddMimeType(zip);
                zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
                Container.WriteTo(zip);
                Opf.WriteTo(zip);
                ToC.WriteToNcxEpubItem();
                Opf.WriteManifestTo(zip);

                zip.Save(fileName);
            }
        }
Example #5
0
        public void ReadFile(string fileName)
        {
            var options = new ReadOptions()
            {
                Encoding = System.Text.Encoding.UTF8
            };

            using (ZipFile zip = ZipFile.Read(fileName, options))
            {
                Container = new Container(zip.ExtractXml(Epub.ContainerPath));
                var containerPath = Container.FullPath;
                Opf = new Opf(zip.ExtractXml(containerPath), containerPath);
                foreach (var item in Opf.Manifest)
                {
                    item.AddRawDataToItem(zip);
                }
                RebuildImageUseIndexes();
                var ncxItem = Opf.NcxItem;
                ToC = new ToC(zip.ExtractXml(ncxItem.AbsolutePath), ncxItem, Opf.AbsolutePathIndex);
            }
        }
Example #6
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);
        }
Example #7
0
 public void InsertChapters(List <EpubItem> chapters, List <TocEntry> tocEntries, EpubItem insertAt)
 {
     Opf.InsertChapter(chapters, insertAt);
     ToC.InsertChapter(tocEntries, insertAt);
 }