コード例 #1
0
        private void OnBtnOK(object sender, EventArgs e)
        {
            SearchParameters sp = GetSearchParameters(true);

            if (sp.RegularExpression)
            {
                try                 // Validate regular expression
                {
                    Regex rx = new Regex(sp.SearchString);
                    rx.IsMatch("ABCD");
                }
                catch (Exception exReg)
                {
                    MessageService.ShowWarning(sp.SearchString, exReg);
                    this.DialogResult = DialogResult.None;
                    return;
                }
            }

            string strGroupName = KPRes.SearchGroupName + " (\"" + sp.SearchString + "\" ";

            strGroupName += KPRes.SearchResultsInSeparator + " ";
            strGroupName += m_pgRoot.Name + ")";
            PwGroup pgResults = new PwGroup(true, true, strGroupName, PwIcon.EMailSearch);

            pgResults.IsVirtual = true;

            PwObjectList <PwEntry> listResults = pgResults.Entries;

            if (m_pdContext != null)
            {
                MainForm.AutoAdjustMemProtSettings(m_pdContext, sp);
            }

            Form          fOptDialog;
            IStatusLogger sl = StatusUtil.CreateStatusDialog(this, out fOptDialog,
                                                             null, KPRes.SearchingOp + "...", true, false);

            // if(fOptDialog != null) Program.MainForm.RedirectActivationPush(fOptDialog);
            this.Enabled = false;

            Exception exFind = null;

            try { m_pgRoot.SearchEntries(sp, listResults, sl); }
            catch (Exception ex) { exFind = ex; }

            // if(fOptDialog != null) Program.MainForm.RedirectActivationPop();
            this.Enabled = true;
            sl.EndLogging();

            if (exFind != null)
            {
                MessageService.ShowWarning(exFind);
            }

            m_pgResultsGroup = pgResults;

            sp.SearchString = string.Empty;             // Clear for saving (sp points to global)
        }
コード例 #2
0
ファイル: Migration.cs プロジェクト: cpugnoud/KeePassOTP
 protected void InitLogger(string sCaption, int max)
 {
     m_sl         = StatusUtil.CreateStatusDialog(GlobalWindowManager.TopWindow, out m_Form, sCaption, null, false, false);
     m_EntryCount = max;
     m_EntryIndex = 0;
     m_sl.SetProgress(0);
     KeePass.Program.MainForm.UIBlockInteraction(true);
 }
コード例 #3
0
        private IStatusLogger CreateUpdateCheckLogger()
        {
            IStatusLogger sl = StatusUtil.CreateStatusDialog(null, out m_CheckProgress,
                                                             KeePass.Resources.KPRes.UpdateCheck, KeePass.Resources.KPRes.CheckingForUpd + "...", true, true);
            Button btnCancel = (Button)Tools.GetControl("m_btnCancel", m_CheckProgress);

            if (btnCancel != null)
            {
                int x = btnCancel.Right;
                btnCancel.AutoSize = true;
                btnCancel.Text     = PluginTranslate.EnterBackgroundMode;
                btnCancel.Left     = x - btnCancel.Width;
            }
            return(sl);
        }
コード例 #4
0
ファイル: UpdateCheckEx.cs プロジェクト: fsdsabel/keepass
		private static void RunPriv(object o)
		{
			UpdateCheckParams p = (o as UpdateCheckParams);
			if(p == null) { Debug.Assert(false); return; }

			IStatusLogger sl = null;
			try
			{
				if(p.ForceUI)
				{
					Form fStatusDialog;
					sl = StatusUtil.CreateStatusDialog(p.Parent, out fStatusDialog,
						KPRes.UpdateCheck, KPRes.CheckingForUpd + "...", true, true);
				}

				List<UpdateComponentInfo> lInst = GetInstalledComponents();
				List<string> lUrls = GetUrls(lInst);
				Dictionary<string, List<UpdateComponentInfo>> dictAvail =
					DownloadInfoFiles(lUrls, sl);
				if(dictAvail == null) return; // User cancelled

				MergeInfo(lInst, dictAvail);

				bool bUpdAvail = false;
				foreach(UpdateComponentInfo uc in lInst)
				{
					if(uc.Status == UpdateComponentStatus.NewVerAvailable)
					{
						bUpdAvail = true;
						break;
					}
				}

				if(sl != null) { sl.EndLogging(); sl = null; }

				if(bUpdAvail || p.ForceUI)
					ShowUpdateDialogAsync(lInst, p.ForceUI);
			}
			catch(Exception) { Debug.Assert(false); }
			finally
			{
				try { if(sl != null) sl.EndLogging(); }
				catch(Exception) { Debug.Assert(false); }
			}
		}
