/// Calculate time offset for all relevant entries /// Do NOT use Task.Run as this requires .NET 4.5 which will cause issues on Mono /// Mono reports .NET 4.0.3 being installed despite higher versions can be used /// This results in KeePass refusing to compile the plgx public static /*async*/ void GetTimingsAsync(KeePassLib.PwDatabase db) { //Don't use TraverseTree as db content might change during processing //and this will result in an exception since TraverseTree uses 'foreach' //Don't use Task at all (https://github.com/Rookiestyle/KeePassOTP/issues/31) KeePassLib.Delegates.GAction <object> act = new KeePassLib.Delegates.GAction <object>((object o) => { DateTime dtStart = DateTime.Now; IEnumerable <string> lURL = db.RootGroup.GetEntries(true). Where(e => OTPDAO.OTPDefined(e) != OTPDAO.OTPDefinition.None). //We're not interested in sites without OTP being set up Select(e => e.Strings.ReadSafe(KeePassLib.PwDefs.UrlField)).Distinct(); //We're not interested in duplicate URLs foreach (string url in lURL) { if (m_timeCorrectionUrls.ContainsKey(url)) { continue; } GetTimeCorrection(url); System.Threading.Thread.Sleep(100); } ; DateTime dtEnd = DateTime.Now; PluginDebug.AddInfo("Calculated OTP time corrections", 0, "Start: " + dtStart.ToLongTimeString(), "End: " + dtEnd.ToLongTimeString()); }); System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(act)); }
/// Calculate time offset for all relevant entries /// Do NOT use Task.Run as this requires .NET 4.5 which will cause issues on Mono /// Mono reports .NET 4.0.3 being installed despite higher versions can be used /// This results in KeePass refusing to compile the plgx private /* async */ void SetURL(string url) { m_url = url == null ? string.Empty : url; //Don't use Task at all (https://github.com/Rookiestyle/KeePassOTP/issues/31) KeePassLib.Delegates.GAction <object> act = new KeePassLib.Delegates.GAction <object>((object o) => { OTPTimeCorrection = GetTimeCorrection(url); }); System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(act)); }
private void CheckPluginLanguages(object o) { PluginUpdateHandler.LoadPlugins(false); if (!PluginConfig.Active) { return; } if (m_bPluginLanguagesChecked) { return; } m_bPluginLanguagesChecked = true; string translations = string.Empty; List <OwnPluginUpdate> lPlugins = new List <OwnPluginUpdate>(); foreach (PluginUpdate pu in PluginUpdateHandler.Plugins) { if (!PluginUpdateHandler.VersionsEqual(pu.VersionInstalled, pu.VersionAvailable)) { continue; } foreach (var t in pu.Translations) { if (t.NewTranslationAvailable || (PluginConfig.DownloadActiveLanguage && t.TranslationForCurrentLanguageAvailable)) { lPlugins.Add(pu as OwnPluginUpdate); break; } } } if (lPlugins.Count == 0) { return; } var arrPlugins = lPlugins.ConvertAll(x => x.ToString()).ToArray(); PluginDebug.AddInfo("Available translation updates", 0, arrPlugins); KeePassLib.Delegates.GAction DisplayTranslationForm = () => { using (TranslationUpdateForm t = new TranslationUpdateForm()) { t.InitEx(lPlugins); if (t.ShowDialog() == DialogResult.OK) { UpdatePluginTranslations(PluginConfig.DownloadActiveLanguage, t.SelectedPlugins); } } }; m_host.MainWindow.BeginInvoke(DisplayTranslationForm); }
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()); } } }