Exemple #1
0
 private void WindowAdded(object sender, GwmWindowEventArgs e)
 {
     if (!PluginConfig.Active)
     {
         return;
     }
     PluginDebug.AddInfo("Form added", 0, e.Form.Name, e.Form.GetType().FullName, DebugPrint);
     if (e.Form is UpdateCheckForm)
     {
         if (m_CheckProgress != null && !m_CheckProgress.IsDisposed && !m_CheckProgress.Disposing)
         {
             if (!KeePassLib.Native.NativeLib.IsUnix())
             {
                 m_CheckProgress.Hide();                                                            //Makes KeePass freeze sometimes... How I love randomness in development...
             }
             lock (m_lock) { m_UpdateCheckStatus = UpdateCheckStatus.Checked; }
         }
         if (PluginConfig.OneClickUpdate)
         {
             PluginDebug.AddInfo("OneClickUpdate 1", 0, DebugPrint);
             e.Form.Shown += OnUpdateCheckFormShown;
             PluginDebug.AddInfo("OneClickUpdate 2", 0, DebugPrint);
         }
         return;
     }
     if (e.Form is KeyPromptForm)
     {
         KeyPromptFormAdded();
     }
     if (e.Form is LanguageForm)
     {
         e.Form.Shown += LanguageFormAdded;
     }
 }
Exemple #2
0
        public void CheckForUpdates()
        {
            InErrorException = null;
            if (!ApplicationDeployment.IsNetworkDeployed)
            {
                CurrentStatus = UpdateCheckStatus.IsNotNetworkDeployed;
                return;
            }
            try
            {
                UpdateCheckInfo info = ApplicationDeployment.CurrentDeployment.CheckForDetailedUpdate();
                if (!info.UpdateAvailable)
                {
                    CurrentStatus = UpdateCheckStatus.NoUpdateAvailable;
                    return;
                }

                if (info.IsUpdateRequired)
                {
                    CurrentStatus = UpdateCheckStatus.MandatoryUpdateAvailable;
                    return;
                }

                CurrentStatus = UpdateCheckStatus.OptionalUpdateAvailable;
            }
            catch (Exception e)
            {
                CurrentStatus    = UpdateCheckStatus.InError;
                InErrorException = e;
            }
        }
        internal void MenuShown()
        {
            MenuVisible = true;
            if (updateStatus == UpdateCheckStatus.NotStarted)
            {
                updater.StartUpdateCheckAsync();
                updateStatus = UpdateCheckStatus.InProgress;
            }

            TryShowUpdateMessage();
        }
        private void UpdateCheckDone(XmlDocument doc)
        {
#if DEBUG
            Log.WriteFormat("UpdateCheckDone: {0}", doc);
#endif
            if (doc == null)
            {
                updateStatus = UpdateCheckStatus.Failed;
            }
            else
            {
                updateStatus = UpdateCheckStatus.Done;
                doc.Save(configPath);
                ReadUpdateStatus(doc);
            }

            TryShowUpdateMessage();
        }
 public void CheckForUpdates()
 {
     try
     {
         if (GetOnlineVersion() > GetCurrentVersion())
         {
             CurrentStatus = UpdateCheckStatus.MandatoryUpdateAvailable;
         }
         else
         {
             CurrentStatus = UpdateCheckStatus.NoUpdateAvailable;
         }
     }
     catch
     {
         CurrentStatus = UpdateCheckStatus.InError;
     }
 }
