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"); }
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); } }