Exemplo n.º 1
0
        private static Image GetImage(PwIcon ic, PwUuid puCustom)
        {
            MainForm   mf = Program.MainForm;
            PwDatabase pd = mf.ActiveDatabase;

            if ((pd == null) || !pd.IsOpen)
            {
                Debug.Assert(false); return(null);
            }

            ImageList il = mf.ClientIcons;

            if (il == null)
            {
                Debug.Assert(false); return(null);
            }

            int i;

            if (puCustom.Equals(PwUuid.Zero))
            {
                i = (int)ic;
            }
            else
            {
                i = (int)PwIcon.Count + pd.GetCustomIconIndex(puCustom);
            }

            if ((i < 0) || (i >= il.Images.Count))
            {
                Debug.Assert(false); return(null);
            }
            return(il.Images[i]);
        }
Exemplo n.º 2
0
        public TreeGroupModel FindGroups()
        {
            TreeGroupModel model         = new TreeGroupModel();
            DateTime       m_dtCachedNow = DateTime.Now;
            GroupModel     root          = null;

            // add root if exists
            if (db.RootGroup != null)
            {
                int nIconID = ((!db.RootGroup.CustomIconUuid.EqualsValue(PwUuid.Zero)) ?
                               ((int)PwIcon.Count + db.GetCustomIconIndex(
                                    db.RootGroup.CustomIconUuid)) : (int)db.RootGroup.IconId);

                if (db.RootGroup.Expires && (db.RootGroup.ExpiryTime <= m_dtCachedNow))
                {
                    nIconID = (int)PwIcon.Expired;
                }

                root = new GroupModel()
                {
                    Name               = db.RootGroup.Name,
                    ImageIndex         = nIconID,
                    SelectedImageIndex = nIconID,
                    Group              = db.RootGroup,
                    Expires            = db.RootGroup.Expires,
                    ExpiryTime         = db.RootGroup.ExpiryTime
                };

                model.Nodes.Add(root);
            }

            RecursiveAddGroup(model, root, db.RootGroup, null);

            return(model);
        }
        private void populateExpiringEntries(PwObjectList <PwEntry> pwObjectList)
        {
            if (pwObjectList.Count() > 0)
            {
                foreach (PwEntry pe in pwObjectList)
                {
                    if (pe.Strings.Exists(PasswordChangeReminderExt._EntryStringKey))
                    {
                        PwListItem pli       = new PwListItem(pe);
                        int        iRemindIn = Convert.ToInt32(pe.Strings.Get(PasswordChangeReminderExt._EntryStringKey).ReadString().ToString());
                        int        iPwAge    = Tools.calculateAge(pe);
                        int        iChangeIn = iRemindIn - iPwAge;

                        ListViewItem lvi = lvExpiringPasswords.Items.Add(pe.Strings.ReadSafe(PwDefs.TitleField));
                        lvi.UseItemStyleForSubItems = false;

                        if (iChangeIn > m_config.pcrPasswordsFormTentativeState)
                        {
                            lvi.SubItems.Add(iChangeIn + " " + Properties.strings.pcr_days).BackColor = m_config.pcrPasswordsFormGreatColor;
                            lvi.Group     = lvExpiringPasswords.Groups[1];
                            lvi.BackColor = m_config.pcrPasswordsFormGreatColor;
                        }
                        else if (iChangeIn > m_config.pcrPasswordsFormCriticalState)
                        {
                            lvi.SubItems.Add(iChangeIn + " " + Properties.strings.pcr_days).BackColor = m_config.pcrPasswordsFormTentativeColor;
                            lvi.Group     = lvExpiringPasswords.Groups[1];
                            lvi.BackColor = m_config.pcrPasswordsFormTentativeColor;
                            lvExpiringPasswords.ShowGroups = true;
                        }
                        else
                        {
                            lvi.SubItems.Add(Properties.strings.pcr_today + " (" + iChangeIn + Properties.strings.pcr_days + ")").BackColor = m_config.pcrPasswordsFormCriticalColor;
                            lvi.Group     = lvExpiringPasswords.Groups[0];
                            lvi.BackColor = m_config.pcrPasswordsFormCriticalColor;
                            lvExpiringPasswords.ShowGroups = true;
                        }

                        lvi.SubItems.Add(iPwAge + " " + Properties.strings.pcr_days).BackColor    = Color.LightGray;
                        lvi.SubItems.Add(iRemindIn + " " + Properties.strings.pcr_days).BackColor = Color.LightGray;
                        lvi.ToolTipText = Properties.strings.pcr_created + ": " + pe.CreationTime + "\r\n" + Properties.strings.pcr_last_modified + ": " + pe.LastModificationTime;
                        lvi.Tag         = pli;


                        if (pe.CustomIconUuid.Equals(PwUuid.Zero))
                        {
                            lvi.ImageIndex = (int)pe.IconId;
                        }
                        else
                        {
                            lvi.ImageIndex = (int)PwIcon.Count + pdb.GetCustomIconIndex(pe.CustomIconUuid);
                        }
                    }
                }
            }
            else
            {
                lvExpiringPasswords.Items.Add(Properties.strings.pcr_nothing + "...");
            }
        }
