示例#1
0
        private void Init()
        {
            collectionLoaded();
            TransferCollection.defaultCollection().addListener(this);

            PopulateBandwithList();

            View.TranscriptVisible = Preferences.instance().getBoolean("queue.logDrawer.isOpen");
            View.TranscriptHeight  = Preferences.instance().getInteger("queue.logDrawer.size.height");
            View.QueueSize         = Preferences.instance().getInteger("queue.maxtransfers");
            View.BandwidthEnabled  = false;

            View.ResumeEvent                  += View_ResumeEvent;
            View.ReloadEvent                  += View_ReloadEvent;
            View.StopEvent                    += View_StopEvent;
            View.RemoveEvent                  += View_RemoveEvent;
            View.CleanEvent                   += View_CleanEvent;
            View.OpenEvent                    += View_OpenEvent;
            View.ShowEvent                    += View_ShowEvent;
            View.SelectionChangedEvent        += View_SelectionChangedEvent;
            View.BandwidthChangedEvent        += View_BandwidthChangedEvent;
            View.QueueSizeChangedEvent        += View_QueueSizeChangedEvent;
            View.ToggleTranscriptEvent        += View_ToggleTranscriptEvent;
            View.TranscriptHeightChangedEvent += View_TranscriptHeightChangedEvent;

            View.ValidateResumeEvent += View_ValidateResumeEvent;
            View.ValidateReloadEvent += View_ValidateReloadEvent;
            View.ValidateStopEvent   += View_ValidateStopEvent;
            View.ValidateRemoveEvent += View_ValidateRemoveEvent;
            View.ValidateCleanEvent  += View_ValidateCleanEvent;
            View.ValidateOpenEvent   += View_ValidateOpenEvent;
            View.ValidateShowEvent   += View_ValidateShowEvent;
        }
 public static bool ApplicationShouldTerminate()
 {
     if (null != _instance)
     {
         //Saving state of transfer window
         PreferencesFactory.get().setProperty("queue.window.open.default", _instance.Visible);
         if (TransferCollection.defaultCollection().numberOfRunningTransfers() > 0)
         {
             TaskDialogResult result =
                 _instance.QuestionBox(LocaleFactory.localizedString("Transfer in progress"),
                                       LocaleFactory.localizedString("There are files currently being transferred. Quit anyway?"),
                                       null, String.Format("{0}", LocaleFactory.localizedString("Exit")), true);
             if (result.CommandButtonResult == 0)
             {
                 // Quit
                 for (int i = 0; i < _instance.getRegistry().size(); i++)
                 {
                     ((BackgroundAction)_instance.getRegistry().get(i)).cancel();
                 }
                 return(true);
             }
             // Cancel
             return(false);
         }
     }
     return(true);
 }
示例#3
0
 public static bool ApplicationShouldTerminate()
 {
     if (null != _instance)
     {
         //Saving state of transfer window
         Preferences.instance().setProperty("queue.openByDefault", _instance.Visible);
         if (TransferCollection.defaultCollection().numberOfRunningTransfers() > 0)
         {
             DialogResult result = _instance.QuestionBox(Locale.localizedString("Transfer in progress"),
                                                         Locale.localizedString(
                                                             "There are files currently being transferred. Quit anyway?"),
                                                         null,
                                                         String.Format("{0}", Locale.localizedString("Exit")),
                                                         true //Cancel
                                                         );
             if (DialogResult.OK == result)
             {
                 // Quit
                 for (int i = 0; i < TransferCollection.defaultCollection().size(); i++)
                 {
                     Transfer transfer = (Transfer)TransferCollection.defaultCollection().get(i);
                     if (transfer.isRunning())
                     {
                         transfer.interrupt();
                     }
                 }
                 return(true);
             }
             // Cancel
             return(false);
         }
     }
     return(true);
 }
        private void UpdateOverallProgress()
        {
            TransferProgress progress = TransferCollection.defaultCollection().getProgress();

            TransferController.Instance.View.UpdateOverallProgressState(
                TransferCollection.defaultCollection().numberOfRunningTransfers() == 0
                    ? 0
                    : progress.getTransferred().longValue(), progress.getSize().longValue());
        }
