コード例 #1
0
        public void Save()
        {
            if (EpubMode)
            {
                try
                {
                    SaveAsEpub();
                }
                catch (Exception err)
                {
                    SIL.Reporting.ErrorReport.NotifyUserOfProblem("Bloom was not able to save the ePUB.  {0}", err.Message);
                }
                return;
            }
            try
            {
                // Give a slight preference to USB keys, though if they used a different directory last time, we favor that.

                if (string.IsNullOrEmpty(_lastDirectory) || !Directory.Exists(_lastDirectory))
                {
                    var drives = SIL.UsbDrive.UsbDriveInfo.GetDrives();
                    if (drives != null && drives.Count > 0)
                    {
                        _lastDirectory = drives[0].RootDirectory.FullName;
                    }
                }

                using (var dlg = new DialogAdapters.SaveFileDialogAdapter())
                {
                    if (!string.IsNullOrEmpty(_lastDirectory) && Directory.Exists(_lastDirectory))
                    {
                        dlg.InitialDirectory = _lastDirectory;
                    }
                    var portion = "";
                    switch (BookletPortion)
                    {
                    case BookletPortions.None:
                        Debug.Fail("Save should not be enabled");
                        return;

                    case BookletPortions.AllPagesNoBooklet:
                        portion = "Pages";
                        break;

                    case BookletPortions.BookletCover:
                        portion = "Cover";
                        break;

                    case BookletPortions.BookletPages:
                        portion = "Inside";
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    string suggestedName = string.Format("{0}-{1}-{2}.pdf", Path.GetFileName(_currentlyLoadedBook.FolderPath),
                                                         _collectionSettings.GetFilesafeLanguage1Name("en"), portion);
                    dlg.FileName = suggestedName;
                    var rgb = L10NSharp.LocalizationManager.GetString(@"PublishTab.PdfMaker.PdfWithRGB",
                                                                      "PDF with RGB color",
                                                                      @"displayed as file type for Save File dialog. 'RGB' may not be translatable, it is a standard.");
                    var swopv2 = L10NSharp.LocalizationManager.GetString(@"PublishTab.PdfMaker.PdfWithCmykSwopV2",
                                                                         "PDF with CMYK color (U.S. Web Coated (SWOP) v2)",
                                                                         @"displayed as file type for Save File dialog, the content in parentheses may not be translatable. 'CMYK' may not be translatable, it is a print shop standard.");

                    rgb        = rgb.Replace("|", "");
                    swopv2     = swopv2.Replace("|", "");
                    dlg.Filter = String.Format("{0}|*.pdf|{1}|*.pdf", rgb, swopv2);
                    if (DialogResult.OK == dlg.ShowDialog())
                    {
                        _lastDirectory = Path.GetDirectoryName(dlg.FileName);
                        switch (dlg.FilterIndex)
                        {
                        case 1:                         // PDF for Desktop Printing
                            RobustFile.Copy(PdfFilePath, dlg.FileName, true);
                            break;

                        case 2:                         // PDF for Printshop (CMYK US Web Coated V2)
                            ProcessPdfFurtherAndSave(ProcessPdfWithGhostscript.OutputType.Printshop, dlg.FileName);
                            break;
                        }
                        Analytics.Track("Save PDF", new Dictionary <string, string>()
                        {
                            { "Portion", Enum.GetName(typeof(BookletPortions), BookletPortion) },
                            { "Layout", PageLayout.ToString() },
                            { "BookId", BookSelection.CurrentSelection.ID },
                            { "Country", _collectionSettings.Country }
                        });
                    }
                }
            }
            catch (Exception err)
            {
                SIL.Reporting.ErrorReport.NotifyUserOfProblem("Bloom was not able to save the PDF.  {0}", err.Message);
            }
        }