Ejemplo n.º 1
0
        public static bool PerformGlobal(List<PwDatabase> vSources,
            ImageList ilIcons)
        {
            Debug.Assert(vSources != null); if(vSources == null) return false;

            if(KeePassLib.Native.NativeLib.IsUnix())
            {
                if(!NativeMethods.TryXDoTool(true))
                {
                    MessageService.ShowWarning(KPRes.AutoTypeXDoToolRequiredGlobalVer);
                    return false;
                }
            }

            IntPtr hWnd;
            string strWindow;
            try
            {
                // hWnd = NativeMethods.GetForegroundWindowHandle();
                // strWindow = NativeMethods.GetWindowText(hWnd);
                NativeMethods.GetForegroundWindowInfo(out hWnd, out strWindow, true);
            }
            catch(Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; }

            if(string.IsNullOrEmpty(strWindow)) return false;
            if(!IsValidAutoTypeWindow(hWnd, true)) return false;

            PwObjectList<PwEntry> vList = new PwObjectList<PwEntry>();
            DateTime dtNow = DateTime.Now;

            EntryHandler eh = delegate(PwEntry pe)
            {
                // Ignore expired entries
                if(pe.Expires && (pe.ExpiryTime < dtNow)) return true;

                if(GetSequenceForWindow(pe, strWindow, true) != null)
                    vList.Add(pe);

                return true;
            };

            foreach(PwDatabase pwSource in vSources)
            {
                if(pwSource.IsOpen == false) continue;
                pwSource.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh);
            }

            if(vList.UCount == 1)
                AutoType.PerformInternal(vList.GetAt(0), strWindow);
            else if(vList.UCount > 1)
            {
                EntryListForm elf = new EntryListForm();
                elf.InitEx(KPRes.AutoTypeEntrySelection, KPRes.AutoTypeEntrySelectionDescShort,
                    KPRes.AutoTypeEntrySelectionDescLong,
                    Properties.Resources.B48x48_KGPG_Key2, ilIcons, vList);
                elf.EnsureForeground = true;

                if(elf.ShowDialog() == DialogResult.OK)
                {
                    try { NativeMethods.EnsureForegroundWindow(hWnd); }
                    catch(Exception) { Debug.Assert(false); }

                    if(elf.SelectedEntry != null)
                        AutoType.PerformInternal(elf.SelectedEntry, strWindow);
                }
                UIUtil.DestroyForm(elf);
            }

            return true;
        }
        public static PwEntry show_parent_template_chooser(IPluginHost m_host)
        {
            EntryListForm elf = new EntryListForm();
            PwObjectList<PwEntry> entries = GetPossibleTemplates(m_host);
            elf.InitEx("Select Parent Template Entry", "Selecting Parent Template Entry", "Select the parent entry to use as a template", Resources.Resources.B48x48_Folder_Txt, m_host.MainWindow.ClientIcons, entries);
            elf.EnsureForeground = true;

            if (elf.ShowDialog() != DialogResult.OK || elf.SelectedEntry == null)
                return null;
            return elf.SelectedEntry;
        }
Ejemplo n.º 3
0
        public static bool PerformGlobal(List<PwDatabase> vSources,
            ImageList ilIcons)
        {
            Debug.Assert(vSources != null); if(vSources == null) return false;

            IntPtr hWnd;
            string strWindow;

            try
            {
                hWnd = NativeMethods.GetForegroundWindow();
                strWindow = NativeMethods.GetWindowText(hWnd);
            }
            catch(Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; }

            if((strWindow == null) || (strWindow.Length == 0)) return false;

            PwObjectList<PwEntry> m_vList = new PwObjectList<PwEntry>();

            DateTime dtNow = DateTime.Now;

            EntryHandler eh = delegate(PwEntry pe)
            {
                // Ignore expired entries
                if(pe.Expires && (pe.ExpiryTime < dtNow)) return true;

                if(GetSequenceForWindow(pe, strWindow, true) != null)
                    m_vList.Add(pe);

                return true;
            };

            foreach(PwDatabase pwSource in vSources)
            {
                if(pwSource.IsOpen == false) continue;
                pwSource.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh);
            }

            if(m_vList.UCount == 1)
                AutoType.PerformInternal(m_vList.GetAt(0), strWindow);
            else if(m_vList.UCount > 1)
            {
                EntryListForm elf = new EntryListForm();
                elf.InitEx(KPRes.AutoTypeEntrySelection, KPRes.AutoTypeEntrySelectionDescShort,
                    KPRes.AutoTypeEntrySelectionDescLong,
                    Properties.Resources.B48x48_KGPG_Key2, ilIcons, m_vList);
                elf.EnsureForeground = true;

                if(elf.ShowDialog() == DialogResult.OK)
                {
                    try { NativeMethods.EnsureForegroundWindow(hWnd); }
                    catch(Exception) { Debug.Assert(false); }

                    if(elf.SelectedEntry != null)
                        AutoType.PerformInternal(elf.SelectedEntry, strWindow);
                }
            }

            return true;
        }