Esempio n. 1
0
 public void RunIt()
 {
     using (var dlg = new BloomPackInstallDialog(@"C:\Users\John\Desktop\Szi's shells Books.BloomPack"))
     {
         dlg.ShowDialog();
     }
 }
Esempio n. 2
0
        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();
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                //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 DEBUG
                using (new 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"))
                    {
                        using (var dlg = new BloomPackInstallDialog(args[0]))
                        {
                            dlg.ShowDialog();
                        }
                        return;
                    }


#if !DEBUG //the exception you get when there is no other BLOOM is a pain when running debugger with break-on-exceptions
                    if (!GrabMutexForBloom())
                    {
                        return;
                    }
#endif

                    OldVersionCheck();



                    SetUpErrorHandling();

                    _applicationContainer = new ApplicationContainer();

                    SetUpLocalization();
                    Logger.Init();



                    if (args.Length == 1 && args[0].ToLower().EndsWith(".bloomcollection"))
                    {
                        Settings.Default.MruProjects.AddNewPath(args[0]);
                    }
                    _earliestWeShouldCloseTheSplashScreen = DateTime.Now.AddSeconds(3);

                    Settings.Default.Save();


                    Browser.SetUpXulRunner();

                    Application.Idle += Startup;



                    L10NSharp.LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false);

                    try
                    {
                        Application.Run();
                    }
                    catch (System.AccessViolationException nasty)
                    {
                        Logger.ShowUserATextFileRelatedToCatastrophicError(nasty);
                        System.Environment.FailFast("AccessViolationException");
                    }

                    Settings.Default.Save();

                    Logger.ShutDown();


                    if (_projectContext != null)
                    {
                        _projectContext.Dispose();
                    }
                }
            }
            finally
            {
                ReleaseMutexForBloom();
            }
        }