Esempio n. 1
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 public MainController()
 {
     // Initialize WindowsFormsSynchronizationContext (sets SynchronizationContext.Current)
     NotificationServiceFactory.get().setup();
     // Execute OnStartup later
     SynchronizationContext.Current.Post(OnStartup, null);
 }
Esempio n. 2
0
        public void Show()
        {
            int uses = PreferencesFactory.get().getInteger("uses");

            var notify = (ToolstripNotificationService)NotificationServiceFactory.get();

            var result = TaskDialog.Show(
                owner: IntPtr.Zero,
                allowDialogCancellation: true,
                title: Localize("Please Donate") + " (" + uses + ")",
                verificationText: Localize("Don't show again for this version"),
                mainInstruction: Localize("Thank you for using Cyberduck!"),
                content: $@"{Localize("This is free software, but it still costs money to write, support, and distribute it. If you enjoy using it, please consider a donation to the authors of this software. It will help to make Cyberduck even better!")} {Localize("As a contributor to Cyberduck, you receive a registration key that disables this prompt.")}",
                commandLinks: new[] { Localize("Donate"), Localize("Later"), Localize("Buy in Windows Store") },
                verificationByDefault: Assembly.GetExecutingAssembly().GetName().Version.ToString().Equals(PreferencesFactory.get().getProperty("donate.reminder")));

            if (result.VerificationChecked == true)
            {
                PreferencesFactory.get().setProperty("donate.reminder", Assembly.GetExecutingAssembly().GetName().Version.ToString());
            }

            if (result.CommandButtonResult == 0)
            {
                BrowserLauncherFactory.get().open(PreferencesFactory.get().getProperty("website.donate"));
            }
            if (result.CommandButtonResult == 2)
            {
                BrowserLauncherFactory.get().open(PreferencesFactory.get().getProperty("website.store"));
            }

            PreferencesFactory.get().setProperty("donate.reminder.date", DateTime.Now.Ticks);
        }
Esempio n. 3
0
        private void OnStartup(object state)
        {
            _bc      = NewBrowser(true, true);
            MainForm = _bc.View as Form;

            /* UWP Registration, initialize as soon as possible */
            if (Utils.IsRunningAsUWP)
            {
                InitStoreContext();
            }

            NotificationServiceFactory.get().setup();

            InitializeTransfers();
            InitializeSessions();

            // User bookmarks and thirdparty applications
            CountdownEvent bookmarksSemaphore  = new CountdownEvent(1);
            CountdownEvent thirdpartySemaphore = new CountdownEvent(1);

            InitializeBookmarks(bookmarksSemaphore);
            InitializeBonjour();
            InitializeProtocolHandler();
            ImportBookmarks(bookmarksSemaphore, thirdpartySemaphore);
            SetupServiceHost();
            InitializeUpdater();
        }
        public void Show()
        {
            int uses = PreferencesFactory.get().getInteger("uses");

            var notify = (ToolstripNotificationService)NotificationServiceFactory.get();

            var result = TaskDialog.Show(
                owner: IntPtr.Zero,
                allowDialogCancellation: true,
                title: Localize("Please Donate") + " (" + uses + ")",
                verificationText: Localize("Don't show again for this version."),
                mainInstruction: Localize("Thank you for using Cyberduck!"),
                content: $@"{Localize("It has taken many nights to develop this application. If you enjoy using it, please consider a donation to the author of this software. It will help to make Cyberduck even better!")}

{Localize("The payment can be made simply and safely using Paypal. You don't need to open an account.")}",
                expandedInfo: $@"{Localize("Donation Key")}

{Localize("As a contributor to Cyberduck, you receive a donation key that disables this prompt.")}",
                commandLinks: new[] { Localize("Donate!"), Localize("Later") },
                expandedByDefault: true,
                verificationByDefault: Assembly.GetExecutingAssembly().GetName().Version.ToString().Equals(PreferencesFactory.get().getProperty("donate.reminder")));

            if (result.VerificationChecked == true)
            {
                PreferencesFactory.get().setProperty("donate.reminder", Assembly.GetExecutingAssembly().GetName().Version.ToString());
            }

            if (result.CommandButtonResult == 0)
            {
                BrowserLauncherFactory.get().open(PreferencesFactory.get().getProperty("website.donate"));
            }

            PreferencesFactory.get().setProperty("donate.reminder.date", DateTime.Now.Ticks);
        }
Esempio n. 5
0
 public static void Exit(bool updateInProgress)
 {
     NotificationServiceFactory.get().unregister();
     if (!updateInProgress && PrepareExit())
     {
         ApplicationShouldTerminateAfterDonationPrompt();
     }
     DefaultBackgroundExecutor.get().shutdown();
     System.Windows.Forms.Application.Exit();
 }
Esempio n. 6
0
        public static void Exit(bool updateInProgress)
        {
            // Already shutting down. Do nothing.
            if (!applicationShutdown.WaitOne(0))
            {
                return;
            }

            NotificationServiceFactory.get().unregister();
            if (!updateInProgress && PrepareExit())
            {
                ApplicationShouldTerminateAfterDonationPrompt();
            }
            DefaultBackgroundExecutor.get().shutdown();
            _application.Shutdown(updateInProgress);
            _application.ExitThreadCore();
        }
Esempio n. 7
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");

            /* 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);
                    }
                }
            }
        }