Exemple #6
0
        public void InstallUpdateSyncWithInfo()
        {
            CheckForUpdates();
            switch (CurrentStatus)
            {
            case UpdateCheckStatus.OptionalUpdateAvailable:
            case UpdateCheckStatus.MandatoryUpdateAvailable:
            {
                DialogResult dr = MessageBox.Show(LanguageManager.Language["STR_UPDATE_AVAILABLE_TEXT"], LanguageManager.Language["STR_UPDATE_AVAILABLE_TITLE"], MessageBoxButtons.OKCancel);
                if ((DialogResult.OK == dr))
                {
                    CurrentStatus = UpdateCheckStatus.Updating;
                    try
                    {
                        DownloadUpdate();
                        CompleteUpdate_part1();
                    }
                    catch (Exception dde)
                    {
                        MessageBox.Show(LanguageManager.Language["STR_UPDATE_ERROR_TEXT"].Replace("\\n", "\n") + ": " + dde, LanguageManager.Language["STR_UPDATE_ERROR_TITLE"]);
                        return;
                    }
                }
                break;
            }

            case UpdateCheckStatus.NoUpdateAvailable:
            case UpdateCheckStatus.IsNotNetworkDeployed:
            {
                MessageBox.Show(LanguageManager.Language["STR_UPDATE_NO_TEXT"], LanguageManager.Language["STR_UPDATE_NO_TITLE"]);
                break;
            }

            case UpdateCheckStatus.InError:
            {
                MessageBox.Show(LanguageManager.Language["STR_UPDATE_ERROR1_TEXT"] + ":" + InErrorException.Message, LanguageManager.Language["STR_UPDATE_ERROR1_TITLE"]);
                break;
            }

            default:
                break;
            }
        }
        private void CheckForUpdates_Click(object sender, RoutedEventArgs e)
        {
            if (_config == null || _appName == null || _appName.Length <= 0)
            {
                return;
            }

            UpdateCheckStatus.Inlines.Clear();
            UpdateCheckStatus.Text = "Checking for updates... (" + DateTime.Now.ToString() + ")";

            try
            {
                string         html    = string.Empty;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://updates.b******g.io/updates.json");
                request.AutomaticDecompression = DecompressionMethods.GZip;

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    using (Stream stream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            html = reader.ReadToEnd();
                        }

                var json   = JObject.Parse(html);
                var latest = json[_appName]["version"]?.ToString();
                if (latest == null)
                {
                    return;
                }

                // Why isn't this just using the AssemblyVersion?!?!
                var    dashPosition = AboutVersionNumber.Text.IndexOf('-');
                string numericVer;
                numericVer = dashPosition >= 0 ? AboutVersionNumber.Text.Substring(0, dashPosition) : AboutVersionNumber.Text;
                var cVer = Version.Parse(numericVer);
                var lVer = Version.Parse(latest);

                // Reverse this sign to test
                if (cVer.CompareTo(lVer) < 0)
                {
                    // Update available
                    UpdateCheckStatus.Text = "Update Available! (" + DateTime.Now.ToString() + ")";
                    Hyperlink hyperlink = null;
                    try
                    {
                        var location = json[_appName]["location"]?.ToString();
                        if (location != null)
                        {
                            hyperlink = new Hyperlink(new Run(location))
                            {
                                NavigateUri = new Uri(location),
                            };
                            hyperlink.RequestNavigate += Hyperlink_RequestNavigate;
                            UpdateCheckStatus.Text    += "\n";
                            UpdateCheckStatus.Inlines.Add(hyperlink);
                        }
                    }
                    catch
                    {
                        // noop - there was an update, we just don't know where
                    }

                    if (MessageBox.Show("A new b******g update is available! Would you like to go to the update site?",
                                        "B******g Update",
                                        MessageBoxButton.YesNo,
                                        MessageBoxImage.Asterisk) == MessageBoxResult.Yes)
                    {
                        hyperlink?.DoClick();
                    }

                    try
                    {
                        ((TabControl)((TabItem)Parent).Parent).SelectedItem = Parent;
                        UpdateCheckStatus.Focus();
                    }
                    catch
                    {
                        // noop - things went bang
                    }
                }
                else
                {
                    UpdateCheckStatus.Text = "No new updates! (" + DateTime.Now.ToString() + ")";
                }
            }
            catch (Exception ex)
            {
                UpdateCheckStatus.Text = "Error encountered whilst checking for updates! (" + DateTime.Now.ToString() + ")";
                new ButtplugLogManager().GetLogger(GetType()).LogException(ex);
            }
        }
Exemple #8
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());
                }
            }
        }
Exemple #9
0
 public UpdateException(UpdateCheckStatus status, string msg = null) : base(msg) => Status = status;