コード例 #5
0
        public FaviconDialog(IPluginHost host)
        {
            // KeePass plugin host
            pluginHost = host;

            // Set up BackgroundWorker
            bgWorker = new BackgroundWorker();

            // BackgroundWorker Events
            bgWorker.DoWork             += BgWorker_DoWork;
            bgWorker.RunWorkerCompleted += BgWorker_RunWorkerCompleted;

            // Status Progress Form
            Form fStatusDialog;

            logger = StatusUtil.CreateStatusDialog(pluginHost.MainWindow, out fStatusDialog, "Yet Another Favicon Downloader", "Downloading favicons...", true, false);

            // Block UI
            pluginHost.MainWindow.UIBlockInteraction(true);
        }
コード例 #6
0
ファイル: SearchForm.cs プロジェクト: 0xfeeddeadbeef/KeePass
        private void OnBtnOK(object sender, EventArgs e)
        {
            SearchParameters sp = GetSearchParameters();

            Form          fOptDialog;
            IStatusLogger sl = StatusUtil.CreateStatusDialog(this, out fOptDialog,
                                                             null, KPRes.SearchingOp + "...", true, false);

            // if(fOptDialog != null) Program.MainForm.RedirectActivationPush(fOptDialog);
            this.Enabled = false;

            PwGroup   pgResults = null;
            Exception exFind    = null;

            try { pgResults = SearchUtil.Find(sp, m_pgRoot, sl); }
            catch (Exception ex) { exFind = ex; }

            this.Enabled = true;
            // if(fOptDialog != null) Program.MainForm.RedirectActivationPop();
            sl.EndLogging();

            if (exFind != null)
            {
                MessageService.ShowWarning(sp.SearchString, exFind);
                this.DialogResult = DialogResult.None;
            }
            else if (pgResults != null)
            {
                m_pgResults = pgResults;
                m_spResult  = sp;
            }
            else
            {
                Debug.Assert(false);
                this.DialogResult = DialogResult.None;
            }
        }
コード例 #7
0
        private static string FindUI(MainForm mf, FsxMatchFn fMatch, string strRootPath)
        {
            if (mf == null)
            {
                Debug.Assert(false); return(null);
            }
            if (fMatch == null)
            {
                Debug.Assert(false); return(null);
            }

            Form          fOptDialog;
            IStatusLogger sl = StatusUtil.CreateStatusDialog(mf, out fOptDialog,
                                                             null, GetSearchingText(null), true, true);

            mf.UIBlockInteraction(true);

            List <FsxContext> lContexts = new List <FsxContext>();
            string            strExcp   = null;

            try { lContexts = Find(fMatch, sl, strRootPath); }
            catch (Exception ex) { strExcp = ex.Message; }

            bool bAborted = !sl.ContinueWork();

            mf.UIBlockInteraction(false);
            sl.EndLogging();

            if (!string.IsNullOrEmpty(strExcp))
            {
                MessageService.ShowWarning(strExcp);
                return(null);
            }

            Action <ListView> fInit = delegate(ListView lv)
            {
                int w  = lv.ClientSize.Width - UIUtil.GetVScrollBarWidth();
                int ws = w / 70;
                lv.Columns.Add(KPRes.File, w / 5);
                lv.Columns.Add(KPRes.Folder, (int)(((long)w * 2L) / 5L - (ws * 3)));
                lv.Columns.Add(KPRes.Size, w / 10 + ws, HorizontalAlignment.Right);
                lv.Columns.Add(KPRes.Type, w / 10 + ws);
                lv.Columns.Add(KPRes.LastModified, w / 5 + ws);
            };

            List <object> lItems = new List <object>();
            int           cFiles = 0;

            foreach (FsxContext ctx in lContexts)
            {
                List <FsxResult> lResults = ctx.GetResults();
                if (lResults.Count == 0)
                {
                    continue;
                }

                string strGroup = UrlUtil.EnsureTerminatingSeparator(ctx.RootDirectory, false);
                if (ctx.VolumeLabel.Length != 0)
                {
                    strGroup += " (" + ctx.VolumeLabel + ")";
                }
                lItems.Add(new ListViewGroup(strGroup));

                foreach (FsxResult r in lResults)
                {
                    try
                    {
                        FileInfo fi = new FileInfo(r.Path);

                        ListViewItem lvi = new ListViewItem(UrlUtil.GetFileName(r.Path));
                        lvi.SubItems.Add(UrlUtil.GetFileDirectory(r.Path, true, false));
                        lvi.SubItems.Add(StrUtil.FormatDataSizeKB((ulong)fi.Length));
                        lvi.SubItems.Add(r.Type);
                        lvi.SubItems.Add(TimeUtil.ToDisplayString(
                                             TimeUtil.ToLocal(fi.LastWriteTimeUtc, false)));
                        lvi.Tag = r.Path;

                        lItems.Add(lvi);
                        ++cFiles;
                    }
                    catch (Exception) { Debug.Assert(false); }
                }
            }

            string strSub = KPRes.ObjectsFound.Replace("{PARAM}", cFiles.ToString()) + ".";

            if (bAborted)
            {
                strSub += " " + (new OperationCanceledException()).Message;
            }

            ListViewForm dlg = new ListViewForm();

            dlg.InitEx(KPRes.SearchGroupName, strSub, null,
                       Properties.Resources.B48x48_XMag, lItems, null, fInit);
            UIUtil.ShowDialogAndDestroy(dlg, mf);

            return(dlg.ResultItem as string);
        }
