Esempio n. 1
0
        /// <summary>
        /// A normal (non-single-instance) application raises the Startup event every time it starts.
        /// A single-instance application raises the Startup  event when it starts only if the application
        /// is not already active; otherwise, it raises the StartupNextInstance  event.
        /// </summary>
        /// <see cref="http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.applicationservices.windowsformsapplicationbase.startup.aspx"/>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ApplicationDidFinishLaunching(object sender, StartupEventArgs e)
        {
            Logger.debug("ApplicationDidFinishLaunching");
            CommandsAfterLaunch(CommandLineArgs);

            UpdateController.Instance.CheckForUpdatesIfNecessary();

            if (Preferences.instance().getBoolean("queue.openByDefault"))
            {
                TransferController.Instance.View.Show();
            }

            if (Preferences.instance().getBoolean("browser.serialize"))
            {
                _bc.Background(delegate { _sessions.load(); },
                               delegate
                {
                    foreach (
                        Host host in
                        _sessions)
                    {
                        NewBrowser().Mount(host);
                    }
                    _sessions.clear();
                });
            }
            //Registering for Growl is an expensive operation. Takes up to 500ms on my machine.
            _bc.Background(delegate { ch.cyberduck.ui.growl.Growl.instance().register(); }, delegate { });

            // User bookmarks and thirdparty applications
            CountdownEvent cde = new CountdownEvent(2);

            _bc.Background(delegate
            {
                BookmarkCollection c = BookmarkCollection.defaultCollection();
                c.load();
                cde.Signal();
            }, delegate
            {
                if (Preferences.instance
                        ().getBoolean(
                        "browser.openUntitled"))
                {
                    if (
                        Browsers.Count ==
                        0)
                    {
                        OpenDefaultBookmark
                            (NewBrowser());
                    }
                }
            });
            _bc.Background(delegate { HistoryCollection.defaultCollection().load(); }, delegate { });
            _bc.Background(delegate { TransferCollection.defaultCollection().load(); }, delegate { });

            // Bonjour initialization);
            if (Preferences.instance().getBoolean("rendezvous.enable"))
            {
                try
                {
                    RendezvousFactory.instance().init();
                }
                catch (COMException)
                {
                    Logger.warn("No Bonjour support available");
                }
            }
            if (Preferences.instance().getBoolean("defaulthandler.reminder") &&
                Preferences.instance().getInteger("uses") > 0)
            {
                if (!URLSchemeHandlerConfiguration.Instance.IsDefaultApplicationForFtp() ||
                    !URLSchemeHandlerConfiguration.Instance.IsDefaultApplicationForSftp())
                {
                    _bc.CommandBox(
                        Locale.localizedString("Default Protocol Handler", "Preferences"),
                        Locale.localizedString("Set Cyberduck as default application for FTP and SFTP locations?",
                                               "Configuration"),
                        Locale.localizedString(
                            "As the default application, Cyberduck will open when you click on FTP or SFTP links in other applications, such as your web browser. You can change this setting in the Preferences later.",
                            "Configuration"),
                        String.Format("{0}|{1}",
                                      Locale.localizedString("Change", "Configuration"),
                                      Locale.localizedString("Cancel", "Configuration")),
                        false, Locale.localizedString("Don't ask again", "Configuration"), SysIcons.Question,
                        delegate(int option, bool verificationChecked)
                    {
                        if (verificationChecked)
                        {
                            // Never show again.
                            Preferences.instance().setProperty(
                                "defaulthandler.reminder", false);
                        }
                        switch (option)
                        {
                        case 0:
                            URLSchemeHandlerConfiguration.Instance.
                            RegisterFtpProtocol();
                            URLSchemeHandlerConfiguration.Instance.
                            RegisterSftpProtocol();
                            break;
                        }
                    });
                }
            }
            // Import thirdparty bookmarks.
            IList <ThirdpartyBookmarkCollection> thirdpartyBookmarks = GetThirdpartyBookmarks();

            _bc.Background(delegate
            {
                foreach (ThirdpartyBookmarkCollection c in thirdpartyBookmarks)
                {
                    if (!Preferences.instance().getBoolean(c.getConfiguration()))
                    {
                        if (!c.isInstalled())
                        {
                            Logger.info("No application installed for " + c.getBundleIdentifier());
                            continue;
                        }
                        c.load();
                        if (c.isEmpty())
                        {
                            // Flag as imported
                            Preferences.instance().setProperty(c.getConfiguration(), true);
                        }
                    }
                }
            },
                           delegate
            {
                foreach (ThirdpartyBookmarkCollection c in thirdpartyBookmarks)
                {
                    if (!Preferences.instance().getBoolean(c.getConfiguration()))
                    {
                        if (!c.isEmpty())
                        {
                            ThirdpartyBookmarkCollection c1 = c;
                            _bc.CommandBox(Locale.localizedString("Import", "Configuration"),
                                           String.Format(
                                               Locale.localizedString("Import {0} Bookmarks",
                                                                      "Configuration"), c.getName()),
                                           String.Format(
                                               Locale.localizedString(
                                                   "{0} bookmarks found. Do you want to add these to your bookmarks?",
                                                   "Configuration"), c.size()),
                                           String.Format("{0}",
                                                         Locale.localizedString("Import",
                                                                                "Configuration")),
                                           true,
                                           Locale.localizedString("Don't ask again", "Configuration"),
                                           SysIcons.Question,
                                           delegate(int option, bool verificationChecked)
                            {
                                if (verificationChecked)
                                {
                                    // Flag as imported
                                    Preferences.instance().setProperty(
                                        c1.getConfiguration(), true);
                                }
                                switch (option)
                                {
                                case 0:
                                    BookmarkCollection.defaultCollection().
                                    addAll(c1);
                                    // Flag as imported
                                    Preferences.instance().setProperty(
                                        c1.getConfiguration(), true);
                                    break;
                                }
                            });
                        }
                    }
                }
                cde.Signal();
            });


            _bc.Background(delegate
            {
                cde.Wait();
                BookmarkCollection c = BookmarkCollection.defaultCollection();
                if (c.isEmpty())
                {
                    FolderBookmarkCollection defaults =
                        new FolderBookmarkCollection(LocalFactory.createLocal(
                                                         Preferences.instance().getProperty("application.bookmarks.path")
                                                         ));
                    defaults.load();
                    foreach (Host bookmark in defaults)
                    {
                        if (Logger.isDebugEnabled())
                        {
                            Logger.debug("Adding default bookmark:" + bookmark);
                        }
                        c.add(bookmark);
                    }
                }
            }, delegate { });
        }