public ComicInfo LoadUri(Uri Uri) { CurrentUrl = Uri; Document = new HtmlDocument(); var HTML = Encoding.UTF8.GetString(TryDownload(Uri)); Document.LoadHtml(HTML); if (Program.Debug) { Program.Writer?.WriteLine("Load URL: {0}\r\nHTML: {1}", Uri.AbsoluteUri, HTML); Program.Writer?.Flush(); } foreach (var Node in Document.SelectNodes("//span[@class='none']")) { Node.Remove(); } ComicInfo Info = new ComicInfo(); Info.ContentType = ContentType.Comic; Info.Title = HttpUtility.HtmlDecode(Document.SelectSingleNode("//h1[@class='Title']").InnerText); Info.Cover = HttpUtility.HtmlDecode(Document.SelectSingleNode("//figure/img").GetAttributeValue("src", "")).TryDownload(); Info.Url = Uri; return(Info); }
public async Task <IActionResult> Edit(int id, [Bind("ComicID,ComicName,Description,Pages,Price,Extension,CompanyID,CategoryID")] ComicInfo comicInfo) { if (id != comicInfo.ComicID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(comicInfo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ComicInfoExists(comicInfo.ComicID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.ComicCategories, "CategoryID", "CategoryName", comicInfo.CategoryID); ViewData["CompanyID"] = new SelectList(_context.ComicCompanies, "CompanyID", "CompanyName", comicInfo.CompanyID); return(View(comicInfo)); }
public ComicInfo LoadUri(Uri Uri) { if (Browser == null) { Browser = new ChromiumWebBrowser(); Browser.Size = new System.Drawing.Size(500, 600); Browser.ReCaptchaHook(); while (!Browser.IsBrowserInitialized) { ThreadTools.Wait(100, true); } Login(); SkipSlowDown(); SolveCaptcha(); } CurrentUrl = Uri.AbsoluteUri; var Document = DownloadDocument(Uri); ComicInfo Info = new ComicInfo(); Info.Title = HttpUtility.HtmlDecode(Document.Descendants("title").First().InnerText); Info.Title = DataTools.GetRawName(Info.Title).Split('»').First(); Info.Cover = TryDownload(new Uri(HttpUtility.HtmlDecode(Document .SelectSingleNode("//div[@id=\"cover\"]/a/img") .GetAttributeValue("data-src", "")))); Info.ContentType = ContentType.Comic; return(Info); }
public MTBTaskCacheData() { firstInitMark = false; EventManager.RegisterEvent(EventMacro.FIRST_INIT_TASK, onFirstInitTask); initMark = false; if (!checkCanInitTask()) { canConductTaskList = new Dictionary <int, MTBTaskData>(); initMark = true; return; } taskCacheData data = MTBTaskCacheDataLoader.loadData(); if (data.taskId <= 1 && data.stepId == 0) { int[] picIds = { 1, 2 }; ComicInfo comicinfo = new ComicInfo(picIds, 7); MTBComicController.Instance.playComicByTime(comicinfo); } canConductTaskList = data.canConductTaskList; PrepareInitNpcMap = data.PrepareInitNpcMap; curStep = data.stepId; if (data.taskId != 0) { curConDuctTaskData = canConductTaskList[data.taskId]; } initMark = true; if (firstInitMark) { initNpc(); } }
public ComicInfo LoadUri(Uri Uri) { if (Browser == null) { Browser = new ChromiumWebBrowser(Uri.AbsoluteUri); Browser.ReCaptchaHook(); Browser.WaitForLoad(); Cookies = Browser.GetCookies().ToContainer(); UserAgent = Browser.GetUserAgent(); } CurrentUrl = Uri.AbsoluteUri; Document = DownloadDocument(Uri); ComicInfo Info = new ComicInfo(); Info.Title = HttpUtility.HtmlDecode(Document.SelectSingleNode("//div[@class=\"book-title\"]").InnerText); Info.Cover = TryDownload(HttpUtility.HtmlDecode(Document .SelectSingleNode("//img[@class=\"book-page-image img-responsive\"]") .GetAttributeValue("src", "")).EnsureAbsoluteUri(Domain)); Info.ContentType = ContentType.Comic; return(Info); }
public ComicInfo LoadUri(Uri Uri) { CurrentHost = Uri.Host; string CurrentHtml = Encoding.UTF8.GetString(TryDownload(Uri)); if (CurrentHtml.IsCloudflareTriggered()) { Cloudflare = JSTools.BypassCloudflare(Uri.AbsoluteUri); CurrentHtml = Encoding.UTF8.GetString(TryDownload(Uri)); } Document = new HtmlDocument(); Document.LoadHtml(CurrentHtml); ComicInfo Info = new ComicInfo(); Info.Title = Document.Descendants("title").First().InnerText; Info.Title = HttpUtility.HtmlDecode(Info.Title); Info.Title = Info.Title.Substring(0, Info.Title.LastIndexOf("-")).Trim(); Info.Cover = TryDownload(new Uri(Document .SelectSingleNode("//img[@class=\"img-thumbnail\"]") .GetAttributeValue("src", ""))); Info.ContentType = ContentType.Comic; return(Info); }
public ComicInfo LoadUri(Uri Uri) { Document = new HtmlDocument(); Document.LoadUrl(Uri); ComicInfo Info = new ComicInfo(); Info.Title = Document.SelectSingleNode("//h3").InnerText; Info.Title = HttpUtility.HtmlDecode(Info.Title); var Node = Document.SelectSingleNode("//img[contains(@class,\"alignnone size-large\")]"); string CLink = Node.GetAttributeValue("data-cfsrc", null); if (CLink == null) { CLink = Node.GetAttributeValue("src", null); } Info.Cover = new Uri(HttpUtility.HtmlDecode(CLink)).TryDownload(); Info.ContentType = ContentType.Comic; return(Info); }
public ComicInfo LoadUri(Uri Uri) { CurrentUrl = Uri.AbsoluteUri; Document = new HtmlDocument(); Document.LoadUrl(Uri); ComicInfo Info = new ComicInfo(); Info.Title = (Document.SelectSingleNode("//ul[@class=\"manga-info-text\"]/li/h1") ?? Document.SelectSingleNode("//ul[@class=\"manga-info-text\"]/li/h2") ?? Document.SelectSingleNode("//div[@class=\"story-info-right\"]/h1") ?? Document.SelectSingleNode("//h1[@class=\"title-manga\"]") ?? Document.SelectSingleNode("//h2[@class=\"title-manga\"]")).InnerText; Info.Title = HttpUtility.HtmlDecode(Info.Title); string CoverUrl = (Document.SelectSingleNode("//div[@class=\"manga-info-pic\"]/img") ?? Document.SelectSingleNode("//span[@class=\"info-image\"]/img") ?? Document.SelectSingleNode("//div[@class=\"media-left cover-detail\"]/img")).GetAttributeValue("src", string.Empty); Info.Cover = CoverUrl.EnsureAbsoluteUrl(Uri).TryDownload(); Info.ContentType = ContentType.Comic; return(Info); }
public static void InsertComicsPart2(MySqlConnection connection) { using (var db = new MyDbContext(connection, false)) { var P = new Publisher { Name = "Marvel", Imprint = false }; var W = new Writer { Name = "Brian Bendis" }; var C = new ComicInfo { Name = "All-New X-men", IssueNumber = 22, CoverPrice = 4.25 }; var C1 = new ComicInfo { Name = "All-New X-men", IssueNumber = 23, CoverPrice = 3.99 }; var C2 = new ComicInfo { Name = "All-New X-men", IssueNumber = 24, CoverPrice = 3.99 }; P.Comics = new List <ComicInfo>(); P.Comics.Add(C); P.Comics.Add(C1); P.Comics.Add(C2); P.Writers = new List <Writer>(); P.Writers.Add(W); db.Publisher.Add(P); db.SaveChanges(); } }
private static void InsertComics(MySqlConnection conn) { using (var db = new MyDbContext(conn, false)) { var C1 = new ComicInfo { Name = "Eternal Warrior", IssueNumber = 2, CoverPrice = 3.99 }; var C2 = new ComicInfo { Name = "Eternal Warrior", IssueNumber = 3, CoverPrice = 3.99 }; var W = db.Writer.FirstOrDefault(w => w.Name == "Greg Pak"); var P = db.Publisher.FirstOrDefault(p => p.Name == "Valiant Entertainment"); // COMIC 1 C1.Publisher = P; C1.Writer = W; // COMIC 2 C2.Publisher = P; C2.Writer = W; // ADD BOTH COMICS TO THE DATABASE db.Comics.Add(C1); db.Comics.Add(C2); // SAVE THE COMICS TO THE DATABASE db.SaveChanges(); } }
public static void InsertComicsPart4(MySqlConnection connection) { using (var db = new MyDbContext(connection, false)) { // LETS LINK THE NEW WRITER TO THE PUBLISHER [Paul Cornel to Marvel] var w = new Writer() { Name = "Paul Cornell" }; var P = db.Publisher.FirstOrDefault(p => p.Name == "Marvel"); w.Publisher = P; db.Writer.Add(w); db.SaveChanges(); // AT THIS POINT THE WRITER SHOULD BE SAVED IN THE TABLE AND LINKED TO PUBLISHER var W = db.Writer.FirstOrDefault(w1 => w1.Name == "Paul Cornell"); var C = new ComicInfo() { Name = "Wolverine", IssueNumber = 1, CoverPrice = 3.99 }; C.Writer = W; C.Publisher = P; // ADD COMIC TO THE TABLE AND THEN SUBMIT TO DATABASE db.Comics.Add(C); db.SaveChanges(); } }
public ComicInfo LoadUri(Uri Uri) { string CurrentHtml = Encoding.UTF8.GetString(TryDownload(Uri)); if (CurrentHtml.IsCloudflareTriggered()) { Cloudflare = JSTools.BypassCloudflare(Uri.AbsoluteUri); CurrentHtml = Encoding.UTF8.GetString(TryDownload(Uri)); } Document = new HtmlDocument(); Document.LoadHtml(CurrentHtml); ComicInfo Info = new ComicInfo(); Info.Title = Document.SelectSingleNode("//div[@class=\"info-title\"]/h1").InnerText; Info.Title = HttpUtility.HtmlDecode(Info.Title); Info.Cover = TryDownload(new Uri(Document .SelectSingleNode("//div[contains(@class, \"info-img\")]/img") .GetAttributeValue("src", ""))); Info.ContentType = ContentType.Comic; return(Info); }
//暂时不公开 //public void playComic(int picId) //{ // comicUI = UIManager.Instance.showUI<ComicUI>(UITypes.COMIC, ComicObjPath) as ComicUI; // comicUI.showComic(picId); //} public void playComicByTime(ComicInfo info) { _info = info; _playMark = true; _timeDelay = _info.timeEachPic; _comicUI = UIManager.Instance.showUI <ComicUI>(UITypes.COMIC, ComicObjPath) as ComicUI; }
public ComicInfo LoadUri(Uri Uri) { Cookies = new CookieContainer(); CurrentUrl = Uri; ReverseChapters = Uri.Host.ToLower().Contains("manga47.com"); Document.LoadUrl(Uri, Cookies: Cookies); if (string.IsNullOrWhiteSpace(Document.ToHTML()) || Document.IsCloudflareTriggered()) { CFData = JSTools.BypassCloudflare(Uri.AbsoluteUri); Document.LoadHtml(CFData?.HTML); } ComicInfo Info = new ComicInfo(); var TitleNode = Document.SelectSingleNode("//div[@class='post-title']/*[self::h3 or self::h2 or self::h1]"); try { TitleNode.RemoveChild(TitleNode.ChildNodes.Where(x => x.Name == "span").Single()); } catch { } Info.Title = TitleNode.InnerText.Trim(); if (Info.Title.ToUpper().StartsWith("HOT")) { Info.Title = Info.Title.Substring(3); } Info.Title = HttpUtility.HtmlDecode(Info.Title).Trim(); var ImgNode = Document.SelectSingleNode("//div[@class='summary_image']/a/img"); var ImgUrl = ImgNode.GetAttributeValue("data-lazy-srcset", ""); if (string.IsNullOrWhiteSpace(ImgUrl)) { ImgUrl = ImgNode.GetAttributeValue("data-src", ""); } else { ImgUrl = ImgUrl.Trim().Split(',', ' ').First(); } if (string.IsNullOrWhiteSpace(ImgUrl)) { ImgUrl = ImgNode.GetAttributeValue("src", ""); } if (string.IsNullOrWhiteSpace(ImgUrl)) { ImgUrl = ImgNode.GetAttributeValue("data-cfsrc", ""); } if (ImgUrl.StartsWith("//")) { ImgUrl = "http:" + ImgUrl; } Info.Cover = ImgUrl.TryDownload(CFData); Info.ContentType = ContentType.Comic; return(Info); }
public ComicInfo LoadUri(Uri Uri) { Cookies = new CookieContainer(); CurrentUrl = Uri; Document.LoadUrl(Uri, Cookies: Cookies); if (string.IsNullOrWhiteSpace(Document.ToHTML()) || Document.IsCloudflareTriggered()) { CFData = JSTools.BypassCloudflare(Uri.AbsoluteUri); Document.LoadHtml(CFData?.HTML); } ComicInfo Info = new ComicInfo(); Info.Title = HttpUtility.HtmlDecode(Document.SelectSingleNode("//*[(self::h1 or self::h2 or self::h3) and @class='entry-title']").InnerText.Trim()); var ImgNode = Document.SelectSingleNode("//div[@class='thumb']/img"); var ImgUrl = ImgNode.GetAttributeValue("data-lazy-srcset", ""); if (string.IsNullOrWhiteSpace(ImgUrl)) { ImgUrl = ImgNode.GetAttributeValue("data-src", ""); } else { ImgUrl = ImgUrl.Trim().Split(',', ' ').First(); } if (string.IsNullOrWhiteSpace(ImgUrl)) { ImgUrl = ImgNode.GetAttributeValue("src", ""); } if (string.IsNullOrWhiteSpace(ImgUrl)) { ImgUrl = ImgNode.GetAttributeValue("data-cfsrc", ""); } if (ImgUrl.StartsWith("//")) { ImgUrl = "http:" + ImgUrl; } Info.Cover = ImgUrl.TryDownload(CFData); Info.ContentType = ContentType.Comic; return(Info); }
/// <summary> /// Save the current settings for this comic to the settings file. /// </summary> /// <param name="page">Page to save into settings</param> private async Task SaveCurrentSettings() { ComicInfo currentInfo; if (!UserSettings.CurrentSettings.comicList.TryGetValue(FilePath, out currentInfo)) { currentInfo = new ComicInfo(); } currentInfo.PageNumber = CurrentPageIndex; currentInfo.MangaMode = MangaMode; UserSettings.CurrentSettings.comicList[FilePath] = currentInfo; await UserSettings.SaveToFile(); }
public ComicInfo LoadUri(Uri Uri) { if (Uri.AbsoluteUri.Contains("/chapters/")) { Uri = new Uri(Uri.AbsoluteUri.Substring(0, Uri.AbsoluteUri.IndexOf("/chapters/")).TrimEnd('/') + "/chapters/1"); } else { Uri = new Uri(Uri.AbsoluteUri.TrimEnd('/') + "/chapters/1"); } if (CFData == null) { using (ChromiumWebBrowser Browser = new ChromiumWebBrowser()) { Browser.WaitForLoad(Uri.AbsoluteUri); do { CFData = Browser.BypassCloudflare(); } while (Browser.IsCloudflareTriggered()); } } Document = new HtmlAgilityPack.HtmlDocument(); Document.LoadUrl(Uri, Referer: "https://mangadex.org", UserAgent: CFData?.UserAgent ?? null, Cookies: CFData?.Cookies ?? null); ComicInfo Info = new ComicInfo(); Info.Title = Document.SelectSingleNode("//*[@id=\"content\"]//h6/span[@class=\"mx-1\"]").InnerText; Info.Title = HttpUtility.HtmlDecode(Info.Title); Info.Cover = TryDownload(Document .SelectSingleNode("//*[@id=\"content\"]//img[@class=\"rounded\"]") .GetAttributeValue("src", string.Empty).EnsureAbsoluteUri("https://mangadex.org")); Info.ContentType = ContentType.Comic; CurrentUrl = Uri.AbsoluteUri; if (Uri.AbsolutePath.Trim('/').Split('/').Length == 4) { CurrentUrl = Document.SelectSingleNode("//link[@rel='canonical']").GetAttributeValue("href", null); CurrentUrl = CurrentUrl.TrimEnd() + "/chapters/1"; } return(Info); }
public ComicInfo LoadUri(Uri Uri) { CurrentDomain = $"https://{Uri.Host}"; Document = new HtmlDocument(); Document.LoadUrl(Uri); ComicInfo Info = new ComicInfo(); Info.Title = Document.Descendants("title").First().InnerText; Info.Title = HttpUtility.HtmlDecode(Info.Title); Info.Title = Info.Title.Substring(0, Info.Title.ToLower().IndexOf("- raw")).Trim(); Info.Cover = new Uri(Document .SelectSingleNode("//div[@class=\"well info-cover\"]/img") .GetAttributeValue("src", string.Empty)).TryDownload(); Info.ContentType = ContentType.Comic; return(Info); }
public ComicInfo LoadUri(Uri Uri) { Document = new HtmlDocument(); Document.LoadHtml(Encoding.UTF8.GetString(TryDownload(Uri))); ComicInfo Info = new ComicInfo(); Info.Title = Document.SelectSingleNode("//span[@class=\"detail-info-right-title-font\"]").InnerText; Info.Title = HttpUtility.HtmlDecode(Info.Title.Trim()); string URL = Document .SelectSingleNode("//img[@class=\"detail-info-cover-img\"]") .GetAttributeValue("src", string.Empty); Info.Cover = TryDownload(new Uri(URL)); Info.ContentType = ContentType.Comic; return(Info); }
public ComicInfo ParseComicRackMetaData(string path) { ComicInfo config = null; try { XmlSerializer serializer = new XmlSerializer(typeof(ComicInfo)); StreamReader reader = new StreamReader(path); config = (ComicInfo)serializer.Deserialize(reader); reader.Close(); return(config); } catch (Exception e) { return(null); } finally { } }
public ComicInfo LoadUri(Uri Uri) { Document = new HtmlDocument(); Document.LoadUrl(Uri); ComicInfo Info = new ComicInfo(); Info.Title = Document.SelectSingleNode("//div[@class=\"info\"]/h1").InnerText; Info.Title = HttpUtility.HtmlDecode(Info.Title); Info.Cover = Document .SelectSingleNode("//div[@class=\"detail_body\"]") .GetAttributeValue("style", string.Empty) .Substring("url(", ")").TryDownload(Referer); Info.ContentType = ContentType.Comic; CurrentUrl = Uri.AbsoluteUri; return(Info); }
public static void InsertComicsPart3(MySqlConnection connection) { using (var db = new MyDbContext(connection, false)) { var P = db.Publisher.FirstOrDefault(p => p.Name == "Valiant Entertainment"); var C = new ComicInfo { Name = "Quantum and Woody", IssueNumber = 8, CoverPrice = 3.99 }; var C1 = new ComicInfo { Name = "Quantum and Woody", IssueNumber = 9, CoverPrice = 3.99 }; var C2 = new ComicInfo { Name = "Quantum and Woody", IssueNumber = 10, CoverPrice = 3.99 }; /* * var W = new Writer {Name = "James Asmus"}; * // LET SEE IF I CAN ADD JUST A NEW WRITER AND LINK IT TO ID#1[Valiant Entertainment] * W.Publisher = P; * db.Writer.Add(W); */ // ^THE ABOVE WORKED^ var W = db.Writer.FirstOrDefault(w => w.Name == "James Asmus"); // COMIC 1 C.Publisher = P; C.Writer = W; // COMIC 2 C1.Publisher = P; C1.Writer = W; // COMIC 3 C2.Publisher = P; C2.Writer = W; // ADD COMICS TO THE TABLES db.Comics.Add(C); db.Comics.Add(C1); db.Comics.Add(C2); db.SaveChanges(); } }
public ComicInfo LoadUri(Uri Uri) { CurrentDomain = $"https://{Uri.Host}"; Document = new HtmlDocument(); Document.LoadHtml(TryDownload(Uri.AbsoluteUri)); ComicInfo Info = new ComicInfo(); Info.Title = Document.SelectSingleNode("//h2[@class='cg_color']").InnerText; Info.Title = HttpUtility.HtmlDecode(Info.Title); Info.Cover = TryDownload(new Uri(Document .SelectSingleNode("//div[@class='col-sm-4 text-right']/img") .GetAttributeValue("src", "") .Substring("/timthumb.php?src=", "&", IgnoreMissmatch: true) .EnsureAbsoluteUrl(CurrentDomain))); Info.ContentType = ContentType.Comic; return(Info); }
public async Task <IActionResult> Create([Bind("ComicID,ComicName,Description,Pages,Price,File,CompanyID,CategoryID")] ComicInfo comicInfo) { using (var memoryStream = new MemoryStream()) { await comicInfo.File.FormFile.CopyToAsync(memoryStream); string photoname = comicInfo.File.FormFile.FileName; comicInfo.Extension = Path.GetExtension(photoname); if (!".jpg.jpeg.png.gif.bmp".Contains(comicInfo.Extension.ToLower())) { ModelState.AddModelError("File.FormFile", "Invalid Format of Image Given."); } else { ModelState.Remove("Extension"); } } if (ModelState.IsValid) { _context.Add(comicInfo); await _context.SaveChangesAsync(); var uploadsRootFolder = Path.Combine(_environment.WebRootPath, "photos"); if (!Directory.Exists(uploadsRootFolder)) { Directory.CreateDirectory(uploadsRootFolder); } string filename = comicInfo.ComicID + comicInfo.Extension; var filePath = Path.Combine(uploadsRootFolder, filename); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await comicInfo.File.FormFile.CopyToAsync(fileStream).ConfigureAwait(false); } return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.ComicCategories, "CategoryID", "CategoryName", comicInfo.CategoryID); ViewData["CompanyID"] = new SelectList(_context.ComicCompanies, "CompanyID", "CompanyName", comicInfo.CompanyID); return(View(comicInfo)); }
public ComicInfo LoadUri(Uri Uri) { CurrentUrl = Uri.AbsoluteUri.TrimEnd('/'); if (CurrentUrl.Contains("/page-")) { CurrentUrl = CurrentUrl.Substring(0, CurrentUrl.ToLower().IndexOf("/page-")); } CurrentUrl += "/page-1"; Document = new HtmlDocument(); Document.LoadUrl(Uri); ComicInfo Info = new ComicInfo(); Info.Title = HttpUtility.HtmlDecode(Document.SelectSingleNode("//h1[@class=\"name bigger\"]").InnerText); Info.Cover = Document .SelectSingleNode("//div[@class=\"comic-info\"]//img") .GetAttributeValue("src", "").TryDownload(); Info.ContentType = ContentType.Comic; return(Info); }
public ComicInfo LoadUri(Uri Uri) { Document = new HtmlDocument(); Document.LoadUrl(Uri); ComicInfo Info = new ComicInfo(); Info.Title = Document.SelectSingleNode("//span[@class='title']").InnerText; var Node = Document.SelectSingleNode("//div[@class='cover']/img"); string CLink = Node.GetAttributeValue("data-cfsrc", null); if (CLink == null) { CLink = Node.GetAttributeValue("src", null); } Info.Cover = new Uri(HttpUtility.HtmlDecode(CLink)).TryDownload(); Info.ContentType = ContentType.Comic; return(Info); }
public ComicInfo LoadUri(Uri Uri) { Document = LoadDocument(Uri.AbsoluteUri); OriUrl = Uri.AbsoluteUri; if (!OriUrl.EndsWith("/")) { OriUrl += "/"; } ComicInfo Info = new ComicInfo(); Info.Title = Document.Descendants("title").First().InnerText.Split('|')[0]; Info.Title = HttpUtility.HtmlDecode(Info.Title); Info.Cover = new Uri(Document .SelectSingleNode("//div[@class=\"widget\"]//img") .GetAttributeValue("src", string.Empty)).TryDownload(CFData); Info.ContentType = ContentType.Comic; return(Info); }
/// <summary> /// Publish comic information. /// </summary> /// <param name="comicInfo">The comic information.</param> public void Publish(ComicInfo comicInfo) { if (!_isRepairing && _options.DisableMetaInformation) return; using (var memoryStream = new MemoryStream()) { comicInfo.Save(memoryStream); memoryStream.Position = 0; _zipFile.BeginUpdate(); _zipFile.Add(new DataSource(memoryStream), "ComicInfo.xml"); _zipFile.CommitUpdate(); } }
private void ComicListFetchCompleted(object sender, DownloadStringCompletedEventArgs e) { WebClient wc = sender as WebClient; if (wc != null) { wc = null; } if (RESTError(e)) { Debug.WriteLine("Error fetching comic list! Error: " + e.Error.ToString()); return; } // Process JSON to get interesting data. DataContractJsonSerializer jsonparser = new DataContractJsonSerializer(typeof(PivotComicsData)); PivotComicsData serverComics = null; try { byte[] jsonArray = Encoding.UTF8.GetBytes(e.Result); MemoryStream jsonStream = new MemoryStream(jsonArray); serverComics = (PivotComicsData)jsonparser.ReadObject(jsonStream); } catch (SerializationException) { Debug.WriteLine("Cannot serialize the JSON. Giving up! Json: " + e.Result); return; } // Populate the model with comic data. IEnumerator <ComicInfo> enumerator = serverComics.comics.GetEnumerator(); while (enumerator.MoveNext()) { ComicInfo comic = enumerator.Current; ComicItem model = new ComicItem(); model.ComicName = comic.name; model.ComicId = comic.comicid; Debug.WriteLine("Got comic from server. Name: " + comic.name + ", id: " + comic.comicid); App.comicListModel.addComic(model); } // Check to see if we have some comic in the DB which is not present on the server. Need to remove that. Collection <ComicItem> comicsInDB = App.comicListModel.AllComicsListModel; IEnumerator <ComicInfo> serverComicsEnum = serverComics.comics.GetEnumerator(); foreach (ComicItem localComic in comicsInDB) { bool found = false; while (serverComicsEnum.MoveNext()) { ComicInfo serverComic = serverComicsEnum.Current; if (localComic.ComicId == serverComic.comicid) { found = true; break; } } if (!found) { Debug.WriteLine("Server does not contain the comic anymore. Removing locally: " + localComic.ComicName); App.comicListModel.removeComicItem(localComic); } serverComicsEnum.Reset(); } // Activate the first comic after the pivots have been populated. if (TopPivot.Items.Count > 0) { TopPivot.SelectedItem = TopPivot.Items[0]; } }
public static void GenerateReaderIndex(ILanguage[] Language, ILanguage CurrentLanguage, ComicInfo Info, string ComicDir, string ChapterName) { string IndexPath = MatchFile(ComicDir, CurrentLanguage.Index + ".html", (from x in Language select x.Index + ".html").ToArray()); string CoverName = MatchFile(ComicDir, CurrentLanguage.Cover + ".png", (from x in Language select x.Cover + ".png").ToArray(), false); string CoverPath = Path.Combine(ComicDir, CoverName); if (!File.Exists(IndexPath)) { string Base = string.Format(Properties.Resources.ComicReaderIndexBase, HttpUtility.HtmlEncode(Info.Title), $".{Path.AltDirectorySeparatorChar}{CoverName}"); File.WriteAllText(IndexPath, Base, Encoding.UTF8); } if (!File.Exists(CoverPath)) { using (MemoryStream Stream = new MemoryStream(Info.Cover)) { Bitmap Cover = Image.FromStream(Stream) as Bitmap; Cover.Save(CoverPath, ImageFormat.Png); } } string Content = null; string New = File.ReadAllText(IndexPath, Encoding.UTF8); while (New != Content) { Content = New; New = Content.TrimEnd('\r', '\n', ' ', '\t'); string[] Sufixes = new string[] { "</html>", "</body>", "</div>" }; foreach (string Sufix in Sufixes) { if (New.ToLower().EndsWith(Sufix)) { New = New.Substring(0, New.Length - Sufix.Length); } } } GetChapterPath(Language, CurrentLanguage, ComicDir, ChapterName, out string ChapterPath, false); New += "\r\n" + string.Format(Properties.Resources.ComicReaderIndexChapterBase, $".{Path.AltDirectorySeparatorChar}{ChapterPath}.html", HttpUtility.HtmlEncode(string.Format(CurrentLanguage.ChapterName, ChapterName))) + "\r\n"; New += " </div>\r\n </body>\r\n</html>"; File.WriteAllText(IndexPath, New, Encoding.UTF8); }
public static void ScanLibrary() { List <Comic> comicsToAddToDb = new List <Comic>(); foreach (string comicPath in Directory.GetDirectories(LIBRARY_PATH)) { Comic comic = new Comic(comicPath); // search db.bin string[] dbFiles = Directory.GetFiles(comicPath, "db.bin"); if (dbFiles.Length > 0) { if (dbFiles.Length > 1) { Console.Error.WriteLine("Found conflicting db.bin files in directory " + comicPath); } else { // read comic info from db.bin comic.ComicInfo = ComicInfo.FromBinary(Path.Combine(comicPath, "db.bin")); // safety check for comic id if (comic.ComicInfo.Id == 0) { Console.WriteLine("Broken id for comic '" + comic.ComicInfo.Title + "'"); } // add comic to comics dictionary if (comics.ContainsKey(comic.ComicInfo.Id)) { Console.Error.WriteLine("Multiple comics with the same id exist. Offender: '" + comic.ComicInfo.Title + "' "); continue; } comics.Add(comic.ComicInfo.Id, comic); } } else { comicsToAddToDb.Add(comic); } } // add db.bin for comics without it uint highestId = comics.Count > 0 ? comics.Aggregate((x, y) => x.Key > y.Key ? x : y).Key : 0; // gets the highest existing key foreach (Comic comic in comicsToAddToDb) { highestId++; ComicInfo ci = new ComicInfo() { Id = highestId, Title = Path.GetFileName(comic.ComicDirectory) }; comic.ComicInfo = ci; comics.Add(comic.ComicInfo.Id, comic); // Save ComicInfo ci.ToBinaryFile(Path.Combine(comic.ComicDirectory, "db.bin")); } }
/// <summary> /// Run in single processing mode for the location. /// </summary> /// <param name="location">The location.</param> /// <param name="options">The collection of options.</param> public static void Single(string location, Options options) { var provider = Providers.FirstOrDefault(x => x.Open(location) != null); if (provider == null) return; using (var series = provider.Open(location)) { using (series.Populate()) { var seriesTitle = series.Title.InvalidatePath(); var persistencePath = Path.Combine(seriesTitle, ".mangarack-persist"); var persistence = new List<List<string>>(); if (File.Exists(persistencePath)) { const int persistenceVersion = 2; foreach (var pieces in File.ReadAllLines(persistencePath).Select(line => new List<string>(line.Split('\0')))) { while (pieces.Count < persistenceVersion) pieces.Add(string.Empty); persistence.Add(pieces); } } foreach (var chapter in series.Children) { var line = persistence.FirstOrDefault(x => string.Equals(x[1], chapter.UniqueIdentifier)); if (line == null) continue; var currentFilePath = Path.Combine(seriesTitle, line[0]); var nextFileName = chapter.ToFileName(seriesTitle, options); if (!string.Equals(line[0], nextFileName) && File.Exists(currentFilePath)) { File.Move(currentFilePath, Path.Combine(seriesTitle, nextFileName)); line[0] = nextFileName; Persist(persistencePath, persistence); Console.WriteLine("Switched {0}", nextFileName); } } foreach (var chapter in series.Children.Filter(options)) { var hasFailed = false; var fileName = chapter.ToFileName(seriesTitle, options); var filePath = Path.Combine(seriesTitle, fileName); var persistenceFile = persistence.FirstOrDefault(x => string.Equals(x[0], fileName)); if (options.EnablePersistentSynchronization && persistenceFile != null) { continue; } if (persistenceFile != null) { persistenceFile[1] = chapter.UniqueIdentifier ?? string.Empty; } else { persistence.Add(new List<string> {fileName, chapter.UniqueIdentifier ?? string.Empty}); } do { if (options.DisableDuplicationPrevention || !File.Exists(filePath)) { using (chapter.Populate()) { using (var publisher = new Publisher(filePath, options, provider)) { using (var synchronizer = new Synchronize(publisher, series, chapter)) { synchronizer.Populate(); hasFailed = false; } } } } else { if (options.EnableOverwriteMetaInformation) { var comicInfo = new ComicInfo(); using (var zipFile = new ZipFile(filePath)) { var zipEntry = zipFile.GetEntry("ComicInfo.xml"); if (zipEntry != null) { var previousComicInfo = ComicInfo.Load(zipFile.GetInputStream(zipEntry)); comicInfo.Transcribe(series, chapter, previousComicInfo.Pages); if (comicInfo.Genre.Any(x => !previousComicInfo.Genre.Contains(x)) || previousComicInfo.Genre.Any(x => !comicInfo.Genre.Contains(x)) || comicInfo.Manga != previousComicInfo.Manga || comicInfo.Number != previousComicInfo.Number || comicInfo.PageCount != previousComicInfo.PageCount || comicInfo.Penciller.Any(x => !previousComicInfo.Penciller.Contains(x)) || previousComicInfo.Penciller.Any(x => !comicInfo.Penciller.Contains(x)) || comicInfo.Series != previousComicInfo.Series || comicInfo.Summary != previousComicInfo.Summary || comicInfo.Title != previousComicInfo.Title || comicInfo.Volume != previousComicInfo.Volume || comicInfo.Writer.Any(x => !previousComicInfo.Writer.Contains(x)) || previousComicInfo.Writer.Any(x => !comicInfo.Writer.Contains(x))) { using (var memoryStream = new MemoryStream()) { comicInfo.Save(memoryStream); memoryStream.Position = 0; zipFile.BeginUpdate(); zipFile.Add(new DataSource(memoryStream), "ComicInfo.xml"); zipFile.CommitUpdate(); Console.WriteLine("Modified {0}", fileName); } } } } } if (!options.DisableRepairAndErrorTracking && File.Exists(string.Format("{0}.txt", filePath))) { using (chapter.Populate()) { ComicInfo comicInfo; var hasBrokenPages = false; using (var zipFile = new ZipFile(filePath)) { var zipEntry = zipFile.GetEntry("ComicInfo.xml"); if (zipEntry == null) { return; } comicInfo = ComicInfo.Load(zipFile.GetInputStream(zipEntry)); } using (var publisher = new Publisher(filePath, options, provider, true)) { using (var repair = new Repair(publisher, chapter, comicInfo, File.ReadAllLines(string.Format("{0}.txt", filePath)))) { repair.Populate(); hasBrokenPages = publisher.HasBrokenPages; hasFailed = publisher.HasFailed = repair.HasFailed; } } if (!hasBrokenPages && File.Exists(string.Format("{0}.txt", filePath))) { File.Delete(string.Format("{0}.txt", filePath)); } } } } } while (hasFailed); Persist(persistencePath, persistence); } } } }