Exemplo n.º 4
0
        private static string MakeIconImg(PwIcon i, PwUuid ci, PfOptions p)
        {
            if (p.ClientIcons == null)
            {
                return(string.Empty);
            }

            Image img = null;

            PwDatabase pd = p.Database;

            if ((ci != null) && !ci.Equals(PwUuid.Zero) && (pd != null))
            {
                int cix = pd.GetCustomIconIndex(ci);
                if (cix >= 0)
                {
                    cix += (int)PwIcon.Count;
                    if (cix < p.ClientIcons.Images.Count)
                    {
                        img = p.ClientIcons.Images[cix];
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            int ix = (int)i;

            if ((img == null) && (ix >= 0) && (ix < p.ClientIcons.Images.Count))
            {
                img = p.ClientIcons.Images[ix];
            }

            string strData = GfxUtil.ImageToDataUri(img);

            if (string.IsNullOrEmpty(strData))
            {
                Debug.Assert(false); return(string.Empty);
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("<img src=\"");
            sb.Append(strData);
            sb.AppendLine("\"");
            sb.Append("class=\"icon_cli\" alt=\"\" />&nbsp;");

            return(sb.ToString());
        }
Exemplo n.º 5
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))
				{
					using(MemoryStream msPng = new MemoryStream())
					{
						img.Save(msPng, ImageFormat.Png);
						pbPng = msPng.ToArray();
					}
				}
				else
				{
					using(Image imgSc = GfxUtil.ScaleImage(img, wMax, hMax))
					{
						using(MemoryStream msPng = new MemoryStream())
						{
							imgSc.Save(msPng, ImageFormat.Png);
							pbPng = msPng.ToArray();
						}
					}
				}
				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); }
		}
