private async Task btnKindleExtras_Run() { //Check current settings if (!File.Exists(txtMobi.Text)) { MessageBox.Show("Specified book was not found.", "Book Not Found"); return; } if (rdoGoodreads.Checked) { if (txtGoodreads.Text == "") { MessageBox.Show($"No {_dataSource.Name} link was specified.", $"Missing {_dataSource.Name} Link"); return; } if (!txtGoodreads.Text.ToLower().Contains(_settings.dataSource.ToLower())) { MessageBox.Show($"Invalid {_dataSource.Name} link was specified.\r\n" + $"If you do not want to use {_dataSource.Name}, you can change the data source in Settings." , $"Invalid {_dataSource.Name} Link"); return; } } if (_settings.realName.Trim().Length == 0 || _settings.penName.Trim().Length == 0) { MessageBox.Show( "Both Real and Pen names are required for End Action\r\n" + "file creation. This information allows you to rate this\r\n" + "book on Amazon. Please review the settings page.", "Amazon Customer Details Not found"); return; } var metadata = await Task.Run(() => UIFunctions.GetAndValidateMetadata(txtMobi.Text, _settings.outDir, _settings.saverawml)); if (metadata == null) { return; } SetDatasourceLabels(); // Reset the dataSource for the new build process Logger.Log($"Book's {_dataSource.Name} URL: {txtGoodreads.Text}"); try { BookInfo bookInfo = new BookInfo(metadata, txtGoodreads.Text); string outputDir = OutputDirectory(bookInfo.author, bookInfo.sidecarName, true); Logger.Log("Attempting to build Author Profile..."); AuthorProfile ap = new AuthorProfile(bookInfo, new AuthorProfile.Settings { AmazonTld = _settings.amazonTLD, Android = _settings.android, OutDir = _settings.outDir, SaveBio = _settings.saveBio, UseNewVersion = _settings.useNewVersion, UseSubDirectories = _settings.useSubDirectories }); if (!await ap.Generate()) { return; } SaPath = $@"{outputDir}\StartActions.data.{bookInfo.asin}.asc"; ApPath = $@"{outputDir}\AuthorProfile.profile.{bookInfo.asin}.asc"; Logger.Log("Attempting to build Start Actions and End Actions..."); EndActions ea = new EndActions(ap, bookInfo, metadata.RawMlSize, _dataSource, new EndActions.Settings { AmazonTld = _settings.amazonTLD, Android = _settings.android, OutDir = _settings.outDir, PenName = _settings.penName, RealName = _settings.realName, UseNewVersion = _settings.useNewVersion, UseSubDirectories = _settings.useSubDirectories }); if (!await ea.Generate()) { return; } if (_settings.useNewVersion) { await ea.GenerateNewFormatData(_progress, _cancelTokens.Token); // TODO: Do the templates differently Model.EndActions eaBase; try { var template = File.ReadAllText(Environment.CurrentDirectory + @"\dist\BaseEndActions.json", Encoding.UTF8); eaBase = JsonConvert.DeserializeObject <Model.EndActions>(template); } catch (FileNotFoundException) { Logger.Log(@"Unable to find dist\BaseEndActions.json, make sure it has been extracted!"); return; } catch (Exception e) { Logger.Log($@"An error occurred while loading dist\BaseEndActions.json (make sure any new versions have been extracted!)\r\n{e.Message}\r\n{e.StackTrace}"); return; } await ea.GenerateEndActionsFromBase(eaBase, _progress, _cancelTokens.Token); StartActions sa; try { var template = File.ReadAllText(Environment.CurrentDirectory + @"\dist\BaseStartActions.json", Encoding.UTF8); sa = JsonConvert.DeserializeObject <StartActions>(template); } catch (FileNotFoundException) { Logger.Log(@"Unable to find dist\BaseStartActions.json, make sure it has been extracted!"); return; } catch (Exception e) { Logger.Log($@"An error occurred while loading dist\BaseStartActions.json (make sure any new versions have been extracted!)\r\n{e.Message}\r\n{e.StackTrace}"); return; } // TODO: Separate out SA logic string saContent = null; if (_settings.downloadSA) { Logger.Log("Attempting to download Start Actions..."); try { saContent = await Amazon.DownloadStartActions(metadata.ASIN); } catch { Logger.Log("No pre-made Start Actions available, building..."); } } if (string.IsNullOrEmpty(saContent)) { saContent = ea.GenerateStartActionsFromBase(sa); } ea.WriteStartActions(saContent); cmsPreview.Items[3].Enabled = true; EaPath = $@"{outputDir}\EndActions.data.{bookInfo.asin}.asc"; } else { ea.GenerateOld(); } cmsPreview.Items[1].Enabled = true; checkFiles(bookInfo.author, bookInfo.title, bookInfo.asin); if (_settings.playSound) { System.Media.SoundPlayer player = new System.Media.SoundPlayer(Environment.CurrentDirectory + @"\done.wav"); player.Play(); } } catch (Exception ex) { Logger.Log("An error occurred while creating the new Author Profile, Start Actions, and/or End Actions files:\r\n" + ex.Message + "\r\n" + ex.StackTrace); } finally { metadata.Dispose(); } }
private void btnKindleExtras_Click(object sender, EventArgs e) { //Check current settings if (!File.Exists(txtMobi.Text)) { MessageBox.Show("Specified book was not found.", "Book Not Found"); return; } if (rdoShelfari.Checked && txtShelfari.Text == "") { MessageBox.Show("No Shelfari link was specified.", "Missing Shelfari Link"); return; } if (!File.Exists(settings.mobi_unpack)) { MessageBox.Show("Kindleunpack was not found. Please review the settings page.", "Kindleunpack Not Found"); return; } if (Properties.Settings.Default.realName.Trim().Length == 0 | Properties.Settings.Default.penName.Trim().Length == 0) { MessageBox.Show( "Both Real and Pen names are required for End Action\r\n" + "file creation. This information allows you to rate this\r\n" + "book on Amazon. Please review the settings page.", "Amazon Customer Details Not found"); return; } //Create temp dir and ensure it exists string randomFile = Functions.GetTempDirectory(); if (!Directory.Exists(randomFile)) { MessageBox.Show("Temporary path not accessible for some reason.", "Temporary Directory Error"); return; } //0 = asin, 1 = uniqid, 2 = databasename, 3 = rawML, 4 = author, 5 = title List<string> results; long rawMLSize = 0; if (settings.useKindleUnpack) { Log("Running Kindleunpack to get metadata..."); results = Functions.GetMetaData(txtMobi.Text, settings.outDir, randomFile, settings.mobi_unpack); if (!File.Exists(results[3])) { Log("Error: RawML could not be found, aborting.\r\nPath: " + results[3]); return; } rawMLSize = new FileInfo(results[3]).Length; } else { Log("Extracting metadata..."); try { Unpack.Metadata md = Functions.GetMetaDataInternal(txtMobi.Text, settings.outDir, false); rawMLSize = md.PDH.TextLength; results = md.getResults(); } catch (Exception ex) { Log("Error getting metadata: " + ex.Message); return; } } if (results.Count != 6) { Log(results[0]); return; } if (settings.saverawml && settings.useKindleUnpack) { Log("Saving rawML to dmp directory..."); File.Copy(results[3], Path.Combine(Environment.CurrentDirectory + @"\dmp", Path.GetFileName(results[3])), true); } // Added author name to log output Log(String.Format("Got metadata!\r\nDatabase Name: {0}\r\nASIN: {1}\r\nAuthor: {2}\r\nTitle: {3}\r\nUniqueID: {4}", results[2], results[0], results[4], results[5], results[1])); try { BookInfo bookInfo = new BookInfo(results[5], results[4], results[0], results[1], results[2], randomFile, Path.GetFileNameWithoutExtension(txtMobi.Text), txtShelfari.Text); Log("Attempting to build Author Profile..."); AuthorProfile ap = new AuthorProfile(bookInfo, this); if (!ap.complete) return; Log("Attempting to build Start Actions and End Actions..."); EndActions ea = new EndActions(ap, bookInfo, rawMLSize, this); if (!ea.complete) return; if (settings.useNewVersion) { ea.GenerateNew(); Log("Attempting to build Start Actions..."); ea.GenerateStartActions(); } else ea.GenerateOld(); if (Properties.Settings.Default.playSound) { System.Media.SoundPlayer player = new System.Media.SoundPlayer(Environment.CurrentDirectory + @"\done.wav"); player.Play(); } try { PopulateAPEAPreviews(ap, ea); } catch (Exception ex) { Log("Error populating extras preview windows: " + ex.Message); } } catch (Exception ex) { Log("An error occurred while creating the new Author Profile, Start Actions, and/or End Actions files: " + ex.Message); } }
private void btnKindleExtras_Click(object sender, EventArgs e) { //Check current settings if (!File.Exists(txtMobi.Text)) { MessageBox.Show("Specified book was not found.", "Book Not Found"); return; } if (rdoShelfari.Checked && txtShelfari.Text == "") { MessageBox.Show("No Shelfari link was specified.", "Missing Shelfari Link"); return; } if (!File.Exists(settings.mobi_unpack)) { MessageBox.Show("Kindleunpack was not found. Please review the settings page.", "Kindleunpack Not Found"); return; } if (Properties.Settings.Default.realName.Trim().Length == 0 | Properties.Settings.Default.penName.Trim().Length == 0) { MessageBox.Show( "Both Real and Pen names are required for End Action\r\n" + "file creation. This information allows you to rate this\r\n" + "book on Amazon. Please review the settings page.", "Amazon Customer Details Not found"); return; } //Create temp dir and ensure it exists string randomFile = Functions.GetTempDirectory(); if (!Directory.Exists(randomFile)) { MessageBox.Show("Temporary path not accessible for some reason.", "Temporary Directory Error"); return; } //0 = asin, 1 = uniqid, 2 = databasename, 3 = rawML, 4 = author, 5 = title List <string> results; long rawMLSize = 0; if (settings.useKindleUnpack) { Log("Running Kindleunpack to get metadata..."); results = Functions.GetMetaData(txtMobi.Text, settings.outDir, randomFile, settings.mobi_unpack); if (!File.Exists(results[3])) { Log("Error: RawML could not be found, aborting.\r\nPath: " + results[3]); return; } rawMLSize = new FileInfo(results[3]).Length; } else { Log("Extracting metadata..."); try { Unpack.Metadata md = Functions.GetMetaDataInternal(txtMobi.Text, settings.outDir, false); rawMLSize = md.PDH.TextLength; results = md.getResults(); } catch (Exception ex) { Log("Error getting metadata: " + ex.Message); return; } } if (results.Count != 6) { Log(results[0]); return; } if (settings.saverawml && settings.useKindleUnpack) { Log("Saving rawML to dmp directory..."); File.Copy(results[3], Path.Combine(Environment.CurrentDirectory + @"\dmp", Path.GetFileName(results[3])), true); } // Added author name to log output Log(String.Format("Got metadata!\r\nDatabase Name: {0}\r\nASIN: {1}\r\nAuthor: {2}\r\nTitle: {3}\r\nUniqueID: {4}", results[2], results[0], results[4], results[5], results[1])); try { BookInfo bookInfo = new BookInfo(results[5], results[4], results[0], results[1], results[2], randomFile, Functions.RemoveInvalidFileChars(results[5]), txtShelfari.Text); Log("Attempting to build Author Profile..."); AuthorProfile ap = new AuthorProfile(bookInfo, this); if (!ap.complete) { return; } Log("Attempting to build Start Actions and End Actions..."); EndActions ea = new EndActions(ap, bookInfo, rawMLSize, this); if (!ea.complete) { return; } if (settings.useNewVersion) { ea.GenerateNew(); Log("Attempting to build Start Actions..."); ea.GenerateStartActions(); } else { ea.GenerateOld(); } if (Properties.Settings.Default.playSound) { System.Media.SoundPlayer player = new System.Media.SoundPlayer(Environment.CurrentDirectory + @"\done.wav"); player.Play(); } try { PopulateAPEAPreviews(ap, ea); } catch (Exception ex) { Log("Error populating extras preview windows: " + ex.Message); } } catch (Exception ex) { Log("An error occurred while creating the new Author Profile, Start Actions, and/or End Actions files: " + ex.Message); } }