private void PopulateAPEAPreviews(AuthorProfile ap, EndActions ea)
        {
            ClearPreviews();

            frmAP.lblTitle.Text = ap.ApTitle;
            frmAP.pbAuthorImage.Image = ap.ApAuthorImage;

            var g = Graphics.FromHwnd(frmAP.lblBio1.Handle);
            int charFitted, linesFitted;
            g.MeasureString(ap.BioTrimmed, frmAP.lblBio1.Font, frmAP.lblBio1.Size,
                StringFormat.GenericTypographic, out charFitted, out linesFitted);

            if (ap.BioTrimmed != "")
            {
                if (ap.BioTrimmed.Length > charFitted)
                {
                    string bio1Trim = ap.BioTrimmed.Substring(0, Math.Min(ap.BioTrimmed.Length, charFitted - 10));
                    frmAP.lblBio1.Text = bio1Trim.Substring(0, bio1Trim.LastIndexOf(" "));
                    frmAP.lblBio2.Text = ap.BioTrimmed.Substring(bio1Trim.LastIndexOf(" ") + 1);
                }
                else
                    frmAP.lblBio1.Text = ap.BioTrimmed;
            }

            frmAP.lblKindleBooks.Text = ap.ApSubTitle;
            int numLabels = Math.Min(4, ap.otherBooks.Count);
            for (int i = 0; i < numLabels; i++)
            {
                frmAP.Controls["lblBook" + (i + 1)].Text = ap.otherBooks[i].title;
            }
            frmEA.lblPost.Text = String.Format("Post on Amazon (as {0}) and Goodreads",
                Properties.Settings.Default.penName);
            frmEA.lblMoreBooks.Text = ap.EaSubTitle;
            numLabels = Math.Min(5, ap.otherBooks.Count);
            for (int i = 0; i < numLabels; i++)
            {
                frmEA.Controls["lblBook" + (i + 1)].Text = ap.otherBooks[i].title;
            }
            if (ea.custAlsoBought.Count > 1)
            {
                frmEA.lblBook6.Text = ea.custAlsoBought[0].title;
                frmEA.lblAuthor1.Text = ea.custAlsoBought[0].author;
                frmEA.lblBook7.Text = ea.custAlsoBought[1].title;
                frmEA.lblAuthor2.Text = ea.custAlsoBought[1].author;
            }

            // StartActions preview
            if (ea.curBook.seriesName == "")
            {
                frmSA.lblBookTitle.Text = ea.curBook.title;
            }
            else
            {
                frmSA.lblBookTitle.Text = string.Format("{0} ({1} Book {2})", ea.curBook.title, ea.curBook.seriesName,
                    ea.curBook.seriesPosition);
            }
            frmSA.lblBookAuthor.Text = ea.curBook.author;
            //Convert rating to equivalent Star image
            string starNum = string.Format("STAR{0}",
                Math.Floor(ea.curBook.amazonRating).ToString());
            //Return an object from the star image in the project,
            //set the Image property of pbRating to the returned object as Image
            frmSA.pbRating.Image = (Image)Properties.Resources.ResourceManager.GetObject(starNum);
            frmSA.lblBookDesc.Text = ea.curBook.desc;
            frmSA.lblRead.Text = string.Format("{0} hours and {1} minutes", ea.curBook.readingHours, ea.curBook.readingMinutes);
            frmSA.lblPages.Text = string.Format("{0} pages", ea.curBook.pagesInBook);
            if (ea.curBook.seriesPosition != "")
                frmSA.lblSeries.Text = string.Format("This is book {0} of {1} in {2}",
                    ea.curBook.seriesPosition, ea.curBook.totalInSeries, ea.curBook.seriesName);
            else
                frmSA.lblSeries.Text = "This book is not part of a series.";
            frmSA.pbAuthorImage.Image = ap.ApAuthorImage;
            frmSA.lblAboutAuthor.Text = ea.curBook.author;
            frmSA.lblAuthorBio.Text = ap.BioTrimmed;
        }
        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);
            }

        }
