private void Lv_DrawItem(object sender, DrawListViewItemEventArgs e) { AceColumn colPw = KeePass.Program.Config.MainWindow.FindColumn(AceColumnType.Password); string m = string.Empty; if (((colPw == null) || colPw.HideWithAsterisks) && !SinglePwDisplay.PasswordShown(e.Item)) { //Let the OS draw in case no other handlers exist //If other handlers exist, we pass their value for DrawDefault e.DrawDefault = true; if (colPw == null) { m = "Password column not found"; } else { m = "Password column found, password hidden"; } List <string> lCol = new List <string>(); foreach (var c in KeePass.Program.Config.MainWindow.EntryListColumns) { lCol.Add(c.GetDisplayName()); } PluginDebug.AddInfo(m, 0, lCol.ToArray()); return; } e.DrawDefault = false; m = "Password column found, password shown"; PluginDebug.AddSuccess(m, 0); if ((e.State & ListViewItemStates.Selected) != 0) { e.DrawFocusRectangle(); } }
private void HookOtherTimers(bool activate) { foreach (KeyValuePair <string, object> kvp in m_OtherTimers) { if (kvp.Value == null) { PluginDebug.AddError("Hook other timers", 2, "Object: " + kvp.Key, "Hook/Unhook: " + (activate ? "Hook" : "Unhook"), "Error: Object is null"); return; } if (kvp.Value is System.Timers.Timer) { if (activate) { (kvp.Value as System.Timers.Timer).Elapsed += OnUIStateUpdated; } else { (kvp.Value as System.Timers.Timer).Elapsed -= OnUIStateUpdated; } } if (kvp.Value is Timer) { if (activate) { (kvp.Value as Timer).Tick += OnUIStateUpdated; } else { (kvp.Value as Timer).Tick -= OnUIStateUpdated; } } PluginDebug.AddSuccess("Hook other timers", 2, "Object: " + kvp.Key, "Hook/Unhook: " + (activate ? "Hook" : "Unhook")); } }
public override bool Initialize(IPluginHost host) { m_host = host; PluginTranslate.Init(this, KeePass.Program.Translation.Properties.Iso6391Code); Tools.DefaultCaption = PluginTranslate.PluginName; Tools.PluginURL = "https://github.com/rookiestyle/coloredpassword/"; m_menu = new ToolStripMenuItem(Tools.DefaultCaption + "..."); m_menu.Image = SmallIcon; m_menu.Click += (o, e) => Tools.ShowOptions(); m_host.MainWindow.ToolsMenu.DropDownItems.Add(m_menu); Tools.OptionsFormShown += OptionsShown; Tools.OptionsFormClosed += OptionsClosed; ColorConfig.Read(); m_lvEntries = (ListView)Tools.GetControl("m_lvEntries"); if (m_lvEntries != null) { PluginDebug.AddSuccess("m_lvEntries found", 0); m_host.MainWindow.FormLoadPost += MainWindow_FormLoadPost; } else { PluginDebug.AddError("m_lvEntries not found", 0); } ColorPasswords(ColorConfig.Active); GlobalWindowManager.WindowAdded += OnWindowAdded; SinglePwDisplay.Enabled = ColorConfig.SinglePwDisplayActive; return(true); }
private void OnFormShown(object sender, EventArgs e) { PwEditMode m = PwEditMode.Invalid; PropertyInfo pEditMode = typeof(PwEntryForm).GetProperty("EditModeEx"); if (pEditMode != null) //will work starting with KeePass 2.41, preferred way as it's a public attribute { m = (PwEditMode)pEditMode.GetValue(m_pweForm, null); } else // try reading private field { m = (PwEditMode)Tools.GetField("m_pwEditMode", m_pweForm); } PluginDebug.AddSuccess("Entryform shown, editmode: " + m.ToString(), 0); if ((m != PwEditMode.AddNewEntry) && (m != PwEditMode.EditExistingEntry)) { return; } CustomContextMenuStripEx ctx = (CustomContextMenuStripEx)Tools.GetField("m_ctxDefaultTimes", m_pweForm); if (ctx != null) { ctx.Items.Add(new ToolStripSeparator()); ToolStripMenuItem tsmiPED = CreatePEDMenu(false, true); ctx.Items.Add(tsmiPED); PluginDebug.AddSuccess("Found m_ctxDefaultTimes", 0); } else { PluginDebug.AddError("Could not find m_ctxDefaultTimes", 0); } PEDCalcValue ped = m_pweForm.EntryRef.GetPEDValue(true); CheckBox cbExpires = (CheckBox)Tools.GetControl("m_cbExpires", m_pweForm); DateTimePicker dtExpireDate = (DateTimePicker)Tools.GetControl("m_dtExpireDateTime", m_pweForm); DateTime expiry = ped.NewExpiryDateUtc.ToLocalTime(); if (m == PwEditMode.EditExistingEntry) { cbExpires.CheckedChanged += (o, e1) => CheckShowNewExpireDate(); dtExpireDate.ValueChanged += (o, e1) => CheckShowNewExpireDate(); SecureTextBoxEx password = (SecureTextBoxEx)Tools.GetControl("m_tbPassword", m_pweForm); password.TextChanged += (o, e1) => CheckShowNewExpireDate(); Label lNewExpireDate = new Label(); lNewExpireDate.Name = "PEDCalc_NewExpireDate"; string sDate = string.Empty; m_iSelectedEntries = (int)m_host.MainWindow.GetSelectedEntriesCount(); if ((Tools.KeePassVersion >= Configuration.KeePassMultipleEntries) && (m_iSelectedEntries > 1)) { PropertyInfo piMultiple = typeof(KeePass.Resources.KPRes).GetProperty("MultipleValues"); if (piMultiple != null) { sDate = piMultiple.GetValue(null, null) as string; } else { sDate = "?"; } } else if (dtExpireDate.Format == DateTimePickerFormat.Long) { sDate = expiry.ToLongDateString(); } else if (dtExpireDate.Format == DateTimePickerFormat.Short) { sDate = expiry.ToShortDateString(); } else if (dtExpireDate.Format == DateTimePickerFormat.Time) { sDate = expiry.ToLongTimeString(); } else { sDate = expiry.ToString(dtExpireDate.CustomFormat); } lNewExpireDate.Text = PluginTranslate.PluginName + ": " + sDate; lNewExpireDate.Left = dtExpireDate.Left; lNewExpireDate.Top = dtExpireDate.Top + dtExpireDate.Height + 2; lNewExpireDate.Width = dtExpireDate.Width; ToolTip tt = new ToolTip(); tt.ToolTipTitle = PluginTranslate.PluginName; tt.ToolTipIcon = ToolTipIcon.Info; tt.SetToolTip(lNewExpireDate, PluginTranslate.NewExpiryDateTooltip); dtExpireDate.Parent.Controls.Add(lNewExpireDate); int h = dtExpireDate.Parent.ClientSize.Height; if (h < lNewExpireDate.Top + lNewExpireDate.Height + 2) { h = lNewExpireDate.Top + lNewExpireDate.Height + 2 - h; } else { h = 0; } try { dtExpireDate.Parent.Parent.Height += h; } catch { } CheckShowNewExpireDate(); } if (m == PwEditMode.AddNewEntry) { if (ped.Off) { return; } if ((cbExpires == null) || (dtExpireDate == null)) { Tools.ShowError(string.Format(PluginTranslate.ErrorInitExpiryDate, expiry.ToString())); return; } m_pweForm.EntryRef.ExpiryTime = dtExpireDate.Value = expiry; m_pweForm.EntryRef.Expires = cbExpires.Checked = true; PwEntry peInitialEntry = (PwEntry)Tools.GetField("m_pwInitialEntry", m_pweForm); if (peInitialEntry != null) { peInitialEntry.Expires = true; peInitialEntry.ExpiryTime = expiry.ToUniversalTime(); } } }
private void OnUpdateCheckFormShown(object sender, EventArgs e) { m_lEventHandlerItemActivate = null; PluginDebug.AddSuccess("OUCFS 1", 0); if (!PluginConfig.Active || !PluginConfig.OneClickUpdate) { return; } PluginDebug.AddSuccess("OUCFS 2", 0); CustomListViewEx lvPlugins = (CustomListViewEx)Tools.GetControl("m_lvInfo", sender as UpdateCheckForm); if (lvPlugins == null) { PluginDebug.AddError("m_lvInfo not found", 0); return; } else { PluginDebug.AddSuccess("m_lvInfo found", 0); } PluginUpdateHandler.LoadPlugins(false); if (PluginUpdateHandler.Plugins.Count == 0) { return; } SetPluginSelectionStatus(false); bool bColumnAdded = false; m_lEventHandlerItemActivate = EventHelper.GetItemActivateHandlers(lvPlugins); if (m_lEventHandlerItemActivate.Count > 0) { EventHelper.RemoveItemActivateEventHandlers(lvPlugins, m_lEventHandlerItemActivate); lvPlugins.ItemActivate += LvPlugins_ItemActivate; } //https://github.com/mono/mono/issues/17747 //Do NOT use ListView.SmallImageList if (m_ImgApply == null) { m_ImgApply = (Image)KeePass.Program.Resources.GetObject("B16x16_Apply"); } if (m_ImgUnselected == null) { m_ImgUnselected = m_ImgApply == null ? null : UIUtil.CreateGrayImage(m_ImgApply); } foreach (ListViewItem item in lvPlugins.Items) { PluginDebug.AddInfo("Check plugin update status", 0, item.SubItems[0].Text, item.SubItems[1].Text); if (!item.SubItems[1].Text.Contains(KeePass.Resources.KPRes.NewVersionAvailable)) { continue; } foreach (PluginUpdate upd in PluginUpdateHandler.Plugins) { if (item.SubItems[0].Text != upd.Title) { continue; } if (upd.UpdateMode == UpdateOtherPluginMode.Unknown) { continue; } if (!bColumnAdded) { lvPlugins.Columns.Add(PluginTranslate.PluginUpdate); bColumnAdded = true; } ListViewItem.ListViewSubItem lvsiUpdate = new ListViewItem.ListViewSubItem(item, PluginTranslate.PluginUpdate); lvsiUpdate.Tag = upd; item.SubItems.Add(lvsiUpdate); upd.Selected = true; try { upd.VersionAvailable = new Version(item.SubItems[3].Text); } catch (Exception ex) { PluginDebug.AddError("Could not parse new version", 0, upd.Name, item.SubItems[3].Text, ex.Message); } break; } } if (bColumnAdded) { UIUtil.ResizeColumns(lvPlugins, new int[] { 3, 3, 2, 2, 1 }, true); lvPlugins.MouseClick += OnUpdateCheckFormPluginMouseClick; lvPlugins.OwnerDraw = true; lvPlugins.DrawSubItem += LvPlugins_DrawSubItem; lvPlugins.DrawColumnHeader += LvPlugins_DrawColumnHeader; ShowUpdateButton(sender as Form, true); } if (m_lEventHandlerItemActivate.Count == 0) { if (lvPlugins.ContextMenuStrip == null) { lvPlugins.ContextMenuStrip = new ContextMenuStrip(); string sMenuText = KeePass.Resources.KPRes.PluginsDesc; try { sMenuText = Tools.GetControl("m_linkPlugins", sender as UpdateCheckForm).Text; } catch { } lvPlugins.ContextMenuStrip.Items.Add(new ToolStripMenuItem(sMenuText, null, OnReleasePageClick)); lvPlugins.ContextMenuStrip.Opening += ContextMenuStrip_Opening; } else { PluginDebug.AddWarning("m_lvEntries.ContextMenuStrip already defined, special handling for added 'go to release page' to be defined", 0); } } }
private void UpdateCheckBackground() { List <string> lMsg = new List <string>(); string sBackup = KeePass.Program.Config.Application.LastUpdateCheck; KeePass.Program.Config.Application.LastUpdateCheck = TimeUtil.SerializeUtc(DateTime.UtcNow); bool bOK = true; MethodInfo miGetInstalledComponents = typeof(UpdateCheckEx).GetMethod("GetInstalledComponents", BindingFlags.Static | BindingFlags.NonPublic); if (miGetInstalledComponents == null) { bOK = false; lMsg.Add("Could not locate UpdateCheckEx.GetInstalledComponents"); } MethodInfo miGetUrls = typeof(UpdateCheckEx).GetMethod("GetUrls", BindingFlags.Static | BindingFlags.NonPublic); if (miGetUrls == null) { bOK = false; lMsg.Add("Could not locate UpdateCheckEx.GetUrls"); } MethodInfo miDownloadInfoFiles = typeof(UpdateCheckEx).GetMethod("DownloadInfoFiles", BindingFlags.Static | BindingFlags.NonPublic); if (miDownloadInfoFiles == null) { bOK = false; lMsg.Add("Could not locate UpdateCheckEx.DownloadInfoFiles"); } MethodInfo miMergeInfo = typeof(UpdateCheckEx).GetMethod("MergeInfo", BindingFlags.Static | BindingFlags.NonPublic); if (miMergeInfo == null) { bOK = false; lMsg.Add("Could not locate UpdateCheckEx.MergeInfo"); } try { m_bRestartInvoke = true; KeePassLib.Delegates.GAction actUpdateCheck = new KeePassLib.Delegates.GAction(() => { //taken from UpdateCheckExt.RunPriv //MainForm.InvokeRequired is not true on Mono :( try { lock (m_lock) { m_UpdateCheckStatus = UpdateCheckStatus.Checking; } List <UpdateComponentInfo> lInst = (List <UpdateComponentInfo>)miGetInstalledComponents.Invoke(null, null); List <string> lUrls = (List <string>)miGetUrls.Invoke(null, new object[] { lInst }); Dictionary <string, List <UpdateComponentInfo> > dictAvail = (Dictionary <string, List <UpdateComponentInfo> >)miDownloadInfoFiles.Invoke(null, new object[] { lUrls, null /* m_slUpdateCheck */ }); if (dictAvail == null) { return; // User cancelled } miMergeInfo.Invoke(null, new object[] { lInst, dictAvail }); bool bUpdAvail = false; foreach (UpdateComponentInfo uc in lInst) { if (uc.Status == UpdateComponentStatus.NewVerAvailable) { bUpdAvail = true; break; } } if (m_slUpdateCheck != null) { m_host.MainWindow.Invoke(new KeePassLib.Delegates.GAction(() => { m_slUpdateCheck.EndLogging(); })); m_slUpdateCheck = null; } KeePassLib.Delegates.GAction actShowUpdateForm_UIThread = new KeePassLib.Delegates.GAction(() => { try { // Do not show the update dialog while auto-typing; // https://sourceforge.net/p/keepass/bugs/1265/ if (SendInputEx.IsSending) { return; } UpdateCheckForm dlg = new UpdateCheckForm(); dlg.InitEx(lInst, false); var dr = UIUtil.ShowDialogAndDestroy(dlg); } catch (Exception ex) { bOK = false; lMsg.Add(ex.Message); } }); if (bUpdAvail) { m_host.MainWindow.BeginInvoke(actShowUpdateForm_UIThread); } } catch (Exception ex) { bOK = false; lMsg.Add(ex.Message); } finally { try { if (m_slUpdateCheck != null) { m_slUpdateCheck.EndLogging(); } } catch (Exception) { } if (bOK) { lock (m_lock) { m_UpdateCheckStatus = UpdateCheckStatus.Checked; } } else { lock (m_lock) { m_UpdateCheckStatus = UpdateCheckStatus.Error; } } } }); if (bOK) { try { m_slUpdateCheck = CreateUpdateCheckLogger(); lMsg.Add("Initialising StatusLogger create: " + DebugPrint); } catch (Exception ex) { lMsg.Add("Initialising StatusLogger failed:\n" + ex.Message + "\n" + DebugPrint); } ThreadPool.QueueUserWorkItem(new WaitCallback((object o) => { actUpdateCheck(); })); } while (true) { if ((m_slUpdateCheck != null) && !m_slUpdateCheck.ContinueWork()) { break; } lock (m_lock) { if (m_UpdateCheckStatus == UpdateCheckStatus.Checked) { break; } if (m_UpdateCheckStatus == UpdateCheckStatus.Error) { break; } } } if (m_slUpdateCheck != null) { m_slUpdateCheck.EndLogging(); } if (bOK) { return; } } catch (Exception ex) { bOK = false; lMsg.Add(ex.Message); } finally { lMsg.Insert(0, "Successful: " + bOK.ToString()); if (bOK) { PluginDebug.AddSuccess("Run updatecheck in background", 0, lMsg.ToArray()); } else { PluginDebug.AddError("Run updatecheck in background", 0, lMsg.ToArray()); } } }
private void Restart() { PluginDebug.AddInfo("Restart started", DebugPrint); if (m_kpf != null) { PluginDebug.AddInfo("Closing KeyPromptForm", 0, DebugPrint); m_kpf.DialogResult = DialogResult.Cancel; if (m_kpf != null) { m_kpf.Close(); } if (m_kpf != null) { m_kpf.Dispose(); } Application.DoEvents(); if (m_kpf != null) { GlobalWindowManager.RemoveWindow(m_kpf); } } if (m_slUpdateCheck != null) { PluginDebug.AddInfo("Closing update check progress form", 0, DebugPrint); m_slUpdateCheck.EndLogging(); } if (MonoWorkarounds.IsRequired(620618)) { MethodInfo miSetEnabled = typeof(MonoWorkarounds).GetMethod("SetEnabled", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (miSetEnabled == null) { PluginDebug.AddError("Could not locate MonoWorkarounds.SetEnabled", 0); } else { miSetEnabled.Invoke(null, new object[] { "620618", false }); } if (MonoWorkarounds.IsRequired(620618)) { PluginDebug.AddError("Could not disable MonoWorkaround 620618"); } else { PluginDebug.AddSuccess("Disabled MonoWorkaround 620618"); } } else { PluginDebug.AddSuccess("Disabling MonoWorkaround 620618 not required"); } FieldInfo fi = m_host.MainWindow.GetType().GetField("m_bRestart", BindingFlags.NonPublic | BindingFlags.Instance); if (fi != null) { PluginDebug.AddInfo("Restart started, m_bRestart found", DebugPrint); RemoveAndBackupFormLoadPostHandlers(); HandleMutex(true); fi.SetValue(m_host.MainWindow, true); m_host.MainWindow.ProcessAppMessage((IntPtr)KeePass.Program.AppMessage.Exit, IntPtr.Zero); HandleMutex(false); } else { PluginDebug.AddError("Restart started, m_bRestart not found" + DebugPrint); } }