Пример #1
0
            public bool SetProgress(uint uPercent)
            {
                if (m_dlg == null)
                {
                    Debug.Assert(false); return(true);
                }

                return(m_dlg.SetProgress(uPercent));
            }
 private void ReportProgress(ProgressItem progress)
 {
     if (progressForm != null && !progressForm.IsDisposed)
     {
         var progressHelper  = (ProgressHelper)progressForm.Tag;
         var currentProgress = ((100f / progressHelper.TotalBreaches) * progressHelper.CurrentBreach) + (progress.Progress / progressHelper.TotalBreaches);
         progressForm.SetProgress((uint)currentProgress);
         progressForm.SetText(progress.ProgressText, KeePassLib.Interfaces.LogStatusType.Info);
     }
 }
Пример #3
0
        private async Task CheckBreach(CheckTypeEnum breachType)
        {
            if (!pluginHost.Database.IsOpen)
            {
                MessageBox.Show("You must first open a database", Resources.MessageTitle);
                return;
            }

            var dialog = new CheckerPrompt(breachType, breachType != CheckTypeEnum.Password);

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                progressForm = new StatusProgressForm();
                var progressIndicator = new Progress <ProgressItem>(ReportProgress);
                progressForm.InitEx("Checking Breaches", false, breachType == CheckTypeEnum.SiteDomain, pluginHost.MainWindow);
                progressForm.Show();
                progressForm.SetProgress(0);
                List <BreachedEntry> result = new List <BreachedEntry>();
                if (dialog.CheckAllBreaches)
                {
                    progressForm.Tag = new ProgressHelper(Enum.GetValues(typeof(BreachEnum)).Length);
                    foreach (var breach in Enum.GetValues(typeof(BreachEnum)))
                    {
                        var foundBreaches = await CheckBreaches(supportedBreachCheckers[(BreachEnum)breach](client, pluginHost),
                                                                dialog.ExpireEntries, dialog.OnlyCheckOldEntries, dialog.IgnoreDeletedEntries, progressIndicator);

                        result.AddRange(foundBreaches);
                        ((ProgressHelper)progressForm.Tag).CurrentBreach++;
                    }
                }
                else
                {
                    progressForm.Tag = new ProgressHelper(1);
                    var foundBreaches = await CheckBreaches(supportedBreachCheckers[dialog.SelectedBreach](client, pluginHost),
                                                            dialog.ExpireEntries, dialog.OnlyCheckOldEntries, dialog.IgnoreDeletedEntries, progressIndicator);

                    result.AddRange(foundBreaches);
                }
                progressForm.Close();

                if (!result.Any())
                {
                    MessageBox.Show("No breached entries found.", Resources.MessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    var breachedEntriesDialog = new BreachedEntriesDialog(pluginHost);
                    breachedEntriesDialog.AddBreaches(result);
                    breachedEntriesDialog.ShowDialog();
                }
            }

            pluginHost.MainWindow.Show();
        }
        private StatusProgressForm ConstructStatusDialog()
        {
            StatusProgressForm dlg = StatusProgressForm.ConstructEx(
                m_strTitle, false, true, (m_bUseThread ? null : m_fOwner), null);

            dlg.SetProgress(m_uProgress);

            MainForm mfOwner = ((m_fOwner != null) ? (m_fOwner as MainForm) : null);

            if ((m_bUseThread == false) && (mfOwner != null))
            {
                // mfOwner.RedirectActivationPush(dlg);
                mfOwner.UIBlockInteraction(true);
            }

            return(dlg);
        }
        private void GuiThread()
        {
            uint   uProgress   = InitialProgress;
            string strProgress = InitialStatus;

            StatusProgressForm dlg = null;

            while (true)
            {
                lock (m_objSync)
                {
                    if (m_bTerminate)
                    {
                        break;
                    }

                    if (m_uProgress != uProgress)
                    {
                        uProgress = m_uProgress;
                        if (dlg != null)
                        {
                            dlg.SetProgress(uProgress);
                        }
                    }

                    if (m_strProgress != strProgress)
                    {
                        strProgress = m_strProgress;

                        if (dlg == null)
                        {
                            dlg = ConstructStatusDialog();
                        }

                        dlg.SetText(strProgress, LogStatusType.Info);
                    }
                }

                Application.DoEvents();
            }

            DestroyStatusDialog(dlg);
        }
        public bool SetProgress(uint uPercent)
        {
            lock (m_objSync) { m_uProgress = uPercent; }

            return((m_dlgModal != null) ? m_dlgModal.SetProgress(uPercent) : true);
        }
        private async Task CheckBreach(CheckTypeEnum breachType, PwGroup group)
        {
            var dialog = new CheckerPrompt(breachType, breachType != CheckTypeEnum.Password);

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                progressForm = new StatusProgressForm();
                var progressIndicator = new Progress <ProgressItem>(ReportProgress);
                progressForm.InitEx("Checking Breaches", true, breachType == CheckTypeEnum.SiteDomain, pluginHost.MainWindow);
                progressForm.Show();
                progressForm.SetProgress(0);
                List <BreachedEntry> result = new List <BreachedEntry>();
                try
                {
                    if (dialog.CheckAllBreaches)
                    {
                        var breaches = Enum.GetValues(typeof(BreachEnum)).Cast <BreachEnum>().Where(b => b.GetAttribute <CheckerTypeAttribute>().Type == breachType);
                        progressForm.Tag = new ProgressHelper(breaches.Count());
                        foreach (var breach in breaches)
                        {
                            var foundBreaches = await CheckBreaches(supportedBreachCheckers[(BreachEnum)breach](client, pluginHost),
                                                                    group, dialog.ExpireEntries, dialog.OnlyCheckOldEntries, dialog.IgnoreDeletedEntries, dialog.IgnoreExpiredEntries, progressIndicator, () => progressForm.ContinueWork());

                            result.AddRange(foundBreaches);
                            ((ProgressHelper)progressForm.Tag).CurrentBreach++;
                        }
                    }
                    else
                    {
                        progressForm.Tag = new ProgressHelper(1);
                        var foundBreaches = await CheckBreaches(supportedBreachCheckers[dialog.SelectedBreach](client, pluginHost),
                                                                group, dialog.ExpireEntries, dialog.OnlyCheckOldEntries, dialog.IgnoreDeletedEntries, dialog.IgnoreExpiredEntries, progressIndicator, () => progressForm.ContinueWork());

                        result.AddRange(foundBreaches);
                    }
                }
                catch (Exception ex)
                {
                    result = null;
                    MessageBox.Show(pluginHost.MainWindow, ex.Message, Resources.MessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    progressForm.Close();
                }

                if (result != null)
                {
                    if (!result.Any())
                    {
                        MessageBox.Show(pluginHost.MainWindow, "No breached entries found.", Resources.MessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        var breachedEntriesDialog = new BreachedEntriesDialog(pluginHost);
                        breachedEntriesDialog.AddBreaches(result);
                        breachedEntriesDialog.ShowDialog();
                    }
                }
            }

            pluginHost.MainWindow.Show();
        }