public bool SetText(string strNewText, LogStatusType lsType)
        {
            if (strNewText == null)
            {
                return(true);
            }
            if (lsType != LogStatusType.Info)
            {
                return(true);
            }

            if (m_bUseThread && (m_th == null))
            {
                ThreadStart ts = new ThreadStart(this.GuiThread);
                m_th = new Thread(ts);
                m_th.Start();
            }
            if (!m_bUseThread && (m_dlgModal == null))
            {
                m_dlgModal = ConstructStatusDialog();
            }

            lock (m_objSync) { m_strProgress = strNewText; }
            return((m_dlgModal != null) ? m_dlgModal.SetText(strNewText, lsType) : true);
        }
示例#2
0
            public bool SetText(string strNewText, LogStatusType lsType)
            {
                if (m_dlg == null)
                {
                    Debug.Assert(false); return(true);
                }

                return(m_dlg.SetText(strNewText, lsType));
            }
        /// <summary>
        /// Downloads some favicons.
        /// </summary>
        /// <param name="entries">The entries.</param>
        private void downloadSomeFavicons(KeePassLib.Collections.PwObjectList <PwEntry> entries)
        {
            StatusProgressForm progressForm = new StatusProgressForm();

            progressForm.InitEx("Downloading Favicons", true, false, m_host.MainWindow);
            progressForm.Show();
            progressForm.SetProgress(0);

            float  progress           = 0;
            float  outputLength       = (float)entries.UCount;
            int    downloadsCompleted = 0;
            string errorMessage       = "";
            int    errorCount         = 0;

            foreach (PwEntry pwe in entries)
            {
                string message = "";

                progressForm.SetText("Title: " + pwe.Strings.ReadSafe("Title") + "; User Name: " + pwe.Strings.ReadSafe("UserName"), LogStatusType.Info);

                downloadOneFavicon(pwe, ref message);
                if (message != "")
                {
                    errorMessage = "For an entry with URL '" + pwe.Strings.ReadSafe("URL") + "': " + message;
                    errorCount++;
                }

                downloadsCompleted++;
                progress = (downloadsCompleted / outputLength) * 100;
                progressForm.SetProgress((uint)Math.Floor(progress));
                System.Threading.Thread.Sleep(100);
                if (progressForm.UserCancelled)
                {
                    break;
                }
            }

            progressForm.Hide();
            progressForm.Close();

            if (errorMessage != "")
            {
                if (errorCount == 1)
                {
                    MessageBox.Show(errorMessage, "Download error");
                }
                else
                {
                    MessageBox.Show(errorCount + " errors occurred. The last error message is shown here. To see the other messages, select a smaller group of entries and use the right click menu to start the download.\n" + errorMessage, "Download errors");
                }
            }

            m_host.MainWindow.UpdateUI(false, null, false, null,
                                       true, null, true);
            m_host.MainWindow.UpdateTrayIcon();
        }
 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);
     }
 }
        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);
        }