/// <summary>
/// This routine handles the old-style download requests which come as an order URL from BloomLibrary.
/// Enhance: it's unfortunate that we have two command-line methods of downloading a book. However, they have
/// rather different requirements:
/// - this one displays a progress UI, the other doesn't.
/// - this one must extract the URL from a bloom: url (which the library must produce with urlencoding),
/// for the other, it's more convenient to pass an unencoded url
/// - worse, this version typically goes on to fully launch Bloom; the other always shuts the program down
/// when done. Thus, this version is much more tightly connected to the normal startup code.
/// Note that we can't easily change the exact command line that this version deals with, because
/// Bloom library generates that command line, and if we change what it generates, everyone running an
/// older Bloom will be in trouble.
/// Most of the core implementation of the download process is common.
/// </summary>
private static void HandleDownload(string order)
{
// We will start up just enough to download the book. This avoids the code that normally tries to keep only a single instance running.
// There is probably a pathological case here where we are overwriting an existing template just as the main instance is trying to
// do something with it. The time interval would be very short, because download uses a temp folder until it has the whole thing
// and then copies (or more commonly moves) it over in one step, and making a book from a template involves a similarly short
// step of copying the template to the new book. Hopefully users have (or will soon learn) enough sense not to
// try to use a template while in the middle of downloading a new version.
SetUpErrorHandling();
using(_applicationContainer = new ApplicationContainer())
{
SetUpLocalization();
//JT please review: is this needed? InstallerSupport.MakeBloomRegistryEntries(args);
BookDownloadSupport.EnsureDownloadFolderExists();
Browser.SetUpXulRunner();
Browser.XulRunnerShutdown += OnXulRunnerShutdown;
LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false);
var transfer = new BookTransfer(new BloomParseClient(), ProjectContext.CreateBloomS3Client(),
_applicationContainer.BookThumbNailer, new BookDownloadStartingEvent()) /*not hooked to anything*/;
transfer.HandleBloomBookOrder(order);
PathToBookDownloadedAtStartup = transfer.LastBookDownloadedPath;
// BL-2143: Don't show download complete message if download was not successful
if (!string.IsNullOrEmpty(PathToBookDownloadedAtStartup))
{
var caption = LocalizationManager.GetString("Download.CompletedCaption", "Download complete");
var message = LocalizationManager.GetString("Download.Completed",
@"Your download ({0}) is complete. You can see it in the 'Books from BloomLibrary.org' section of your Collections.");
message = string.Format(message, Path.GetFileName(PathToBookDownloadedAtStartup));
MessageBox.Show(message, caption);
}
}
}