コード例 #8
0
        private void UpdatePlugins(bool bUpdateTranslationsOnly)
        {
            PluginDebug.AddInfo("UpdatePlugins start ", DebugPrint);
            Form fUpdateLog = null;

            m_slUpdatePlugins = StatusUtil.CreateStatusDialog(GlobalWindowManager.TopWindow, out fUpdateLog, PluginTranslate.PluginUpdateCaption, string.Empty, true, true);

            bool   success            = false;
            string sTempPluginsFolder = PluginUpdateHandler.GetTempFolder();

            ThreadStart ts = new ThreadStart(() =>
            {
                m_slUpdatePlugins.StartLogging(PluginTranslate.PluginUpdateCaption, false);

                PluginDebug.AddInfo("Use temp folder", PluginUpdateHandler.Shieldify.ToString(), sTempPluginsFolder, DebugPrint);

                //Download files
                foreach (PluginUpdate upd in PluginUpdateHandler.Plugins)
                {
                    if (!upd.Selected)
                    {
                        continue;
                    }
                    success |= UpdatePlugin(upd, sTempPluginsFolder, bUpdateTranslationsOnly);
                }
            });
            Thread t = new Thread(ts);

            t.IsBackground = true;
            t.Start();
            while (true && t.IsAlive)
            {
                if (!m_slUpdatePlugins.ContinueWork())
                {
                    t.Abort();
                    break;
                }
            }
            if (t != null && t.IsAlive)
            {
                t.Abort();
            }
            if (m_slUpdatePlugins != null)
            {
                m_slUpdatePlugins.EndLogging();
                m_slUpdatePlugins = null;
            }
            if (fUpdateLog != null)
            {
                fUpdateLog.Dispose();
            }

            //Move files from temp folder to plugin folder
            success &= PluginUpdateHandler.MoveAll(sTempPluginsFolder);
            foreach (var pu in PluginUpdateHandler.Plugins)
            {
                if (!pu.Selected)
                {
                    continue;
                }
                if (pu is OwnPluginUpdate)
                {
                    (pu as OwnPluginUpdate).UpdateTranslationInfo(true);
                }
            }
            if (success)
            {
                PluginUpdateHandler.Cleanup(sTempPluginsFolder);
            }
            success = true;
            //Restart KeePass to use new plugin versions
            PluginDebug.AddInfo("Update finished", "Succes: " + success.ToString(), DebugPrint);
            if (success && !bUpdateTranslationsOnly)
            {
                if (Tools.AskYesNo(PluginTranslate.PluginUpdateSuccess, PluginTranslate.PluginUpdateCaption) == DialogResult.Yes)
                {
                    if (m_bRestartInvoke)
                    {
                        m_host.MainWindow.Invoke(new KeePassLib.Delegates.GAction(() => { Restart(); }));
                    }
                    else
                    {
                        Restart();
                    }
                }
            }
        }
