예제 #1
0
        public void BeginExecution()
        {
            Manga.Models.Manga manga = new Manga.Models.Manga();
            string             ex;

            if (args.d)
            {
                if (args.term.IsValidUri())
                {
                    manga.metaData = GetMetaData();
                    ex             = args.l ? args.export + Path.DirectorySeparatorChar + manga.metaData.name + ".adl" : Directory.GetCurrentDirectory() + $"{Path.DirectorySeparatorChar}Epubs{Path.DirectorySeparatorChar}" + manga.metaData.name + ".adl";
                    archive.InitializeZipper(ex);
                }
                else
                {
                    archive.InitializeZipper(args.term, true);
                    manga.LoadMangaFromADL(ref archive.zapive);
                    ex        = args.l ? args.export + Path.DirectorySeparatorChar + manga.metaData.name + ".adl" : Directory.GetCurrentDirectory() + $"{Path.DirectorySeparatorChar}Epubs{Path.DirectorySeparatorChar}" + manga.metaData.name + ".adl";
                    args.term = manga.metaData.url;
                }

                this.mdata = manga.metaData;
                manga.ExportMetaData(ref archive.zapive);
                MovePage(args.term);
                MangaChapter[] b = GetMangaLinks();
                if (manga.Chapters != null)
                {
                    ArraySegment <MangaChapter> mg = new ArraySegment <MangaChapter>(b, manga.Chapters.Length, b.Length - manga.Chapters.Length);
                    MangaChapter[] c = new MangaChapter[b.Length];
                    manga.Chapters.CopyTo(c, 0);
                    mg.CopyTo(c, manga.Chapters.Length);
                    manga.Chapters = c;
                }
                else
                {
                    manga.Chapters = b;
                }
            }
            else
            {
                //manga.Chapters = GetMangaLinks(); unable for now.
                ex = args.l ? args.export : args.term;
                archive.InitializeZipper(ex, true);
                manga.LoadMangaFromADL(ref archive.zapive);
                manga.LoadChaptersFromADL(ref archive.zapive);
            }

            for (int idx = (args.vRange ? args.VideoRange[0] : args.d ? 0 : manga.Chapters.Length); idx < (args.vRange ? args.VideoRange[1] : manga.Chapters.Length); idx++)
            {
                if (manga.Chapters[idx].existing == true)
                {
                    continue;
                }
                manga.Chapters[idx].Images = GetImages(ref manga.Chapters[idx], ref manga, ref archive);
                List <Byte[]> bytes = new List <byte[]>();

                foreach (Epub.Image img in manga.Chapters[idx].Images)
                {
                    bytes.Add(img.bytes);
                }

                archive.AddContentToArchive(manga.Chapters[idx].ChapterName, bytes);
                manga.Chapters[idx].Images = null; // free up memory.
                GC.Collect();
            }

            manga.ExportToEpub(Directory.GetCurrentDirectory() + $"{Path.DirectorySeparatorChar}Epubs{Path.DirectorySeparatorChar}" + manga.metaData.name, ref archive.zapive);
        }