public static int Handle(UploadParameters options) { // This task will be all the program does. We need to do enough setup so that // the upload code can work, then tear it down. Program.SetUpErrorHandling(); try { using (var applicationContainer = new ApplicationContainer()) { Program.SetUpLocalization(applicationContainer); Browser.SetUpXulRunner(); Browser.XulRunnerShutdown += Program.OnXulRunnerShutdown; LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false); var transfer = new BookTransfer(new BloomParseClient(), ProjectContext.CreateBloomS3Client(), applicationContainer.BookThumbNailer, new BookDownloadStartingEvent()); // Since Bloom is not a normal console app, when run from a command line, the new command prompt // appears at once. The extra newlines here are attempting to separate this from our output. Console.WriteLine("\nstarting upload"); transfer.UploadFolder(options.Path, applicationContainer, options.ExcludeAudio); Console.WriteLine(("\nupload complete\n")); } return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); return(1); } }
public static int Handle(UploadParameters options) { bool valid = true; if (String.IsNullOrWhiteSpace(options.UploadUser)) { valid = String.IsNullOrWhiteSpace(options.UploadPassword); } else { valid = !String.IsNullOrWhiteSpace(options.UploadPassword); } if (!valid) { Console.WriteLine("Error: upload -u user and -p password must be used together"); return(1); } IsUploading = true; // This task will be all the program does. We need to do enough setup so that // the upload code can work, then tear it down. Program.SetUpErrorHandling(); try { using (var applicationContainer = new ApplicationContainer()) { Program.SetUpLocalization(applicationContainer); Browser.SetUpXulRunner(); Browser.XulRunnerShutdown += Program.OnXulRunnerShutdown; LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false); var transfer = new BookTransfer(new BloomParseClient(), ProjectContext.CreateBloomS3Client(), applicationContainer.BookThumbNailer, new BookDownloadStartingEvent()); // Since Bloom is not a normal console app, when run from a command line, the new command prompt // appears at once. The extra newlines here are attempting to separate this from our output. Console.WriteLine("\nstarting upload"); transfer.UploadFolder(options.Path, applicationContainer, options.ExcludeNarrationAudio, options.UploadUser, options.UploadPassword, options.SingleBookshelfLevel, options.PreserveThumbnails); Console.WriteLine(("\nupload complete\n")); } return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); return(1); } }
static void Main(string[] args) { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (Palaso.PlatformUtilities.Platform.IsWindows) { OldVersionCheck(); } //bring in settings from any previous version if (Settings.Default.NeedUpgrade) { //see http://stackoverflow.com/questions/3498561/net-applicationsettingsbase-should-i-call-upgrade-every-time-i-load Settings.Default.Upgrade(); Settings.Default.Reload(); Settings.Default.NeedUpgrade = false; Settings.Default.Save(); StartUpWithFirstOrNewVersionBehavior = true; } #if !USING_CHORUS Settings.Default.ShowSendReceive = false; // in case someone turned it on before we disabled #endif #if DEBUG if (args.Length > 0) { // This allows us to debug things like interpreting a URL. MessageBox.Show("Attach debugger now"); } #endif #if DEBUG using (new DesktopAnalytics.Analytics("sje2fq26wnnk8c2kzflf", RegistrationDialog.GetAnalyticsUserInfo(), true)) #else string feedbackSetting = System.Environment.GetEnvironmentVariable("FEEDBACK"); //default is to allow tracking var allowTracking = string.IsNullOrEmpty(feedbackSetting) || feedbackSetting.ToLower() == "yes" || feedbackSetting.ToLower() == "true"; using (new Analytics("c8ndqrrl7f0twbf2s6cv", RegistrationDialog.GetAnalyticsUserInfo(), allowTracking)) #endif { if (args.Length == 1 && args[0].ToLower().EndsWith(".bloompack")) { SetUpErrorHandling(); _applicationContainer = new ApplicationContainer(); SetUpLocalization(); var path = args[0]; // This allows local links to bloom packs. if (path.ToLowerInvariant().StartsWith("bloom://")) { path = path.Substring("bloom://".Length); if (!File.Exists(path)) { path = FileLocator.GetFileDistributedWithApplication(true, path); if (!File.Exists(path)) { return; } } } using (var dlg = new BloomPackInstallDialog(path)) { dlg.ShowDialog(); } return; } if (IsBloomBookOrder(args)) { // 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(); _applicationContainer = new ApplicationContainer(); SetUpLocalization(); Logger.Init(); new BookDownloadSupport(); Browser.SetUpXulRunner(); L10NSharp.LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false); var transfer = new BookTransfer(new BloomParseClient(), ProjectContext.CreateBloomS3Client(), _applicationContainer.HtmlThumbnailer, new BookDownloadStartingEvent()) /*not hooked to anything*/; transfer.HandleBloomBookOrder(args[0]); PathToBookDownloadedAtStartup = transfer.LastBookDownloadedPath; // If another instance is running, this one has served its purpose and can exit right away. // Otherwise, carry on with starting up normally. if (TryToGrabMutexForBloom()) { FinishStartup(); } else { _onlyOneBloomMutex = null; // we don't own it, so ReleaseMutexForBloom must not try to release it. string caption = LocalizationManager.GetString("Download.CompletedCaption", "Download complete"); string message = LocalizationManager.GetString("Download.Completed", @"Your download ({0}) is complete. You can see it in the 'Books from BloomLibrary.org' section of your Collections. " + "If you don't seem to be in the middle of doing something, Bloom will select it for you."); message = string.Format(message, Path.GetFileName(PathToBookDownloadedAtStartup)); MessageBox.Show(message, caption); } return; } if (!GrabMutexForBloom()) { return; } OldVersionCheck(); SetUpErrorHandling(); _applicationContainer = new ApplicationContainer(); if (args.Length == 2 && args[0].ToLowerInvariant() == "--upload") { // A special path to upload chunks of stuff. This is not currently documented and is not very robust. // - User must log in before running this // - For best results each bloom book needs to be part of a collection in its parent folder // - little error checking (e.g., we don't apply the usual constaints that a book must have title and licence info) SetUpLocalization(); Browser.SetUpXulRunner(); var transfer = new BookTransfer(new BloomParseClient(), ProjectContext.CreateBloomS3Client(), _applicationContainer.HtmlThumbnailer, new BookDownloadStartingEvent()) /*not hooked to anything*/; transfer.UploadFolder(args[1], _applicationContainer); return; } new BookDownloadSupport(); // creating this sets some things up so we can download. SetUpLocalization(); Logger.Init(); if (args.Length == 1) { Debug.Assert(args[0].ToLower().EndsWith(".bloomcollection")); // Anything else handled above. Settings.Default.MruProjects.AddNewPath(args[0]); } if (args.Length > 0 && args[0] == "--rename") { try { var pathToNewCollection = CollectionSettings.RenameCollection(args[1], args[2]); //MessageBox.Show("Your collection has been renamed."); Settings.Default.MruProjects.AddNewPath(pathToNewCollection); } catch (ApplicationException error) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, error.Message); Environment.Exit(-1); } catch (Exception error) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "Bloom could not finish renaming your collection folder. Restart your computer and try again."); Environment.Exit(-1); } } Browser.SetUpXulRunner(); #if DEBUG StartDebugServer(); #endif L10NSharp.LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false); FinishStartup(); } } finally { ReleaseMutexForBloom(); } }