コード例 #9
0
        private void OnClickFindEntry(object sender, EventArgs e)
        {
            string   f  = (sender as ToolStripItem).Name;
            FindInfo fi = SearchHelp.FindList.Find(x => x.Name == (sender as ToolStripItem).Name);

            if (CallStandardSearch(fi, (sender as ToolStripItem).Name))
            {
                if (fi != null)
                {
                    foreach (Delegate d in fi.StandardEventHandlers)
                    {
                        d.DynamicInvoke(new object[] { sender, e });
                    }
                }
                return;
            }

            PluginDebug.AddInfo("Call own find routine", 0, "Action: " + f);
            //Show status logger
            Form          fOptDialog = null;
            IStatusLogger sl         = StatusUtil.CreateStatusDialog(m_host.MainWindow, out fOptDialog, null,
                                                                     (KPRes.SearchingOp ?? "..."), true, false);

            m_host.MainWindow.UIBlockInteraction(true);

            m_aStandardLvInit = null;

            //Perform find for all open databases
            PwDatabase    dbAll = MergeDatabases();
            List <object> l     = null;

            try
            {
                object[] parameters;
                if (fi.SearchType != SearchType.BuiltIn)
                {
                    parameters = new object[] { dbAll, sl, null, fi }
                }
                ;
                else
                {
                    parameters = new object[] { dbAll, sl, null }
                };

                l = (List <object>)fi.StandardMethod.Invoke(m_host, parameters);
                m_aStandardLvInit = (Action <ListView>)parameters[2];
            }
            catch (Exception ex)
            {
                l = null;
                PluginDebug.AddError("Call standard find routine", 0, "Action: " + f, "Reason for standard call: " + ex.Message);
                foreach (Delegate d in fi.StandardEventHandlers)
                {
                    d.DynamicInvoke(new object[] { sender, e });
                }
            }
            finally { dbAll.Close(); }

            m_host.MainWindow.UIBlockInteraction(false);
            sl.EndLogging();

            if (l == null)
            {
                return;
            }

            //Fill db column
            ImageList il  = new ImageList();
            ImageList il2 = (ImageList)Tools.GetField("m_ilCurrentIcons", m_host.MainWindow);

            foreach (Image img in il2.Images)
            {
                il.Images.Add(img);
            }

            foreach (var o in l)
            {
                ListViewItem lvi = o as ListViewItem;
                if (lvi == null)
                {
                    continue;
                }
                ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem();
                if (lvi.Tag is PwEntry)
                {
                    lvsi.Text = SearchHelp.GetDBName(lvi.Tag as PwEntry);
                    PwEntry    pe = lvi.Tag as PwEntry;
                    PwDatabase db = m_host.MainWindow.DocumentManager.FindContainerOf(pe);
                    if (!pe.CustomIconUuid.Equals(PwUuid.Zero))
                    {
                        il.Images.Add(db.GetCustomIcon(pe.CustomIconUuid, DpiUtil.ScaleIntX(16), DpiUtil.ScaleIntY(16)));
                        lvi.ImageIndex = il.Images.Count - 1;
                    }
                    else
                    {
                        lvi.ImageIndex = (int)pe.IconId;
                    }
                }
                else if (lvi.Tag is PwGroup)
                {
                    PwGroup pg = lvi.Tag as PwGroup;
                    lvsi.Text = SearchHelp.GetDBName(pg.Entries.GetAt(0));
                }
                lvi.SubItems.Insert(0, lvsi);
            }

            if ((l.Count == 0) && !string.IsNullOrEmpty(fi.NothingFound))
            {
                Tools.ShowInfo(fi.NothingFound);
                il.Dispose();
                return;
            }

            //Show results
            ListViewForm dlg = new ListViewForm();

            //Prepare ImageList (CustomIcons can be different per database)
            dlg.InitEx(fi.Title, fi.SubTitle, fi.Note, fi.img, l, il, InitListView);
            UIUtil.ShowDialogAndDestroy(dlg);
            if (dlg.DialogResult != DialogResult.OK)
            {
                return;
            }
            il.Dispose();
            NavigateToSelectedEntry(dlg, false);
        }