/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel() { _epubFile = new EpubFile(); BrowseCommand = new RelayCommand(Browse); ViewFileCommand = new RelayCommand(ViewFile); SaveZipCommand = new RelayCommand(SaveZip, CanSaveZip); if (!Storage.StorageExists()) { Storage.CreateFile(); } string folder = Storage.GetLastFolder(); if (!string.IsNullOrEmpty(folder)) { if (Directory.Exists(folder)) { _files = GetFileInfo(folder); Folder = folder; RaisePropertyChanged("Folder"); RaisePropertyChanged("Files"); } } }
public ProjectInfo(String epubPath, String projPath) { ProjectPath = Project.GetDirectory(projPath); ProjectName = Path.GetFileNameWithoutExtension(ProjectPath); EpubProjectPath = Path.Combine(ProjectPath, ProjectName + ".epubproj"); EpubName = Path.GetFileName(epubPath); File.Copy(epubPath, EpubPath); PackageName = EpubFile.GetOpfDirectory(); Project.Synthesizer.TempPath = TempPath; _DictionaryName = "Dictionary.txt"; Dictionary = new Dictionary <String, List <String> >(); using (StreamReader streamReader = new StreamReader(ProjectProperties.DictionaryPath)) { while (!streamReader.EndOfStream) { String[] line = streamReader.ReadLine().Split(' '); if (Dictionary.ContainsKey(line[0])) { Dictionary[line[0]].AddRange(line); } else { Dictionary.Add(line[0], line.ToList()); } Dictionary[line[0]] = Dictionary[line[0]].Distinct().ToList(); } streamReader.Close(); } Contents = new List <Content>(); Speed = 1; }
public void CanReadIdentifiers() { using (var data = new EpubFile(_ePubPath)) { Assert.Equal(2, data.Identifiers.Count); Assert.Equal("B000Q3ECHS", data.Identifiers.First(r => r.Key == "AMAZON").Value); } }
public Epub2Comment(string path) { if (!File.Exists(path)) { throw new Exception("File not exits!"); } epub = new EpubFile(path); }
public Epub2Comment(string path) { if (!File.Exists(path)) { throw new Exception("File not exits!"); } epub = new EpubFile(path); output_path = "output_epub2comment_" + Util.FilenameCheck(epub.title) + "/"; }
public void CaReadAuthors() { using (var data = new EpubFile(_ePubPath)) { Assert.Equal(1, data.Authors.Count); var author = data.Authors.First(); Assert.Equal("Charles Dickens", author); } }
private static bool FileNameMatches(EpubFile file, string[] htmlFileName) { for (int i = 0; i < htmlFileName.Length; i++) { if (file.FileName() == htmlFileName[i]) { return(true); } } return(false); }
public void CanReadTitles() { using (var data = new EpubFile(_ePubPath)) { var main = data.Titles.FirstOrDefault(n => n.Key == "main").Value; Assert.Equal("A Christmas Carol in Prose", main); var subtitle = data.Titles.FirstOrDefault(n => n.Key == "subtitle").Value; Assert.Equal("Being a Ghost Story of Christmas", subtitle); } }
public async Task <IActionResult> DownloadFile(EpubFile epubFile) { if (!System.IO.File.Exists(epubFile.FilePath)) { return(Redirect("/FileNotFound")); } byte[] byteFile = await System.IO.File.ReadAllBytesAsync(epubFile.FilePath); await ClearEpubFile(epubFile.FilePath); return(File(byteFile, "application/epub+zip", $"{epubFile.BookTitle}.epub")); }
public static string FileName(this EpubFile epub) { var str = epub.AbsolutePath; var lastIndex = str.LastIndexOf('/'); if (lastIndex < 0) { return(str); } var retval = str.Substring(lastIndex + 1); return(retval); }
public void CanReadDates() { using (var data = new EpubFile(_ePubPath)) { Assert.Equal(2, data.Dates.Count); var pubDate = data.Dates.FirstOrDefault(r => r.Key == "publication").Value; Assert.Equal(new DateTime(2004, 8, 11), pubDate); // 2015-11-01T05:08:31.408827+00:00 var conversion = data.Dates.FirstOrDefault(r => r.Key == "conversion").Value; Assert.Equal(new DateTime(2015, 11, 1), conversion.Date); } }
public async Task <IActionResult> CreateEpub(EpubFile epubFile) { epubFile.guid = Guid.NewGuid(); epubFile.FilePath = Path.Combine(_downloadRoot, $@"{epubFile.guid}.epub"); if (!ModelState.IsValid) { return(RedirectToAction("BadUrls")); } if (await GetEpub(epubFile)) { _fileManagerService.epubFileLocationTimeStamps.Add(epubFile.FilePath, DateTime.Now); return(RedirectToAction("DownloadPage", epubFile)); } return(Redirect("/ConversionFail")); }
private void AssertContentFile(EpubFile expected, EpubFile actual) { Assert.True(expected.Content.SequenceEqual(actual.Content)); Assert.Equal(expected.ContentType, actual.ContentType); Assert.Equal(expected.FileName, actual.FileName); Assert.Equal(expected.MimeType, actual.MimeType); var castedOld = expected as EpubTextFile; var castedNew = actual as EpubTextFile; Assert.Equal(castedOld == null, castedNew == null); if (castedOld != null && castedNew != null) { Assert.Equal(castedOld.TextContent, castedNew.TextContent); } }
private void AssertContentFile(EpubFile expected, EpubFile actual, string name) { Assert.IsTrue(expected.Content.SequenceEqual(actual.Content), $"{name}.Content"); Assert.AreEqual(expected.ContentType, actual.ContentType, $"{name}.ContentType"); Assert.AreEqual(expected.FileName, actual.FileName, $"{name}.FileName"); Assert.AreEqual(expected.MimeType, actual.MimeType, $"{name}.MimeType"); var castedOld = expected as EpubTextFile; var castedNew = actual as EpubTextFile; Assert.AreEqual(castedOld == null, castedNew == null); if (castedOld != null && castedNew != null) { Assert.AreEqual(castedOld.TextContent, castedNew.TextContent, $"{name}.TextContent"); } }
public static void RenameEpub(string path) { EpubFile epub = new EpubFile(path); string[] creators = epub.creators; string creatorStr = ""; if (creators.Length > 0) { creatorStr = $"[{creators[0]}] "; //creatorStr = $"[{String.Join(',',creators)}] "; } string dstFilename = creatorStr + epub.title + ".epub"; dstFilename = Util.FilenameCheck(dstFilename); File.Move(path, Path.Combine(Path.GetDirectoryName(path), dstFilename)); Log.Info(path + " -> " + dstFilename); }
private static EpubFile CreateEpub(string epubPath, string rightsFile = null) { var epub = new EpubFile(epubPath, false); epub.EncryptionProvider = new AesEncryptionProvider(new TestCryptoKeyProvider(epub.Isbn, new Guid("F588C946-386F-4A49-A333-64A189D07DD4"))); if (!string.IsNullOrEmpty(rightsFile)) { epub.DrmPermissionsProvider = new TestPermissionsProvider(rightsFile); } // add these EPUB parts to the encryption exempt list epub.DrmExemptParts.Add(epub.PackagePath); epub.DrmExemptParts.Add(epub.TocPath); epub.DrmExemptParts.Add(epub.CoverImagePath); epub.DrmExemptParts.Add(epub.CoverPagePath); return(epub); }
public static void Proc(string path) { Directory.CreateDirectory(output_dir); if (!File.Exists(path)) { Log.Error("[Error]File not exits!"); return; } EpubFile e = new EpubFile(path); e.items.ForEach( (i) => { if (typeof(TextEpubItemFile) == i.GetType() && i.fullName.EndsWith(".xhtml")) { ProcXHTML((TextEpubItemFile)i); } } ); }
private void SaveZip() { try { if (SelectedFile != null) { EpubFile epub = new EpubFile(); epub.Name = _selectedZipFileName; epub.Content = Content; ZipReader.UpdateZip(SelectedFile.FullName, epub); isDirty = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static bool FixupCss(EpubFile cssFile) { var changed = false; var css = System.Text.Encoding.UTF8.GetString(cssFile.Content); var parser = new StylesheetParser(); var sheet = parser.Parse(css); var cssBodyList = sheet.StyleRules.Where(rule => rule.SelectorText == "body"); foreach (var cssBody in cssBodyList) { var margin = cssBody.Style.Margin; if (margin != null && margin.Contains("%")) { changed = true; cssBody.Style.Margin = "1em"; } var marginLeft = cssBody.Style.MarginLeft; if (marginLeft != null && marginLeft.Contains("%")) { changed = true; cssBody.Style.MarginLeft = "0.5em"; } var marginRight = cssBody.Style.MarginRight; if (marginRight != null && marginRight.Contains("%")) { changed = true; cssBody.Style.MarginRight = "0.5em"; } } if (changed) { var newCss = sheet.ToCss(); var newBuffer = System.Text.Encoding.UTF8.GetBytes(newCss); cssFile.Content = newBuffer; } return(changed); }
public UnpackEpubManga(string epubPath) { epub = new EpubFile(epubPath); }
public void OnGet(string id) { id = id ?? "1f18bd7a-63ca-460e-972f-d81a061f1c99"; Input = (EpubFile)_epubManager.Create(id); }
public void CaReadRights() { using (var data = new EpubFile(_ePubPath)) { Assert.Equal("Public domain in the USA.", data.Rights[0]); } }
public void CaReadLanguages() { using (var data = new EpubFile(_ePubPath)) { Assert.Equal("en", data.Languages[0]); } }
public IActionResult DownloadPage(EpubFile epubFile) => View(epubFile);
public async Task <IActionResult> GoBackAndDelete(EpubFile epubFile) { await ClearEpubFile(epubFile.FilePath); return(RedirectToAction("CreateEpub")); }
public void DumpResult() { using (var data = new EpubFile(_ePubPath)) { Output.WriteLine(JsonConvert.SerializeObject(data, Formatting.Indented)); } }
public void CaReadSubjects() { using (var data = new EpubFile(_ePubPath)) { Assert.Equal(7, data.Subjects.Count); } }
public TocItem(EpubFile epub) { belongTo = epub; }
public async Task <bool> GetEpub(EpubFile EpubFile) { await _getEpub.FromAsync(EpubFile.WikiPages, _downloadRoot, EpubFile.BookTitle, EpubFile.guid); return(true); }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("AeroNovelTool by AE Ver." + Version.date); Console.ForegroundColor = ConsoleColor.White; if (args.Length >= 2) { switch (args[0].ToLower()) { case "epub": { if (!DirectoryExist(args[1])) { return; } var gen = new AeroNovelEpub.GenEpub(); for (int i = 2; i < args.Length; i++) { if (args[i] == "t2s") { gen = new AeroNovelEpub.GenEpub(AeroNovelEpub.ChineseConvertOption.T2S); } } EpubFile e = gen.Gen(args[1]); List <string> creators = new List <string>(); string dateString = DateTime.Today.ToString("yyyyMMdd"); e.dc_creators.ForEach((x) => { if (x.refines.Count > 0) { foreach (var refine in x.refines) { if (refine.name == "role") { if (refine.value != "aut") { return; } } } } creators.Add(x.value); }); try { e.meta.ForEach((x) => { if (x.name == "dcterms:modified") { dateString = x.value.Replace("-", "").Substring(0, 8); } }); } catch (ArgumentOutOfRangeException) { Log.Warn("Error at getting modified date in metadata"); } e.filename = $"[{string.Join(",", creators)}] {e.title} [{dateString}]"; if (args.Length >= 3 && DirectoryExist(args[2])) { e.Save(args[2]); } else { e.Save(""); } } break; case "txt": if (!DirectoryExist(args[1])) { return; } GenTxt.Gen(args[1]); break; case "bbcode": if (!DirectoryExist(args[1])) { return; } if (args.Length >= 3) { if (DirectoryExist(args[2])) { GenBbcode.output_path = Path.Combine(args[2], GenBbcode.output_path); GenBbcode.output_path_single = Path.Combine(args[2], GenBbcode.output_path_single); } } GenBbcode.GenSingle(args[1]); break; case "epub2comment": if (!FileExist(args[1])) { return; } Epub2Comment e2c = new Epub2Comment(args[1]); if (args.Length > 2) { switch (args[2]) { case "BlackTranslatingMagic": e2c.castBlackTranslatingMagic = true; break; case "Glossary": if (args.Length > 3) { e2c.glossaryDocPath = args[3]; } else { Log.Error("Should give glossary document."); } break; } } e2c.Proc(); break; case "epub2atxt": if (!FileExist(args[1])) { return; } Epub2Atxt.Proc(args[1]); break; case "html2comment": if (!FileExist(args[1])) { return; } Html2Comment.Proc(args[1]); break; case "atxt2bbcode": if (!FileExist(args[1])) { return; } GenBbcode.Proc(args[1]); break; case "kakuyomu2comment": { var xhtml = WebSource.KakuyomuEpisode(args[1]); var atxt = Html2Comment.ProcXHTML(xhtml.text); File.WriteAllText("output_kakuyomu2comment.txt", atxt); Log.Note("output_kakuyomu2comment.txt"); } break; case "websrc": { TextEpubItemFile[] xhtmls; string dirname = "output_websrc_"; if (args[1].Contains("kakuyomu.jp")) { xhtmls = WebSource.KakuyomuAuto(args[1]); dirname += "kakuyomu"; } else { Log.Error("什么网站"); break; } if (xhtmls != null) { Directory.CreateDirectory(dirname); foreach (var xhtml in xhtmls) { Save(xhtml, dirname); } } } break; case "atxtcc": { if (!FileExist(args[1])) { return; } bool t2s = false, s2t = false, replace = false; for (int i = 2; i < args.Length; i++) { switch (args[i]) { case "t2s": t2s = true; break; case "s2t": s2t = true; break; case "replace": replace = true; break; } } if (t2s) { AeroNovelEpub.AtxtChineseConvert.ProcT2C(args[1], replace); } else if (s2t) { //Not Implemented } } break; default: Log.Warn("Nothing happens. " + usage); break; } } else { Log.Warn(usage); } }