private void Submit_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(CoverUrl.Text) && CoverUrl.IsEnabled && !CoverUrl.Text.StartsWith(Path.GetTempPath())) { if (coverData != null) { // do nothing } else { byte[] coverBytes = CoverDownloader.BatchProc(CoverUrl.Text); if (coverBytes == null) { MessageBox.Show("Download Cover Error."); return; } SaveCoverToTempFile(coverBytes); } } Packet packet = new Packet(); packet.title = BookTitle.Text; packet.author = BookAuthor.Text; packet.simple = true; packet.chapters = new List <Chapter>(); foreach (dynamic tch in contents) { Chapter ch = new Chapter(); ch.id = tch.id; ch.title = tch.title; ch.author = BookAuthor.Text; ch.source = "TextRepack"; ch.savePath = ch.id + ".txt"; ch.timestamp = 0; packet.chapters.Add(ch); } packet.regexps = new List <string>(); foreach (dynamic ob in files) { packet.regexps.Add(ob.regex); } packet.chapters.Reverse(); packet.timestamp = 0; packet.key = Utils.CalcKey(packet.title, packet.author, true); packet.summary = Utils.CalcSumary(packet.title, packet.author, true, packet.chapters, coverData); packet.source = "TextRepack"; string folder = string.Format("{0}/packets", Constants.LOCAL_PATH); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string path = string.Format("{0}/{1}_{2}.zip", folder, packet.title, packet.author); PacketToZip(packet, path, contents, coverData); MessageBox.Show(string.Format("{0} saved.", path)); }
private void DownloadCover_Click(object sender, RoutedEventArgs e) { CoverDownloader downloader = new CoverDownloader(); downloader.CoverUrl.Text = CoverUrl.Text; if (downloader.ShowDialog() ?? true) { SaveCoverToTempFile(downloader.coverData); } }