Exemplo n.º 6
0
        protected override void Dispose(bool disposing)
        {
            if (!disposing)
            {
                Debug.Assert(false); return;
            }
            if (!m_pd.IsOpen)
            {
                Debug.Assert(false); return;
            }

            int i = m_pd.GetCustomIconIndex(m_puCueIcon);

            if (i >= 0)
            {
                m_pd.CustomIcons.RemoveAt(i);
                m_pd.UINeedsIconUpdate = true;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Copies the custom icons required for this group to the target database.
        /// </summary>
        /// <param name="targetDatabase">The target database where to add the icons.</param>
        /// <param name="sourceDb">The source database where to get the icons from.</param>
        /// <param name="entry">The entry which icon should be copied (if it is custom).</param>
        private static void HandleCustomIcon(PwDatabase targetDatabase, PwDatabase sourceDb, PwEntry entry)
        {
            // Does the entry not use a custom icon or is it already in the target database
            if (entry.CustomIconUuid.Equals(PwUuid.Zero) ||
                targetDatabase.GetCustomIconIndex(entry.CustomIconUuid) != -1)
            {
                return;
            }

            // Check if the custom icon really is in the source database
            int iconIndex = sourceDb.GetCustomIconIndex(entry.CustomIconUuid);

            if (iconIndex < 0 || iconIndex > sourceDb.CustomIcons.Count - 1)
            {
                MessageService.ShowWarning("Can't locate custom icon (" + entry.CustomIconUuid.ToHexString() +
                                           ") for entry " + entry.Strings.ReadSafe("Title"));
            }

            // Get the custom icon from the source database
            PwCustomIcon customIcon = sourceDb.CustomIcons[iconIndex];

            // Copy the custom icon to the target database
            targetDatabase.CustomIcons.Add(customIcon);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Copies the custom icons required for this group to the target database.
        /// </summary>
        /// <param name="targetDatabase">The target database where to add the icons.</param>
        /// <param name="sourceDatabase">The source database where to get the icons from.</param>
        /// <param name="sourceGroup">The source group which icon should be copied (if it is custom).</param>
        private static void HandleCustomIcon(PwDatabase targetDatabase, PwDatabase sourceDatabase, PwGroup sourceGroup)
        {
            // Does the group not use a custom icon or is it already in the target database
            if (sourceGroup.CustomIconUuid.Equals(PwUuid.Zero) ||
                targetDatabase.GetCustomIconIndex(sourceGroup.CustomIconUuid) != -1)
            {
                return;
            }

            // Check if the custom icon really is in the source database
            int iconIndex = sourceDatabase.GetCustomIconIndex(sourceGroup.CustomIconUuid);

            if (iconIndex < 0 || iconIndex > sourceDatabase.CustomIcons.Count - 1)
            {
                MessageService.ShowWarning("Can't locate custom icon (" + sourceGroup.CustomIconUuid.ToHexString() +
                                           ") for group " + sourceGroup.Name);
            }

            // Get the custom icon from the source database
            PwCustomIcon customIcon = sourceDatabase.CustomIcons[iconIndex];

            // Copy the custom icon to the target database
            targetDatabase.CustomIcons.Add(customIcon);
        }
Exemplo n.º 9
0
        public static bool WriteEntries(Stream msOutput, PwDatabase pdContext,
                                        PwEntry[] vEntries)
        {
            if (msOutput == null)
            {
                Debug.Assert(false); return(false);
            }
            // pdContext may be null
            if (vEntries == null)
            {
                Debug.Assert(false); return(false);
            }

            /* KdbxFile f = new KdbxFile(pwDatabase);
             * f.m_format = KdbxFormat.PlainXml;
             *
             * XmlTextWriter xtw = null;
             * try { xtw = new XmlTextWriter(msOutput, StrUtil.Utf8); }
             * catch(Exception) { Debug.Assert(false); return false; }
             * if(xtw == null) { Debug.Assert(false); return false; }
             *
             * f.m_xmlWriter = xtw;
             *
             * xtw.Formatting = Formatting.Indented;
             * xtw.IndentChar = '\t';
             * xtw.Indentation = 1;
             *
             * xtw.WriteStartDocument(true);
             * xtw.WriteStartElement(ElemRoot);
             *
             * foreach(PwEntry pe in vEntries)
             *      f.WriteEntry(pe, false);
             *
             * xtw.WriteEndElement();
             * xtw.WriteEndDocument();
             *
             * xtw.Flush();
             * xtw.Close();
             * return true; */

            PwDatabase pd = new PwDatabase();

            pd.New(new IOConnectionInfo(), new CompositeKey());

            PwGroup pg = pd.RootGroup;

            if (pg == null)
            {
                Debug.Assert(false); return(false);
            }

            foreach (PwEntry pe in vEntries)
            {
                PwUuid pu = pe.CustomIconUuid;
                if (!pu.Equals(PwUuid.Zero) && (pd.GetCustomIconIndex(pu) < 0))
                {
                    int i = -1;
                    if (pdContext != null)
                    {
                        i = pdContext.GetCustomIconIndex(pu);
                    }
                    if (i >= 0)
                    {
                        PwCustomIcon ci = pdContext.CustomIcons[i];
                        pd.CustomIcons.Add(ci);
                    }
                    else
                    {
                        Debug.Assert(pdContext == null);
                    }
                }

                PwEntry peCopy = pe.CloneDeep();
                pg.AddEntry(peCopy, true);
            }

            KdbxFile f = new KdbxFile(pd);

            f.Save(msOutput, null, KdbxFormat.PlainXml, null);
            return(true);
        }
        /// <summary>
        /// Read entries from a stream.
        /// </summary>
        /// <param name="msData">Input stream to read the entries from.</param>
        /// <returns>Extracted entries.</returns>
        /// <param name="pdContext">Context database (e.g. for storing icons).</param>
        /// <param name="bCopyIcons">If <c>true</c>, custom icons required by
        /// the loaded entries are copied to the context database.</param>
        /// <returns>Loaded entries.</returns>
        public static List <PwEntry> ReadEntries(Stream msData, PwDatabase pdContext,
                                                 bool bCopyIcons)
        {
            List <PwEntry> lEntries = new List <PwEntry>();

            /* KdbxFile f = new KdbxFile(pwDatabase);
             * if(msData == null) { Debug.Assert(false); return lEntries; }
             * f.m_format = KdbxFormat.PlainXml;
             *
             * XmlDocument doc = new XmlDocument();
             * doc.Load(msData);
             *
             * XmlElement el = doc.DocumentElement;
             * if(el.Name != ElemRoot) throw new FormatException();
             *
             * List<PwEntry> vEntries = new List<PwEntry>();
             *
             * foreach(XmlNode xmlChild in el.ChildNodes)
             * {
             *      if(xmlChild.Name == ElemEntry)
             *      {
             *              PwEntry pe = f.ReadEntry(xmlChild);
             *              pe.Uuid = new PwUuid(true);
             *
             *              foreach(PwEntry peHistory in pe.History)
             *                      peHistory.Uuid = pe.Uuid;
             *
             *              vEntries.Add(pe);
             *      }
             *      else { Debug.Assert(false); }
             * }
             *
             *
             * return vEntries; */

            PwDatabase pd = new PwDatabase();

            pd.New(new IOConnectionInfo(), new CompositeKey());

            KdbxFile f = new KdbxFile(pd);

            f.Load(msData, KdbxFormat.PlainXml, null);

            foreach (PwEntry pe in pd.RootGroup.Entries)
            {
                pe.SetUuid(new PwUuid(true), true);
                lEntries.Add(pe);

                if (bCopyIcons && (pdContext != null))
                {
                    PwUuid pu = pe.CustomIconUuid;
                    if (!pu.Equals(PwUuid.Zero))
                    {
                        int iSrc = pd.GetCustomIconIndex(pu);
                        int iDst = pdContext.GetCustomIconIndex(pu);

                        if (iSrc < 0)
                        {
                            Debug.Assert(false);
                        }
                        else if (iDst < 0)
                        {
                            pdContext.CustomIcons.Add(pd.CustomIcons[iSrc]);

                            pdContext.Modified          = true;
                            pdContext.UINeedsIconUpdate = true;
                        }
                    }
                }
            }

            return(lEntries);
        }
Exemplo n.º 11
0
        bool RecursiveAddGroup(TreeNode parentNode, PwGroup parentGroup, bool autodetect)
        {
            if (parentGroup == null)
            {
                return(false);
            }

            TreeNodeCollection treeNodes;

            if (parentNode == null)
            {
                treeNodes = mCustomTreeViewEx.Nodes;
            }
            else
            {
                treeNodes = parentNode.Nodes;
            }

            bool entriesFound = false;

            foreach (PwGroup childGroup in parentGroup.Groups)
            {
                if (mActiveDb.RecycleBinEnabled &&
                    childGroup.Uuid.EqualsValue(mActiveDb.RecycleBinUuid))
                {
                    continue;
                }

                bool   bExpired = (childGroup.Expires && (childGroup.ExpiryTime <= mCachedNow));
                string strName  = childGroup.Name;

                int iconID = ((!childGroup.CustomIconUuid.EqualsValue(PwUuid.Zero)) ?
                              ((int)PwIcon.Count + mActiveDb.GetCustomIconIndex(childGroup.CustomIconUuid)) :
                              (int)childGroup.IconId);
                if (bExpired)
                {
                    iconID = (int)PwIcon.Expired;
                }

                var newNode = new TreeNode(strName, iconID, iconID);
                newNode.Tag       = childGroup;
                newNode.ForeColor = SystemColors.GrayText;
                UIUtil.SetGroupNodeToolTip(newNode, childGroup);

                if (bExpired && (mExpiredFont != null))
                {
                    newNode.NodeFont = mExpiredFont;
                }

                treeNodes.Add(newNode);

                entriesFound |= RecursiveAddGroup(newNode, childGroup, autodetect);

                if (newNode.Nodes.Count > 0)
                {
                    if ((newNode.IsExpanded) && (!childGroup.IsExpanded))
                    {
                        newNode.Collapse();
                    }
                    else if ((!newNode.IsExpanded) && (childGroup.IsExpanded))
                    {
                        newNode.Expand();
                    }
                }
            }

            foreach (var entry in parentGroup.Entries)
            {
                var settings = entry.GetKeeAgentSettings();
                if (autodetect)
                {
                    var entryClone = entry.CloneDeep();
                    settings.AllowUseOfSshKey      = true;
                    settings.Location.SelectedType = EntrySettings.LocationType.Attachment;
                    var sshKeyFound = false;
                    foreach (var attachment in entry.Binaries)
                    {
                        try {
                            settings.Location.AttachmentName = attachment.Key;
                            entryClone.SetKeeAgentSettings(settings);
                            entryClone.GetSshKey(); // throws
                            entry.SetKeeAgentSettings(settings);
                            entry.Touch(true);
                            mActiveDb.Modified = true;
                            ext.pluginHost.MainWindow.UpdateUI(false, null, false, null, false, null, false);
                            sshKeyFound = true;
                            break;
                        } catch (Exception) {
                            // ignore all errors
                        }
                    }
                    if (!sshKeyFound)
                    {
                        continue;
                    }
                }
                if (settings.AllowUseOfSshKey)
                {
                    var entryNode = new TreeNode(entry.Strings.Get(PwDefs.TitleField).ReadString(),
                                                 (int)entry.IconId, (int)entry.IconId);
                    entryNode.Tag = entry;

                    if (entry.Expires && (entry.ExpiryTime <= mCachedNow))
                    {
                        entryNode.ImageIndex = (int)PwIcon.Expired;
                        if (mExpiredFont != null)
                        {
                            entryNode.NodeFont = mExpiredFont;
                        }
                    }
                    else // Not expired
                    {
                        if (entry.CustomIconUuid.EqualsValue(PwUuid.Zero))
                        {
                            entryNode.ImageIndex = (int)entry.IconId;
                        }
                        else
                        {
                            entryNode.ImageIndex = (int)PwIcon.Count +
                                                   mActiveDb.GetCustomIconIndex(entry.CustomIconUuid);
                        }
                    }
                    entryNode.ForeColor = entry.ForegroundColor;
                    entryNode.BackColor = entryNode.BackColor;
                    parentNode.Nodes.Add(entryNode);
                    entriesFound = true;
                }
            }
            return(entriesFound);
        }
Exemplo n.º 12
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();
                }
            }
        }