示例#5
0
 private void StartTransfer(Transfer transfer, bool resumeRequested, bool reloadRequested)
 {
     if (!TransferCollection.defaultCollection().contains(transfer))
     {
         TransferCollection.defaultCollection().add(transfer);
     }
     if (Preferences.instance().getBoolean("queue.orderFrontOnStart"))
     {
         View.Show();
     }
     background(new TransferBackgroundAction(this, transfer, resumeRequested, reloadRequested));
 }
示例#6
0
 private void View_RemoveEvent()
 {
     foreach (IProgressView progressView in View.SelectedTransfers)
     {
         Transfer transfer = GetTransferFromView(progressView);
         if (!transfer.isRunning())
         {
             TransferCollection.defaultCollection().remove(transfer);
         }
     }
     TransferCollection.defaultCollection().save();
 }
 public override void cleanup()
 {
     base.cleanup();
     if (_transfer.isComplete() && _transfer.isReset())
     {
         if (_preferences.getBoolean("queue.window.open.transfer.stop"))
         {
             if (!(TransferCollection.defaultCollection().numberOfRunningTransfers() > 0))
             {
                 _controller.View.Close();
             }
         }
     }
 }
示例#8
0
 private void Badge()
 {
     if (Preferences.instance().getBoolean("queue.dock.badge"))
     {
         int count = TransferCollection.defaultCollection().numberOfRunningTransfers();
         if (0 == count)
         {
             _controller.Invoke(delegate { _controller.View.TaskbarBadge(null); });
         }
         else
         {
             _controller.Invoke(delegate { _controller.View.TaskbarBadge(count.ToString()); });
         }
     }
 }
示例#9
0
 public void collectionLoaded()
 {
     Invoke(delegate
     {
         IList <IProgressView> model = new List <IProgressView>();
         foreach (Transfer transfer in TransferCollection.defaultCollection())
         {
             ProgressController progressController = new ProgressController(transfer);
             model.Add(progressController.View);
             _transferMap.Add(new KeyValuePair <Transfer, ProgressController>(transfer,
                                                                              progressController));
         }
         View.SetModel(model);
     }
            );
 }
示例#10
0
 private void UpdateOverallProgress()
 {
     if (Utils.IsVistaOrLater)
     {
         if (TransferCollection.defaultCollection().numberOfRunningTransfers() +
             TransferCollection.defaultCollection().numberOfQueuedTransfers() == 0)
         {
             TransferController.Instance.View.UpdateOverallProgressState(0, 0);
         }
         else
         {
             double progress = TransferCollection.defaultCollection().getDataTransferred();
             double maximum  = TransferCollection.defaultCollection().getDataSize();
             TransferController.Instance.View.UpdateOverallProgressState(progress, maximum);
         }
     }
 }
示例#11
0
 private void InitializeTransfers()
 {
     _controller.Background(delegate
     {
         var transfers = TransferCollection.defaultCollection();
         lock (transfers)
         {
             transfers.load();
         }
         transfersSemaphore.Signal();
     }, delegate { });
     if (PreferencesFactory.get().getBoolean("queue.window.open.default"))
     {
         _bc.Invoke(() =>
         {
             transfersSemaphore.Wait();
             TransferController.Instance.View.Show();
         });
     }
 }
示例#12
0
        private void View_CleanEvent()
        {
            IList <Transfer> toRemove = new List <Transfer>();

            foreach (KeyValuePair <Transfer, ProgressController> pair in _transferMap)
            {
                Transfer t = pair.Key;
                if (!t.isRunning() && t.isComplete())
                {
                    TransferCollection.defaultCollection().remove(t);
                    View.RemoveTransfer(pair.Value.View);
                    toRemove.Add(t);
                }
            }
            foreach (Transfer t in toRemove)
            {
                _transferMap.Remove(t);
            }
            TransferCollection.defaultCollection().save();
        }
示例#13
0
 public override void cleanup()
 {
     if (_transfer.isComplete() && !_transfer.isCanceled())
     {
         if (_transfer.isReset())
         {
             if (Preferences.instance().getBoolean("queue.removeItemWhenComplete"))
             {
                 TransferCollection.defaultCollection().remove(_transfer);
             }
             if (Preferences.instance().getBoolean("queue.orderBackOnStop"))
             {
                 if (!(TransferCollection.defaultCollection().numberOfRunningTransfers() > 0))
                 {
                     _controller.View.Close();
                 }
             }
         }
     }
     TransferCollection.defaultCollection().save();
 }
示例#14
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);
                    }
                }
            }
        }
示例#15
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 { });
        }