示例#1
0
        private static void ImportIcon(XmlNode xn, PwEntry pe, PwDatabase pd)
        {
            XmlNode xnIcon = xn.Attributes.GetNamedItem("ICON");
            if(xnIcon == null) return;

            string strIcon = xnIcon.Value;
            if(!StrUtil.IsDataUri(strIcon)) { Debug.Assert(false); return; }

            try
            {
                byte[] pbImage = StrUtil.DataUriToData(strIcon);
                if((pbImage == null) || (pbImage.Length == 0)) { Debug.Assert(false); return; }

                Image img = GfxUtil.LoadImage(pbImage);
                if(img == null) { Debug.Assert(false); return; }

                byte[] pbPng;
                int wMax = PwCustomIcon.MaxWidth;
                int hMax = PwCustomIcon.MaxHeight;
                if((img.Width <= wMax) && (img.Height <= hMax))
                {
                    MemoryStream msPng = new MemoryStream();
                    img.Save(msPng, ImageFormat.Png);
                    pbPng = msPng.ToArray();
                    msPng.Close();
                }
                else
                {
                    Image imgSc = GfxUtil.ScaleImage(img, wMax, hMax);

                    MemoryStream msPng = new MemoryStream();
                    imgSc.Save(msPng, ImageFormat.Png);
                    pbPng = msPng.ToArray();
                    msPng.Close();

                    imgSc.Dispose();
                }
                img.Dispose();

                PwUuid pwUuid = null;
                int iEx = pd.GetCustomIconIndex(pbPng);
                if(iEx >= 0) pwUuid = pd.CustomIcons[iEx].Uuid;
                else
                {
                    pwUuid = new PwUuid(true);
                    pd.CustomIcons.Add(new PwCustomIcon(pwUuid, pbPng));
                    pd.UINeedsIconUpdate = true;
                    pd.Modified = true;
                }
                pe.CustomIconUuid = pwUuid;
            }
            catch(Exception) { Debug.Assert(false); }
        }
示例#2
0
        void InitalizeList(bool autodetect)
        {
            mCustomTreeViewEx.BeginUpdate();
              mCustomTreeViewEx.Nodes.Clear();
              mCachedNow = DateTime.Now;
              bool entriesFound = false;

              foreach (var db in ext.pluginHost.MainWindow.DocumentManager.GetOpenDatabases()) {
            mActiveDb = db;
            UpdateImageLists();

            TreeNode rootNode = null;
            var rootGroup = mActiveDb.RootGroup;
            if (rootGroup != null) {
              int nIconID = ((!rootGroup.CustomIconUuid.EqualsValue(PwUuid.Zero)) ?
            ((int)PwIcon.Count + mActiveDb.GetCustomIconIndex(
            rootGroup.CustomIconUuid)) : (int)rootGroup.IconId);
              if (rootGroup.Expires && (rootGroup.ExpiryTime <= mCachedNow)) {
            nIconID = (int)PwIcon.Expired;
              }

              rootNode = new TreeNode(rootGroup.Name, nIconID, nIconID);
              rootNode.Tag = rootGroup;
              rootNode.ForeColor = SystemColors.GrayText;

              if (mBoldFont != null) {
            rootNode.NodeFont = mBoldFont;
              }
              rootNode.ToolTipText = db.IOConnectionInfo.GetDisplayName();

              mCustomTreeViewEx.Nodes.Add(rootNode);

              entriesFound |= RecursiveAddGroup(rootNode, rootGroup, autodetect);
            }

            if (rootNode != null) {
              rootNode.Expand();
            }
              }
              mCustomTreeViewEx.EndUpdate();

              if (!entriesFound) {
            if (autodetect) {
              MessageService.ShowWarning("No entries with SSH keys were found.");
              Close();
            } else {
              // Use timer so that this dialog finishes displaying before attempting
              // the auto-detect routine.
              var autodetectDialogDelayTimer = new Timer();
              autodetectDialogDelayTimer.Interval = 100;
              autodetectDialogDelayTimer.Tick += (sender, e) =>
              {
            autodetectDialogDelayTimer.Stop();
            AskShouldAutodetect();
              };
              autodetectDialogDelayTimer.Start();
            }
              }
        }