Exemplo n.º 13
0
		public static bool WriteEntries(Stream msOutput, PwDatabase pdContext,
			PwEntry[] vEntries)
		{
			if(msOutput == null) { Debug.Assert(false); return false; }
			// pdContext may be null
			if(vEntries == null) { Debug.Assert(false); return false; }

			/* KdbxFile f = new KdbxFile(pwDatabase);
			f.m_format = KdbxFormat.PlainXml;

			XmlTextWriter xtw = null;
			try { xtw = new XmlTextWriter(msOutput, StrUtil.Utf8); }
			catch(Exception) { Debug.Assert(false); return false; }
			if(xtw == null) { Debug.Assert(false); return false; }

			f.m_xmlWriter = xtw;

			xtw.Formatting = Formatting.Indented;
			xtw.IndentChar = '\t';
			xtw.Indentation = 1;

			xtw.WriteStartDocument(true);
			xtw.WriteStartElement(ElemRoot);

			foreach(PwEntry pe in vEntries)
				f.WriteEntry(pe, false);

			xtw.WriteEndElement();
			xtw.WriteEndDocument();

			xtw.Flush();
			xtw.Close();
			return true; */

			PwDatabase pd = new PwDatabase();
			pd.New(new IOConnectionInfo(), new CompositeKey());

			PwGroup pg = pd.RootGroup;
			if(pg == null) { Debug.Assert(false); return false; }

			foreach(PwEntry pe in vEntries)
			{
				PwUuid pu = pe.CustomIconUuid;
				if(!pu.Equals(PwUuid.Zero) && (pd.GetCustomIconIndex(pu) < 0))
				{
					int i = -1;
					if(pdContext != null) i = pdContext.GetCustomIconIndex(pu);
					if(i >= 0)
					{
						PwCustomIcon ci = pdContext.CustomIcons[i];
						pd.CustomIcons.Add(ci);
					}
					else { Debug.Assert(pdContext == null); }
				}

				PwEntry peCopy = pe.CloneDeep();
				pg.AddEntry(peCopy, true);
			}

			KdbxFile f = new KdbxFile(pd);
			f.Save(msOutput, null, KdbxFormat.PlainXml, null);
			return true;
		}
