Exemplo n.º 1
0
        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);
                }
            }
        }