Beispiel #3
0
        private void PopulateAPEAPreviews(AuthorProfile ap, EndActions ea)
        {
            ClearPreviews();

            frmAP.lblTitle.Text       = ap.ApTitle;
            frmAP.pbAuthorImage.Image = ap.ApAuthorImage;

            var g = Graphics.FromHwnd(frmAP.lblBio1.Handle);
            int charFitted, linesFitted;

            g.MeasureString(ap.BioTrimmed, frmAP.lblBio1.Font, frmAP.lblBio1.Size,
                            StringFormat.GenericTypographic, out charFitted, out linesFitted);

            if (ap.BioTrimmed != "")
            {
                if (ap.BioTrimmed.Length > charFitted)
                {
                    string bio1Trim = ap.BioTrimmed.Substring(0, Math.Min(ap.BioTrimmed.Length, charFitted - 10));
                    frmAP.lblBio1.Text = bio1Trim.Substring(0, bio1Trim.LastIndexOf(" "));
                    frmAP.lblBio2.Text = ap.BioTrimmed.Substring(bio1Trim.LastIndexOf(" ") + 1);
                }
                else
                {
                    frmAP.lblBio1.Text = ap.BioTrimmed;
                }
            }

            frmAP.lblKindleBooks.Text = ap.ApSubTitle;
            int numLabels = Math.Min(4, ap.otherBooks.Count);

            for (int i = 0; i < numLabels; i++)
            {
                frmAP.Controls["lblBook" + (i + 1)].Text = ap.otherBooks[i].title;
            }
            frmEA.lblPost.Text = String.Format("Post on Amazon (as {0}) and Goodreads",
                                               Properties.Settings.Default.penName);
            frmEA.lblMoreBooks.Text = ap.EaSubTitle;
            numLabels = Math.Min(5, ap.otherBooks.Count);
            for (int i = 0; i < numLabels; i++)
            {
                frmEA.Controls["lblBook" + (i + 1)].Text = ap.otherBooks[i].title;
            }
            if (ea.custAlsoBought.Count > 1)
            {
                frmEA.lblBook6.Text   = ea.custAlsoBought[0].title;
                frmEA.lblAuthor1.Text = ea.custAlsoBought[0].author;
                frmEA.lblBook7.Text   = ea.custAlsoBought[1].title;
                frmEA.lblAuthor2.Text = ea.custAlsoBought[1].author;
            }

            // StartActions preview
            if (ea.curBook.seriesName == "")
            {
                frmSA.lblBookTitle.Text = ea.curBook.title;
            }
            else
            {
                frmSA.lblBookTitle.Text = string.Format("{0} ({1} Book {2})", ea.curBook.title, ea.curBook.seriesName,
                                                        ea.curBook.seriesPosition);
            }
            frmSA.lblBookAuthor.Text = ea.curBook.author;
            //Convert rating to equivalent Star image
            string starNum = string.Format("STAR{0}",
                                           Math.Floor(ea.curBook.amazonRating).ToString());

            //Return an object from the star image in the project,
            //set the Image property of pbRating to the returned object as Image
            frmSA.pbRating.Image   = (Image)Properties.Resources.ResourceManager.GetObject(starNum);
            frmSA.lblBookDesc.Text = ea.curBook.desc;
            frmSA.lblRead.Text     = string.Format("{0} hours and {1} minutes", ea.curBook.readingHours, ea.curBook.readingMinutes);
            frmSA.lblPages.Text    = string.Format("{0} pages", ea.curBook.pagesInBook);
            if (ea.curBook.seriesPosition != "")
            {
                frmSA.lblSeries.Text = string.Format("This is book {0} of {1} in {2}",
                                                     ea.curBook.seriesPosition, ea.curBook.totalInSeries, ea.curBook.seriesName);
            }
            else
            {
                frmSA.lblSeries.Text = "This book is not part of a series.";
            }
            frmSA.pbAuthorImage.Image = ap.ApAuthorImage;
            frmSA.lblAboutAuthor.Text = ea.curBook.author;
            frmSA.lblAuthorBio.Text   = ap.BioTrimmed;
        }
Beispiel #4
0
        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();
            }
        }
Beispiel #5
0
        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);
            }
        }