static void DumpHDImage(string[] args) { Log.log("Dump azw.res"); Log.log("azw6 source:" + args[0]); string outputdir = ""; if (!File.Exists(args[0])) { Log.log("File was not found:" + args[0]); return; } Azw6File azw = new Azw6File(args[0]); if (args.Length >= 3) { outputdir = args[1]; } else { outputdir = Path.Combine(Path.GetDirectoryName(args[0]), azw.header.title); } if (!CreateDirectory(outputdir)) { return; } foreach (var a in azw.image_sections) { CRES_Section sec = (CRES_Section)azw.sections[a]; string filename = Epub.ImageNameHD(a - 1, sec); File.WriteAllBytes(Path.Combine(outputdir, filename), sec.img); Log.log("Saved:" + Path.Combine(outputdir, filename)); } }
public Epub(Azw3File azw3, Azw6File azw6 = null) { this.azw3 = azw3; this.azw6 = azw6; azw3.flowProcessLog = new string[azw3.flows.Count]; for (int i = 0; i < azw3.xhtmls.Count; i++) { xhtml_names.Add("part" + Util.Number(i) + ".xhtml"); } foreach (string xhtml in azw3.xhtmls) { var doc = LoadXhtml(xhtml); xhtmls.Add(doc); ProcNodes(doc.DocumentElement); } try { CreateNCX(); CreateNAV(); } catch (Exception e) { Log.log("[Error]Cannot Create NCX or NAV."); Log.log("[Error]" + e.ToString()); } CreateCover(); CreateOPF(); { UInt64 thumb_offset = 0; if (azw3.mobi_header.extMeta.id_value.TryGetValue(202, out thumb_offset)) { azw3.sections[azw3.mobi_header.first_res_index + thumb_offset].comment = "Thumb Cover, Ignored"; } } }
public Epub(Azw3File azw3, Azw6File azw6 = null) { this.azw3 = azw3; this.azw6 = azw6; azw3.flowProcessLog = new string[azw3.flows.Count]; for (int i = 0; i < azw3.xhtmls.Count; i++) { xhtml_names.Add("part" + Util.Number(i) + ".xhtml"); } foreach (string xhtml in azw3.xhtmls) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xhtml); xhtmls.Add(doc); ProcNodes(doc.DocumentElement); } CreateNCX(); CreateCover(); CreateOPF(); { uint thumb_offset = 0; if (azw3.mobi_header.extMeta.id_value.TryGetValue(202, out thumb_offset)) { azw3.sections[azw3.mobi_header.first_res_index + thumb_offset].comment = "Thumb Cover, Ignored"; } } }
static void test() { Azw6File azw6 = new Azw6File(@"sample.azw.res"); Azw3File azw3 = new Azw3File(@"sample_nodrm.azw3"); Epub mainfile = new Epub(azw3, azw6); mainfile.Save("temp"); }
public Epub(Azw3File azw3, Azw6File azw6, bool rename_xhtml_with_id) { this.azw3 = azw3; this.azw6 = azw6; renameXhtmlWithId = rename_xhtml_with_id; azw3.flowProcessLog = new string[azw3.flows.Count]; for (int i = 0; i < azw3.xhtmls.Count; i++) { xhtml_names.Add("part" + Util.Number(i) + ".xhtml"); } if (renameXhtmlWithId) { Log.log("[Info]Rename xhtmls with id."); int i = 0, offset = 0; if (NeedCreateCoverDocument()) { i = 1; offset = -1; } var itemrefs = azw3.resc.spine.FirstChild.ChildNodes; for (; (i + offset < xhtml_names.Count) && (i < itemrefs.Count); i++) { var id = itemrefs[i].Attributes.GetNamedItem("idref").Value; xhtml_names[i + offset] = id + ".xhtml"; } } foreach (string xhtml in azw3.xhtmls) { var doc = LoadXhtml(xhtml); xhtmls.Add(doc); ProcNodes(doc.DocumentElement); } try { CreateIndexDoc(); } catch (Exception e) { Log.log("[Error]Cannot Create NCX or NAV."); Log.log("[Error]" + e.ToString()); } SetCover(); CreateOPF(); { UInt64 thumb_offset = 0; if (azw3.mobi_header.extMeta.id_value.TryGetValue(202, out thumb_offset)) { azw3.sections[azw3.mobi_header.first_res_index + thumb_offset].comment = "Thumb Cover, Ignored"; } } }
static void ProcPath(string[] args) { string azw3_path = null; string azw6_path = null; string dir; string p = args[0]; if (Directory.Exists(p)) { string[] files = Directory.GetFiles(p); if (dedrm) { foreach (string n in files) { if (Path.GetExtension(n).ToLower() == ".azw") { DeDRM(n); } } files = Directory.GetFiles(p); } foreach (string n in files) { if (Path.GetExtension(n).ToLower() == ".azw3") { azw3_path = n; } if (Path.GetExtension(n) == ".res") { azw6_path = n; } } } else if (Path.GetExtension(p).ToLower() == ".azw3") { azw3_path = p; dir = Path.GetDirectoryName(p); string[] files = Directory.GetFiles(dir); foreach (string n in files) { if (Path.GetExtension(n) == ".res") { azw6_path = n; break; } } } else if (Path.GetExtension(p).ToLower() == ".res") { azw6_path = p; dir = Path.GetDirectoryName(p); string[] files = Directory.GetFiles(dir); foreach (string n in files) { if (Path.GetExtension(n).ToLower() == ".azw3") { azw3_path = n; break; } } } Azw3File azw3 = null; Azw6File azw6 = null; if (azw3_path != null) { Log.log("==============START==============="); azw3 = new Azw3File(azw3_path); } if (azw6_path != null) { azw6 = new Azw6File(azw6_path); } if (azw3 != null) { string outname = "[" + azw3.mobi_header.extMeta.id_string[100].Split('&')[0] + "] " + azw3.title + ".epub"; Epub epub = new Epub(azw3, azw6); if (Directory.Exists("temp")) { DeleteDir("temp"); } Directory.CreateDirectory("temp"); epub.Save("temp"); Log.log(azw3); string output_path; if (args.Length >= 2) { if (Directory.Exists(args[1])) { output_path = Path.Combine(args[1], outname); } } { string outdir = Path.GetDirectoryName(args[0]); output_path = Path.Combine(outdir, outname); } Util.Packup(output_path); Log.log("azw3 source:" + azw3_path); if (azw6_path != null) { Log.log("azw6 source:" + azw6_path); } } else { Console.WriteLine("Cannot find .azw3 file in " + p); } }
static void ProcPath(string[] args) { string azw3_path = null; string azw6_path = null; string dir; string p = args[0]; if (Directory.Exists(p)) { string[] files = Directory.GetFiles(p); if (dedrm) { foreach (string n in files) { if (Path.GetExtension(n).ToLower() == ".azw") { DeDRM(n); } } files = Directory.GetFiles(p); } foreach (string n in files) { if (Path.GetExtension(n).ToLower() == ".azw3") { azw3_path = n; } if (Path.GetExtension(n) == ".res") { azw6_path = n; } } } else { if (dedrm && Path.GetExtension(p).ToLower() == ".azw") { DeDRM(p); dir = Path.GetDirectoryName(p); string[] files = Directory.GetFiles(dir); foreach (string n in files) { if (Path.GetExtension(n) == ".res") { azw6_path = n; } if (Path.GetExtension(n).ToLower() == ".azw3") { azw3_path = n; } } } else if (Path.GetExtension(p).ToLower() == ".azw3") { azw3_path = p; dir = Path.GetDirectoryName(p); string[] files = Directory.GetFiles(dir); foreach (string n in files) { if (Path.GetExtension(n) == ".res") { azw6_path = n; break; } } } else if (Path.GetExtension(p).ToLower() == ".res") { azw6_path = p; dir = Path.GetDirectoryName(p); string[] files = Directory.GetFiles(dir); foreach (string n in files) { if (Path.GetExtension(n).ToLower() == ".azw3") { azw3_path = n; break; } } } } Azw3File azw3 = null; Azw6File azw6 = null; if (azw3_path != null) { Log.log("==============START==============="); azw3 = new Azw3File(azw3_path); } if (azw6_path != null) { azw6 = new Azw6File(azw6_path); } if (azw3 != null) { string auther = ""; if (azw3.mobi_header.extMeta.id_string.ContainsKey(100)) { auther = "[" + azw3.mobi_header.extMeta.id_string[100].Split('&')[0] + "] "; } string outname = auther + azw3.title + ".epub"; outname = Util.FilenameCheck(outname); Epub epub = new Epub(azw3, azw6, rename_xhtml_with_id); Log.log(azw3); string output_path; if (args.Length >= 2 && Directory.Exists(args[1])) { output_path = Path.Combine(args[1], outname); } else { string outdir = Path.GetDirectoryName(args[0]); output_path = Path.Combine(outdir, outname); } if (File.Exists(output_path)) { Log.log("[Warn]Output already exist."); if (rename_when_exist) { string r_dir = Path.GetDirectoryName(output_path); string r_name = Path.GetFileNameWithoutExtension(output_path); string r_path = Path.Combine(r_dir, r_name); output_path = ""; for (int i = 2; i < 50; i++) { string r_test = r_path + "(" + i + ").epub"; if (!File.Exists(r_test)) { output_path = r_test; break; } } Log.log("[Warn]Save as..."); } else if (!overwrite) { Console.WriteLine("Output file already exist. N(Abort,Defualt)/y(Overwrite)/r(Rename)?"); Console.WriteLine("Output path:" + output_path); string input = Console.ReadLine().ToLower(); if (input == "y") { Log.log("[Warn]Old file will be replaced."); } else if (input == "r") { string r_dir = Path.GetDirectoryName(output_path); string r_name = Path.GetFileNameWithoutExtension(output_path); string r_path = Path.Combine(r_dir, r_name); output_path = ""; for (int i = 2; i < 50; i++) { string r_test = r_path + "(" + i + ").epub"; if (!File.Exists(r_test)) { output_path = r_test; break; } } Log.log("[Warn]Save as..."); } else { Log.log("[Error]Operation aborted. You can use --overwrite or --rename-when-exist to avoid pause."); output_path = ""; } } else { Log.log("[Warn]Old file will be replaced."); } } if (output_path != "") { epub.Save(output_path); } Log.log("azw3 source:" + azw3_path); if (azw6_path != null) { Log.log("azw6 source:" + azw6_path); } } else { Console.WriteLine("Cannot find .azw3 file in " + p); } }