Exemplo n.º 14
0
        private ListViewItem AddEntryToList(PwEntry pe)
        {
            ListViewItem lvi = new ListViewItem();

            lvi.Tag = new PwListItem(pe);

            //if (pe.Expires && (pe.ExpiryTime <= m_dtCachedNow))
            //{
            //    lvi.ImageIndex = (int)PwIcon.Expired;
            //    if (m_fontExpired != null) lvi.Font = m_fontExpired;
            //}
            //else
            if (pe.CustomIconUuid.EqualsValue(PwUuid.Zero))
            {
                lvi.ImageIndex = (int)pe.IconId;
            }
            else
            {
                lvi.ImageIndex = (int)PwIcon.Count +
                                 database.GetCustomIconIndex(pe.CustomIconUuid);
            }

            //if (m_bEntryGrouping)
            //{
            //    PwGroup pgContainer = pe.ParentGroup;
            //    PwGroup pgLast = ((m_lvgLastEntryGroup != null) ?
            //        (PwGroup)m_lvgLastEntryGroup.Tag : null);

            //    Debug.Assert(pgContainer != null);
            //    if (pgContainer != null)
            //    {
            //        if (pgContainer != pgLast)
            //        {
            //            m_lvgLastEntryGroup = new ListViewGroup(
            //                pgContainer.GetFullPath());
            //            m_lvgLastEntryGroup.Tag = pgContainer;

            //            m_lvEntries.Groups.Add(m_lvgLastEntryGroup);
            //        }

            //        lvi.Group = m_lvgLastEntryGroup;
            //    }
            //}

            if (!pe.ForegroundColor.IsEmpty)
            {
                lvi.ForeColor = pe.ForegroundColor;
            }

            if (!pe.BackgroundColor.IsEmpty)
            {
                lvi.BackColor = pe.BackgroundColor;
            }
            // else if(Program.Config.MainWindow.EntryListAlternatingBgColors &&
            //	((m_lvEntries.Items.Count & 1) == 1))
            //	lvi.BackColor = m_clrAlternateItemBgColor;

            // m_bOnlyTans &= PwDefs.IsTanEntry(pe);
            //if (m_bShowTanIndices && m_bOnlyTans)
            //{
            //    string strIndex = pe.Strings.ReadSafe(PwDefs.TanIndexField);

            //    if (strIndex.Length > 0) lvi.Text = strIndex;
            //    else lvi.Text = PwDefs.TanTitle;
            //}
            //else
            lvi.Text = GetEntryFieldEx(pe, 0, true);

            for (int iColumn = 1; iColumn < listview.Columns.Count; ++iColumn)
            {
                lvi.SubItems.Add(GetEntryFieldEx(pe, iColumn, true));
            }

            //listview.Items.Add(lvi);
            Debug.Assert(lvi != null);
            return(lvi);
        }
