Beispiel #1
0
 private static void ShowUpdateDialogPriv(List <UpdateComponentInfo> lInst,
                                          bool bModal)
 {
     try
     {
         UpdateCheckForm dlg = new UpdateCheckForm();
         dlg.InitEx(lInst, bModal);
         UIUtil.ShowDialogAndDestroy(dlg);
     }
     catch (Exception) { Debug.Assert(false); }
 }
Beispiel #2
0
		private static void ShowUpdateDialogPriv(List<UpdateComponentInfo> lInst,
			bool bModal)
		{
			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, bModal);
				UIUtil.ShowDialogAndDestroy(dlg);
			}
			catch(Exception) { Debug.Assert(false); }
		}
        /// <summary>
        /// Used to modify other form when they load.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void WindowAddedHandler(object sender, GwmWindowEventArgs e)
        {
            // If a database is attempted to be unlocked
            if (e.Form is KeyPromptForm keyPromptForm)
            {
                keyPromptForm.Opacity = 0;
                keyPromptForm.Visible = false;
                var mf = KeePass.Program.MainForm;
                isAutoTyping = (bool)mf.GetType().GetField("m_bIsAutoTyping", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(mf);

                var    fieldInfo        = keyPromptForm.GetType().GetField("m_ioInfo", BindingFlags.Instance | BindingFlags.NonPublic);
                var    ioInfo           = fieldInfo.GetValue(keyPromptForm) as IOConnectionInfo;
                string dbName           = Library.CharChange(ioInfo.Path);
                bool   isHelloAvailable = await UWPLibrary.IsHelloAvailable();

                // if the database has credentials saved and Windows Hello is available
                if (!await UWPLibrary.FirstTime(dbName) && isHelloAvailable)
                {
                    // If there is no other Windows Hello Prompt opened
                    if (opened)
                    {
                        opened = false;

                        Library.UnlockDatabase(ioInfo, keyPromptForm);
                    }
                    else // If there is another Windows Hello Prompt opened, just close this regular prompt
                         // This is usefull for when there is a double attempt to unlock the database by some plugins (ChromeIPass)
                    {
                        Library.CloseFormWithResult(keyPromptForm, DialogResult.Cancel);
                    }
                }
                else if (!await UWPLibrary.FirstTime(dbName))
                {
                    MessageService.ShowInfo("This Database has credential data saved. Enable Windows Hello to use.");
                    keyPromptForm.Opacity = 1;
                    keyPromptForm.Visible = true;
                }
                else
                {
                    keyPromptForm.Opacity = 1;
                    keyPromptForm.Visible = true;
                }
            }

            // If the Options window is opened
            if (e.Form is OptionsForm optionsForm)
            {
                if (!host.MainWindow.ActiveDatabase.IsOpen)
                {
                    return;                                         //  If there is no database opened, don't do anything
                }
                optionsForm.Shown += (object sender2, EventArgs e2) =>
                {
                    try
                    {
                        Library.AddWinHelloOptions(optionsForm);
                    }
                    catch (Exception ex)
                    {
                        MessageService.ShowWarning("WinHelloUnlock Error: " + ex.Message);
                    }
                };
            }

            // If the Update Check Window is opened.
            // This is used because the Update Check Window prevents the a database from being opened
            if (e.Form is UpdateCheckForm ucf && !opened)
            {
                WinHelloUnlockExt.updateCheckForm = ucf;
            }
        }
Beispiel #4
0
        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)
                {
                    UpdateCheckForm dlg = new UpdateCheckForm();
                    dlg.InitEx(lInst, p.ForceUI);
                    UIUtil.ShowDialogAndDestroy(dlg);
                }
            }
            catch (Exception) { Debug.Assert(false); }
            finally
            {
                try { if (sl != null)
                      {
                          sl.EndLogging();
                      }
                }
                catch (Exception) { Debug.Assert(false); }
            }
        }
Beispiel #5
0
        private void OnCheckForUpdate(SyncStatus status)
        {
            UpdateCheckForm form = new UpdateCheckForm(this.Configurator);

            this.SnapIn.Console.ShowDialog(form);
        }
Beispiel #6
0
        private void OnUpdateCheckAction(SyncStatus status)
        {
            UpdateCheckForm form = new UpdateCheckForm(this.GetConfigurator());

            this.SnapIn.Console.ShowDialog(form);
        }
Beispiel #7
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());
                }
            }
        }