private void InitializeUpdater() { // register callbacks _canShutdownCallback = CanShutdownCallback; _shutdownRequestCallback = ShutdownRequestCallback; WinSparklePeriodicUpdateChecker.SetCanShutdownCallback(_canShutdownCallback); WinSparklePeriodicUpdateChecker.SetShutdownRequestCallback(_shutdownRequestCallback); if (PreferencesFactory.get().getBoolean("update.check")) { _updater = PeriodicUpdateCheckerFactory.get(); if (_updater.hasUpdatePrivileges()) { DateTime lastCheck = new DateTime(PreferencesFactory.get().getLong("update.check.last")); TimeSpan span = DateTime.Now.Subtract(lastCheck); _updater.register(); if (span.TotalSeconds >= PreferencesFactory.get().getLong("update.check.interval")) { _updater.check(true); } } } if (PreferencesFactory.get().getBoolean("profiles.discovery.updater.enable")) { // Synchronize and register timer _profiles.register(); } }
/// <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"); /* UWP Registration, initialize as soon as possible */ if (Utils.IsRunningAsUWP) { InitStoreContext(); } _controller.Background(delegate { var transfers = TransferCollection.defaultCollection(); lock (transfers) { transfers.load(); } transfersSemaphore.Signal(); }, delegate { }); _controller.Background(delegate { HistoryCollection.defaultCollection().load(); }, delegate { }); CommandsAfterLaunch(CommandLineArgs); HistoryCollection.defaultCollection().addListener(this); if (PreferencesFactory.get().getBoolean("browser.serialize")) { _controller.Background(delegate { _sessions.load(); }, delegate { foreach (Host host in _sessions) { Host h = host; _bc.Invoke(delegate { BrowserController bc = NewBrowser(); bc.Mount(h); }); } _sessions.clear(); }); } NotificationServiceFactory.get().setup(); // User bookmarks and thirdparty applications CountdownEvent bookmarksSemaphore = new CountdownEvent(1); CountdownEvent thirdpartySemaphore = new CountdownEvent(1); // Load all bookmarks in background _controller.Background(delegate { BookmarkCollection c = BookmarkCollection.defaultCollection(); c.load(); bookmarksSemaphore.Signal(); }, delegate { if (PreferencesFactory.get().getBoolean("browser.open.untitled")) { if (PreferencesFactory.get().getProperty("browser.open.bookmark.default") != null) { _bc.Invoke(delegate { BrowserController bc = NewBrowser(); OpenDefaultBookmark(bc); }); } } }); if (PreferencesFactory.get().getBoolean("queue.window.open.default")) { _bc.Invoke(delegate { transfersSemaphore.Wait(); TransferController.Instance.View.Show(); }); } // Bonjour initialization ThreadStart start = delegate { try { RendezvousFactory.instance().init(); } catch (COMException) { Logger.warn("No Bonjour support available"); } }; Thread thread = new Thread(start); thread.SetApartmentState(ApartmentState.STA); thread.Start(); if (PreferencesFactory.get().getBoolean("defaulthandler.reminder") && PreferencesFactory.get().getInteger("uses") > 0) { var handler = SchemeHandlerFactory.get(); if ( !handler.isDefaultHandler(Arrays.asList(Scheme.ftp, Scheme.ftps, Scheme.sftp), new Application(System.Windows.Forms.Application.ExecutablePath))) { Core.Utils.CommandBox(LocaleFactory.localizedString("Default Protocol Handler", "Preferences"), LocaleFactory.localizedString( "Set Cyberduck as default application for FTP and SFTP locations?", "Configuration"), LocaleFactory.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}", LocaleFactory.localizedString("Change", "Configuration"), LocaleFactory.localizedString("Cancel", "Configuration")), false, LocaleFactory.localizedString("Don't ask again", "Configuration"), TaskDialogIcon.Question, delegate(int option, bool verificationChecked) { if (verificationChecked) { // Never show again. PreferencesFactory.get().setProperty("defaulthandler.reminder", false); } switch (option) { case 0: handler.setDefaultHandler(Arrays.asList(Scheme.ftp, Scheme.ftps, Scheme.sftp), new Application(System.Windows.Forms.Application.ExecutablePath)); break; } }); } } // Import thirdparty bookmarks. IList <ThirdpartyBookmarkCollection> thirdpartyBookmarks = GetThirdpartyBookmarks(); _controller.Background(delegate { foreach (ThirdpartyBookmarkCollection c in thirdpartyBookmarks) { if (!c.isInstalled()) { Logger.info("No application installed for " + c.getBundleIdentifier()); continue; } c.load(); if (c.isEmpty()) { if (!PreferencesFactory.get().getBoolean(c.getConfiguration())) { // Flag as imported PreferencesFactory.get().setProperty(c.getConfiguration(), true); } } } bookmarksSemaphore.Wait(); }, delegate { foreach (ThirdpartyBookmarkCollection c in thirdpartyBookmarks) { BookmarkCollection bookmarks = BookmarkCollection.defaultCollection(); c.filter(bookmarks); if (!c.isEmpty()) { ThirdpartyBookmarkCollection c1 = c; Core.Utils.CommandBox(LocaleFactory.localizedString("Import", "Configuration"), String.Format(LocaleFactory.localizedString("Import {0} Bookmarks", "Configuration"), c.getName()), String.Format( LocaleFactory.localizedString( "{0} bookmarks found. Do you want to add these to your bookmarks?", "Configuration"), c.size()), String.Format("{0}", LocaleFactory.localizedString("Import", "Configuration")), true, LocaleFactory.localizedString("Don't ask again", "Configuration"), TaskDialogIcon.Question, delegate(int option, bool verificationChecked) { if (verificationChecked) { // Flag as imported PreferencesFactory.get().setProperty(c1.getConfiguration(), true); } switch (option) { case 0: BookmarkCollection.defaultCollection().addAll(c1); // Flag as imported PreferencesFactory.get().setProperty(c1.getConfiguration(), true); break; } }); } else { PreferencesFactory.get().setProperty(c.getConfiguration(), true); } } thirdpartySemaphore.Signal(); }); // register callbacks _canShutdownCallback = CanShutdownCallback; _shutdownRequestCallback = ShutdownRequestCallback; WinSparklePeriodicUpdateChecker.SetCanShutdownCallback(_canShutdownCallback); WinSparklePeriodicUpdateChecker.SetShutdownRequestCallback(_shutdownRequestCallback); if (PreferencesFactory.get().getBoolean("update.check")) { _updater = PeriodicUpdateCheckerFactory.get(); if (_updater.hasUpdatePrivileges()) { DateTime lastCheck = new DateTime(PreferencesFactory.get().getLong("update.check.last")); TimeSpan span = DateTime.Now.Subtract(lastCheck); _updater.register(); if (span.TotalSeconds >= PreferencesFactory.get().getLong("update.check.interval")) { _updater.check(true); } } } }