Exemplo n.º 15
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;
                if ((img.Width == 16) && (img.Height == 16))
                {
                    MemoryStream msPng = new MemoryStream();
                    img.Save(msPng, ImageFormat.Png);
                    pbPng = msPng.ToArray();
                    msPng.Close();
                }
                else
                {
                    Bitmap       bmp   = UIUtil.CreateScaledImage(img, 16, 16);
                    MemoryStream msPng = new MemoryStream();
                    bmp.Save(msPng, ImageFormat.Png);
                    pbPng = msPng.ToArray();
                    msPng.Close();

                    bmp.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); }
        }
Exemplo n.º 16
0
		/// <summary>
		/// Read entries from a stream.
		/// </summary>
		/// <param name="msData">Input stream to read the entries from.</param>
		/// <param name="pdContext">Context database (e.g. for storing icons).</param>
		/// <param name="bCopyIcons">If <c>true</c>, custom icons required by
		/// the loaded entries are copied to the context database.</param>
		/// <returns>Loaded entries.</returns>
		public static List<PwEntry> ReadEntries(Stream msData, PwDatabase pdContext,
			bool bCopyIcons)
		{
			List<PwEntry> lEntries = new List<PwEntry>();

			if(msData == null) { Debug.Assert(false); return lEntries; }
			// pdContext may be null

			/* KdbxFile f = new KdbxFile(pwDatabase);
			f.m_format = KdbxFormat.PlainXml;

			XmlDocument doc = new XmlDocument();
			doc.Load(msData);

			XmlElement el = doc.DocumentElement;
			if(el.Name != ElemRoot) throw new FormatException();

			List<PwEntry> vEntries = new List<PwEntry>();

			foreach(XmlNode xmlChild in el.ChildNodes)
			{
				if(xmlChild.Name == ElemEntry)
				{
					PwEntry pe = f.ReadEntry(xmlChild);
					pe.Uuid = new PwUuid(true);

					foreach(PwEntry peHistory in pe.History)
						peHistory.Uuid = pe.Uuid;

					vEntries.Add(pe);
				}
				else { Debug.Assert(false); }
			}

			return vEntries; */

			PwDatabase pd = new PwDatabase();
			pd.New(new IOConnectionInfo(), new CompositeKey());

			KdbxFile f = new KdbxFile(pd);
			f.Load(msData, KdbxFormat.PlainXml, null);

			foreach(PwEntry pe in pd.RootGroup.Entries)
			{
				pe.SetUuid(new PwUuid(true), true);
				lEntries.Add(pe);

				if(bCopyIcons && (pdContext != null))
				{
					PwUuid pu = pe.CustomIconUuid;
					if(!pu.Equals(PwUuid.Zero))
					{
						int iSrc = pd.GetCustomIconIndex(pu);
						int iDst = pdContext.GetCustomIconIndex(pu);

						if(iSrc < 0) { Debug.Assert(false); }
						else if(iDst < 0)
						{
							pdContext.CustomIcons.Add(pd.CustomIcons[iSrc]);

							pdContext.Modified = true;
							pdContext.UINeedsIconUpdate = true;
						}
					}
				}
			}

			return lEntries;
		}