Example #1
0
 Task <string> GetPlatformText(EntryHandler handler)
 {
     return(InvokeOnMainThreadAsync(() => GetPlatformControl(handler).Text));
 }
Example #2
0
 bool GetNativeIsTextPredictionEnabled(EntryHandler entryHandler) =>
 GetNativeEntry(entryHandler).AutocorrectionType == UITextAutocorrectionType.Yes;
Example #3
0
 bool GetNativeIsNumericKeyboard(EntryHandler entryHandler) =>
 GetNativeEntry(entryHandler).KeyboardType == UIKeyboardType.DecimalPad;
Example #4
0
 void SetNativeText(EntryHandler entryHandler, string text) =>
 GetNativeEntry(entryHandler).Text = text;
Example #5
0
 bool GetNativeIsPassword(EntryHandler entryHandler) =>
 GetNativeEntry(entryHandler).SecureTextEntry;
Example #6
0
 ImeAction GetNativeReturnType(EntryHandler entryHandler) =>
 GetNativeEntry(entryHandler).ImeOptions;
Example #7
0
 UITextField GetNativeEntry(EntryHandler entryHandler) =>
 (UITextField)entryHandler.NativeView;
Example #8
0
        private void UpdateHtmlDocument()
        {
            if (m_bBlockPreviewRefresh)
            {
                return;
            }

            m_bBlockPreviewRefresh = true;

            PwGroup pgDataSource = m_pgDataSource.CloneDeep();

            int    nSortEntries     = m_cmbSortEntries.SelectedIndex;
            string strSortFieldName = null;

            if (nSortEntries == 0)
            {
            }                                     // No sort
            else if (nSortEntries == 1)
            {
                strSortFieldName = PwDefs.TitleField;
            }
            else if (nSortEntries == 2)
            {
                strSortFieldName = PwDefs.UserNameField;
            }
            else if (nSortEntries == 3)
            {
                strSortFieldName = PwDefs.PasswordField;
            }
            else if (nSortEntries == 4)
            {
                strSortFieldName = PwDefs.UrlField;
            }
            else if (nSortEntries == 5)
            {
                strSortFieldName = PwDefs.NotesField;
            }
            else
            {
                Debug.Assert(false);
            }
            if (strSortFieldName != null)
            {
                SortGroupEntriesRecursive(pgDataSource, strSortFieldName);
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"");
            sb.AppendLine("\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");

            sb.AppendLine("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
            sb.AppendLine("<head>");
            sb.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
            sb.Append("<title>");
            sb.Append(StrUtil.StringToHtml(pgDataSource.Name));
            sb.AppendLine("</title>");
            sb.AppendLine("<meta http-equiv=\"expires\" content=\"0\" />");
            sb.AppendLine("<meta http-equiv=\"cache-control\" content=\"no-cache\" />");
            sb.AppendLine("<meta http-equiv=\"pragma\" content=\"no-cache\" />");

            sb.AppendLine("<style type=\"text/css\"><!--");

            sb.AppendLine("body, p, div, h1, h2, h3, h4, h5, h6, ol, ul, li, td, th, dd, dt, a {");
            sb.AppendLine("\tfont-family: Tahoma, MS Sans Serif, Sans Serif, Verdana, sans-serif;");
            sb.AppendLine("\tfont-size: 10pt;");
            sb.AppendLine("}");
            sb.AppendLine("span.fserif {");
            sb.AppendLine("\tfont-family: Times New Roman, serif;");
            sb.AppendLine("}");
            sb.AppendLine("h1 { font-size: 2em; }");
            sb.AppendLine("h2 { font-size: 1.5em; }");
            sb.AppendLine("h3 { font-size: 1.2em; }");
            sb.AppendLine("h4 { font-size: 1em; }");
            sb.AppendLine("h5 { font-size: 0.89em; }");
            sb.AppendLine("h6 { font-size: 0.6em; }");
            sb.AppendLine("td {");
            sb.AppendLine("\ttext-align: left;");
            sb.AppendLine("\tvertical-align: top;");
            sb.AppendLine("}");
            sb.AppendLine("a:visited {");
            sb.AppendLine("\ttext-decoration: none;");
            sb.AppendLine("\tcolor: #0000DD;");
            sb.AppendLine("}");
            sb.AppendLine("a:active {");
            sb.AppendLine("\ttext-decoration: none;");
            sb.AppendLine("\tcolor: #6699FF;");
            sb.AppendLine("}");
            sb.AppendLine("a:link {");
            sb.AppendLine("\ttext-decoration: none;");
            sb.AppendLine("\tcolor: #0000DD;");
            sb.AppendLine("}");
            sb.AppendLine("a:hover {");
            sb.AppendLine("\ttext-decoration: underline;");
            sb.AppendLine("\tcolor: #6699FF;");
            sb.AppendLine("}");

            sb.AppendLine("--></style>");

            sb.AppendLine("</head><body>");

            sb.AppendLine("<h2>" + StrUtil.StringToHtml(pgDataSource.Name) + "</h2>");

            GroupHandler gh = null;
            EntryHandler eh = null;

            bool bGroup = m_cbGroups.Checked;
            bool bTitle = m_cbTitle.Checked, bUserName = m_cbUser.Checked;
            bool bPassword = m_cbPassword.Checked, bURL = m_cbUrl.Checked;
            bool bNotes = m_cbNotes.Checked;
            bool bCreation = m_cbCreation.Checked, bLastMod = m_cbLastMod.Checked;
            // bool bLastAcc = m_cbLastAccess.Checked;
            bool bExpire        = m_cbExpire.Checked;
            bool bAutoType      = m_cbAutoType.Checked;
            bool bTags          = m_cbTags.Checked;
            bool bCustomStrings = m_cbCustomStrings.Checked;

            bool bMonoPasswords = m_cbMonospaceForPasswords.Checked;

            if (m_rbMonospace.Checked)
            {
                bMonoPasswords = false;                                   // Monospaced anyway
            }
            bool bSmallMono = m_cbSmallMono.Checked;

            string strFontInit = string.Empty, strFontExit = string.Empty;

            if (m_rbSerif.Checked)
            {
                strFontInit = "<span class=\"fserif\">";
                strFontExit = "</span>";
            }
            else if (m_rbSansSerif.Checked)
            {
                strFontInit = string.Empty;
                strFontExit = string.Empty;
            }
            else if (m_rbMonospace.Checked)
            {
                strFontInit = (bSmallMono ? "<code><small>" : "<code>");
                strFontExit = (bSmallMono ? "</small></code>" : "</code>");
            }
            else
            {
                Debug.Assert(false);
            }

            string strTableInit = "<table width=\"100%\">";

            if (m_rbTabular.Checked)
            {
                // int nFieldCount = (bTitle ? 1 : 0) + (bUserName ? 1 : 0);
                // nFieldCount += (bPassword ? 1 : 0) + (bURL ? 1 : 0) + (bNotes ? 1 : 0);

                string strCellPre  = "<td>" + strFontInit;
                string strCellPost = strFontExit + "</td>";

                string strHTdInit = "<td><b>";
                string strHTdExit = "</b></td>";

                StringBuilder sbH = new StringBuilder();
                sbH.AppendLine();
                sbH.Append("<tr>");
                if (bGroup)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.Group) + strHTdExit);
                }
                if (bTitle)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.Title) + strHTdExit);
                }
                if (bUserName)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.UserName) + strHTdExit);
                }
                if (bPassword)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.Password) + strHTdExit);
                }
                if (bURL)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.Url) + strHTdExit);
                }
                if (bNotes)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.Notes) + strHTdExit);
                }
                if (bCreation)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.CreationTime) + strHTdExit);
                }
                // if(bLastAcc) sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.LastAccessTime) + strHTdExit);
                if (bLastMod)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.LastModificationTime) + strHTdExit);
                }
                if (bExpire)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.ExpiryTime) + strHTdExit);
                }
                if (bTags)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.Tags) + strHTdExit);
                }
                sbH.Append("</tr>");                 // No terminating \r\n

                strTableInit += sbH.ToString();
                sb.AppendLine(strTableInit);

                eh = delegate(PwEntry pe)
                {
                    sb.AppendLine("<tr>");

                    WriteTabularIf(bGroup, sb, StrUtil.StringToHtml(pe.ParentGroup.Name), strCellPre, strCellPost);
                    WriteTabularIf(bTitle, sb, pe, PwDefs.TitleField, strCellPre, strCellPost);
                    WriteTabularIf(bUserName, sb, pe, PwDefs.UserNameField, strCellPre, strCellPost);

                    if (bPassword)
                    {
                        if (bMonoPasswords)
                        {
                            sb.Append(bSmallMono ? "<td><code><small>" : "<td><code>");
                        }
                        else
                        {
                            sb.Append(strCellPre);
                        }

                        string strInner = StrUtil.StringToHtml(pe.Strings.ReadSafe(PwDefs.PasswordField));
                        if (strInner.Length > 0)
                        {
                            sb.Append(strInner);
                        }
                        else
                        {
                            sb.Append(@"&nbsp;");
                        }

                        if (bMonoPasswords)
                        {
                            sb.AppendLine(bSmallMono ? "</small></code></td>" : "</code></td>");
                        }
                        else
                        {
                            sb.AppendLine(strCellPost);
                        }
                    }

                    // WriteTabularIf(bURL, sb, pe, PwDefs.UrlField, strCellPre, strCellPost);
                    WriteTabularIf(bURL, sb, MakeUrlLink(pe.Strings.ReadSafe(PwDefs.UrlField),
                                                         strFontInit, strFontExit), strCellPre, strCellPost);

                    WriteTabularIf(bNotes, sb, pe, PwDefs.NotesField, strCellPre, strCellPost);

                    WriteTabularIf(bCreation, sb, TimeUtil.ToDisplayString(
                                       pe.CreationTime), strCellPre, strCellPost);
                    // WriteTabularIf(bLastAcc, sb, TimeUtil.ToDisplayString(
                    //	pe.LastAccessTime), strCellPre, strCellPost);
                    WriteTabularIf(bLastMod, sb, TimeUtil.ToDisplayString(
                                       pe.LastModificationTime), strCellPre, strCellPost);
                    WriteTabularIf(bExpire, sb, (pe.Expires ? TimeUtil.ToDisplayString(
                                                     pe.ExpiryTime) : KPRes.NeverExpires), strCellPre, strCellPost);

                    WriteTabularIf(bTags, sb, StrUtil.TagsToString(pe.Tags, true),
                                   strCellPre, strCellPost);

                    sb.AppendLine("</tr>");
                    return(true);
                };
            }
            else if (m_rbDetails.Checked)
            {
                sb.AppendLine(strTableInit);

                if (pgDataSource.Entries.UCount == 0)
                {
                    sb.AppendLine(@"<tr><td>&nbsp;</td></tr>");
                }

                eh = delegate(PwEntry pe)
                {
                    if (bGroup)
                    {
                        WriteDetailsLine(sb, KPRes.Group, pe.ParentGroup.Name, bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bTitle)
                    {
                        WriteDetailsLine(sb, KPRes.Title, pe.Strings.ReadSafe(PwDefs.TitleField), bSmallMono, bMonoPasswords, strFontInit + "<b>", "</b>" + strFontExit);
                    }
                    if (bUserName)
                    {
                        WriteDetailsLine(sb, KPRes.UserName, pe.Strings.ReadSafe(PwDefs.UserNameField), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bPassword)
                    {
                        WriteDetailsLine(sb, KPRes.Password, pe.Strings.ReadSafe(PwDefs.PasswordField), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bURL)
                    {
                        WriteDetailsLine(sb, KPRes.Url, pe.Strings.ReadSafe(PwDefs.UrlField), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bNotes)
                    {
                        WriteDetailsLine(sb, KPRes.Notes, pe.Strings.ReadSafe(PwDefs.NotesField), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bCreation)
                    {
                        WriteDetailsLine(sb, KPRes.CreationTime, TimeUtil.ToDisplayString(
                                             pe.CreationTime), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    // if(bLastAcc) WriteDetailsLine(sb, KPRes.LastAccessTime, TimeUtil.ToDisplayString(
                    //	pe.LastAccessTime), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    if (bLastMod)
                    {
                        WriteDetailsLine(sb, KPRes.LastModificationTime, TimeUtil.ToDisplayString(
                                             pe.LastModificationTime), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bExpire)
                    {
                        WriteDetailsLine(sb, KPRes.ExpiryTime, (pe.Expires ? TimeUtil.ToDisplayString(
                                                                    pe.ExpiryTime) : KPRes.NeverExpires), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }

                    if (bAutoType)
                    {
                        foreach (AutoTypeAssociation a in pe.AutoType.Associations)
                        {
                            WriteDetailsLine(sb, KPRes.AutoType, a.WindowName +
                                             ": " + a.Sequence, bSmallMono, bMonoPasswords,
                                             strFontInit, strFontExit);
                        }
                    }

                    if (bTags)
                    {
                        WriteDetailsLine(sb, KPRes.Tags, StrUtil.TagsToString(
                                             pe.Tags, true), bSmallMono, bMonoPasswords, strFontInit,
                                         strFontExit);
                    }

                    foreach (KeyValuePair <string, ProtectedString> kvp in pe.Strings)
                    {
                        if (bCustomStrings && !PwDefs.IsStandardField(kvp.Key))
                        {
                            WriteDetailsLine(sb, kvp, bSmallMono, bMonoPasswords,
                                             strFontInit, strFontExit);
                        }
                    }

                    sb.AppendLine(@"<tr><td>&nbsp;</td></tr>");

                    return(true);
                };
            }
            else
            {
                Debug.Assert(false);
            }

            gh = delegate(PwGroup pg)
            {
                if (pg.Entries.UCount == 0)
                {
                    return(true);
                }

                sb.Append("</table><br /><hr /><h3>");
                sb.Append(StrUtil.StringToHtml(pg.GetFullPath(" - ", false)));
                sb.AppendLine("</h3>");
                sb.AppendLine(strTableInit);

                return(true);
            };

            pgDataSource.TraverseTree(TraversalMethod.PreOrder, gh, eh);

            if (m_rbTabular.Checked)
            {
                sb.AppendLine("</table>");
            }
            else if (m_rbDetails.Checked)
            {
                sb.AppendLine("</table><br />");
            }

            sb.AppendLine("</body></html>");

            try { UIUtil.SetWebBrowserDocument(m_wbMain, sb.ToString()); }
            catch (Exception) { }            // Throws in Mono 2.0+
            try { m_wbMain.AllowNavigation = false; }
            catch (Exception) { Debug.Assert(false); }

            m_bBlockPreviewRefresh = false;
        }
Example #9
0
        public override bool Export(PwExportInfo pwExportInfo, Stream sOutput,
                                    IStatusLogger slLogger)
        {
            PwDatabase pd     = pwExportInfo.ContextDatabase;
            PwGroup    pgRoot = pwExportInfo.DataGroup;

            // Remove everything that requires KDBX 4 or higher;
            // see also KdbxFile.GetMinKdbxVersion

            PwUuid puCipher = pd.DataCipherUuid;

            if (puCipher.Equals(ChaCha20Engine.ChaCha20Uuid))
            {
                pd.DataCipherUuid = StandardAesEngine.AesUuid;
            }

            KdfParameters pKdf   = pd.KdfParameters;
            AesKdf        kdfAes = new AesKdf();

            if (!pKdf.KdfUuid.Equals(kdfAes.Uuid))
            {
                pd.KdfParameters = kdfAes.GetDefaultParameters();
            }

            VariantDictionary vdPublic = pd.PublicCustomData;

            pd.PublicCustomData = new VariantDictionary();

            List <PwGroup>            lCustomGK = new List <PwGroup>();
            List <StringDictionaryEx> lCustomGV = new List <StringDictionaryEx>();
            List <PwEntry>            lCustomEK = new List <PwEntry>();
            List <StringDictionaryEx> lCustomEV = new List <StringDictionaryEx>();

            GroupHandler gh = delegate(PwGroup pg)
            {
                if (pg == null)
                {
                    Debug.Assert(false); return(true);
                }
                if (pg.CustomData.Count > 0)
                {
                    lCustomGK.Add(pg);
                    lCustomGV.Add(pg.CustomData);
                    pg.CustomData = new StringDictionaryEx();
                }
                return(true);
            };
            EntryHandler eh = delegate(PwEntry pe)
            {
                if (pe == null)
                {
                    Debug.Assert(false); return(true);
                }
                if (pe.CustomData.Count > 0)
                {
                    lCustomEK.Add(pe);
                    lCustomEV.Add(pe.CustomData);
                    pe.CustomData = new StringDictionaryEx();
                }
                return(true);
            };

            gh(pgRoot);
            pgRoot.TraverseTree(TraversalMethod.PreOrder, gh, eh);

            try
            {
                KdbxFile kdbx = new KdbxFile(pd);
                kdbx.ForceVersion = KdbxFile.FileVersion32_3_1;
                kdbx.Save(sOutput, pgRoot, KdbxFormat.Default, slLogger);
            }
            finally
            {
                // Restore

                pd.DataCipherUuid   = puCipher;
                pd.KdfParameters    = pKdf;
                pd.PublicCustomData = vdPublic;

                for (int i = 0; i < lCustomGK.Count; ++i)
                {
                    lCustomGK[i].CustomData = lCustomGV[i];
                }
                for (int i = 0; i < lCustomEK.Count; ++i)
                {
                    lCustomEK[i].CustomData = lCustomEV[i];
                }
            }

            return(true);
        }
Example #10
0
        private void UpdateHtmlDocument()
        {
            if (m_bBlockPreviewRefresh)
            {
                return;
            }

            m_bBlockPreviewRefresh = true;

            PwGroup pgDataSource = m_pgDataSource.CloneDeep();

            int    nSortEntries     = m_cmbSortEntries.SelectedIndex;
            string strSortFieldName = null;

            if (nSortEntries == 0)
            {
            }                                     // No sort
            else if (nSortEntries == 1)
            {
                strSortFieldName = PwDefs.TitleField;
            }
            else if (nSortEntries == 2)
            {
                strSortFieldName = PwDefs.UserNameField;
            }
            else if (nSortEntries == 3)
            {
                strSortFieldName = PwDefs.PasswordField;
            }
            else if (nSortEntries == 4)
            {
                strSortFieldName = PwDefs.UrlField;
            }
            else if (nSortEntries == 5)
            {
                strSortFieldName = PwDefs.NotesField;
            }
            else
            {
                Debug.Assert(false);
            }
            if (strSortFieldName != null)
            {
                SortGroupEntriesRecursive(pgDataSource, strSortFieldName);
            }

            bool bRtl = (this.RightToLeft == RightToLeft.Yes);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"");
            sb.AppendLine("\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");

            sb.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\"");
            string strLang = Program.Translation.Properties.Iso6391Code;

            if (string.IsNullOrEmpty(strLang))
            {
                strLang = "en";
            }
            strLang = StrUtil.StringToHtml(strLang);
            sb.Append(" lang=\"" + strLang + "\" xml:lang=\"" + strLang + "\"");
            if (bRtl)
            {
                sb.Append(" dir=\"rtl\"");
            }
            sb.AppendLine(">");

            sb.AppendLine("<head>");
            sb.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
            sb.Append("<title>");
            sb.Append(StrUtil.StringToHtml(pgDataSource.Name));
            sb.AppendLine("</title>");
            sb.AppendLine("<meta http-equiv=\"expires\" content=\"0\" />");
            sb.AppendLine("<meta http-equiv=\"cache-control\" content=\"no-cache\" />");
            sb.AppendLine("<meta http-equiv=\"pragma\" content=\"no-cache\" />");

            sb.AppendLine("<style type=\"text/css\"><!--");

            sb.AppendLine("body, p, div, h1, h2, h3, h4, h5, h6, ol, ul, li, td, th, dd, dt, a {");
            sb.AppendLine("\tfont-family: \"Tahoma\", \"MS Sans Serif\", \"Sans Serif\", \"Verdana\", sans-serif;");
            sb.AppendLine("\tfont-size: 10pt;");
            sb.AppendLine("}");

            sb.AppendLine("span.fserif {");
            sb.AppendLine("\tfont-family: \"Times New Roman\", serif;");
            sb.AppendLine("}");

            sb.AppendLine("h1 { font-size: 2em; }");
            sb.AppendLine("h2 {");
            sb.AppendLine("\tfont-size: 1.5em;");
            sb.AppendLine("\tcolor: #000000;");
            sb.AppendLine("\tbackground-color: #D0D0D0;");
            sb.AppendLine("\tpadding-left: 2pt;");
            sb.AppendLine("\tpadding-right: 2pt;");             // RTL support
            sb.AppendLine("}");
            sb.AppendLine("h3 {");
            sb.AppendLine("\tfont-size: 1.2em;");
            sb.AppendLine("\tcolor: #000000;");
            sb.AppendLine("\tbackground-color: #D0D0D0;");
            sb.AppendLine("\tpadding-left: 2pt;");
            sb.AppendLine("\tpadding-right: 2pt;");             // RTL support
            sb.AppendLine("}");
            sb.AppendLine("h4 { font-size: 1em; }");
            sb.AppendLine("h5 { font-size: 0.89em; }");
            sb.AppendLine("h6 { font-size: 0.6em; }");

            sb.AppendLine("table {");
            sb.AppendLine("\twidth: 100%;");
            sb.AppendLine("\ttable-layout: fixed;");
            sb.AppendLine("}");

            sb.AppendLine("th {");
            sb.AppendLine("\ttext-align: " + (bRtl ? "right;" : "left;"));
            sb.AppendLine("\tvertical-align: top;");
            sb.AppendLine("\tfont-weight: bold;");
            sb.AppendLine("}");

            sb.AppendLine("td {");
            sb.AppendLine("\ttext-align: " + (bRtl ? "right;" : "left;"));
            sb.AppendLine("\tvertical-align: top;");
            sb.AppendLine("}");

            sb.AppendLine("a:visited {");
            sb.AppendLine("\ttext-decoration: none;");
            sb.AppendLine("\tcolor: #0000DD;");
            sb.AppendLine("}");
            sb.AppendLine("a:active {");
            sb.AppendLine("\ttext-decoration: none;");
            sb.AppendLine("\tcolor: #6699FF;");
            sb.AppendLine("}");
            sb.AppendLine("a:link {");
            sb.AppendLine("\ttext-decoration: none;");
            sb.AppendLine("\tcolor: #0000DD;");
            sb.AppendLine("}");
            sb.AppendLine("a:hover {");
            sb.AppendLine("\ttext-decoration: underline;");
            sb.AppendLine("\tcolor: #6699FF;");
            sb.AppendLine("}");

            sb.AppendLine(".field_name {");
            sb.AppendLine("\t-webkit-hyphens: auto;");
            sb.AppendLine("\t-moz-hyphens: auto;");
            sb.AppendLine("\t-ms-hyphens: auto;");
            sb.AppendLine("\thyphens: auto;");
            sb.AppendLine("}");
            sb.AppendLine(".field_data {");
            // sb.AppendLine("\tword-break: break-all;");
            sb.AppendLine("\toverflow-wrap: break-word;");
            sb.AppendLine("\tword-wrap: break-word;");
            sb.AppendLine("}");

            // Add the temporary content identifier
            sb.AppendLine("." + Program.TempFilesPool.TempContentTag + " {");
            sb.AppendLine("\tfont-size: 10pt;");
            sb.AppendLine("}");

            sb.AppendLine("--></style>");
            sb.AppendLine("</head><body>");

            sb.AppendLine("<h2>" + StrUtil.StringToHtml(pgDataSource.Name) + "</h2>");

            GroupHandler gh = null;
            EntryHandler eh = null;

            bool bGroup = m_cbGroups.Checked;
            bool bTitle = m_cbTitle.Checked, bUserName = m_cbUser.Checked;
            bool bPassword = m_cbPassword.Checked, bURL = m_cbUrl.Checked;
            bool bNotes = m_cbNotes.Checked;
            bool bCreation = m_cbCreation.Checked, bLastMod = m_cbLastMod.Checked;
            // bool bLastAcc = m_cbLastAccess.Checked;
            bool bExpire        = m_cbExpire.Checked;
            bool bAutoType      = m_cbAutoType.Checked;
            bool bTags          = m_cbTags.Checked;
            bool bCustomStrings = m_cbCustomStrings.Checked;
            bool bUuid          = m_cbUuid.Checked;

            bool bMonoPasswords = m_cbMonospaceForPasswords.Checked;

            if (m_rbMonospace.Checked)
            {
                bMonoPasswords = false;                                   // Monospaced anyway
            }
            bool bSmallMono = m_cbSmallMono.Checked;

            string strFontInit = string.Empty, strFontExit = string.Empty;

            if (m_rbSerif.Checked)
            {
                strFontInit = "<span class=\"fserif\">";
                strFontExit = "</span>";
            }
            else if (m_rbSansSerif.Checked)
            {
                strFontInit = string.Empty;
                strFontExit = string.Empty;
            }
            else if (m_rbMonospace.Checked)
            {
                strFontInit = (bSmallMono ? "<code><small>" : "<code>");
                strFontExit = (bSmallMono ? "</small></code>" : "</code>");
            }
            else
            {
                Debug.Assert(false);
            }

            string  strTableInit = "<table>";
            PwGroup pgLast       = null;

            if (m_rbTabular.Checked)
            {
                int nEquiCols = 0;
                if (bGroup)
                {
                    ++nEquiCols;
                }
                if (bTitle)
                {
                    ++nEquiCols;
                }
                if (bUserName)
                {
                    ++nEquiCols;
                }
                if (bPassword)
                {
                    ++nEquiCols;
                }
                if (bURL)
                {
                    ++nEquiCols;
                }
                if (bNotes)
                {
                    nEquiCols += 2;
                }
                if (bCreation)
                {
                    ++nEquiCols;
                }
                // if(bLastAcc) ++nEquiCols;
                if (bLastMod)
                {
                    ++nEquiCols;
                }
                if (bExpire)
                {
                    ++nEquiCols;
                }
                if (bTags)
                {
                    ++nEquiCols;
                }
                if (bUuid)
                {
                    ++nEquiCols;
                }
                if (nEquiCols == 0)
                {
                    nEquiCols = 1;
                }

                string strColWidth = (100.0f / (float)nEquiCols).ToString(
                    "F2", NumberFormatInfo.InvariantInfo);
                string strColWidth2 = (200.0f / (float)nEquiCols).ToString(
                    "F2", NumberFormatInfo.InvariantInfo);

                string strHTdInit = "<th class=\"field_name\" style=\"width: " +
                                    strColWidth + "%;\">";
                string strHTdInit2 = "<th class=\"field_name\" style=\"width: " +
                                     strColWidth2 + "%;\">";
                string strHTdExit = "</th>";

                string strCellPre  = "<td class=\"field_data\">" + strFontInit;
                string strCellPost = strFontExit + "</td>";

                StringBuilder sbH = new StringBuilder();
                sbH.AppendLine();
                sbH.Append("<tr>");
                if (bGroup)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.Group) + strHTdExit);
                }
                if (bTitle)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.Title) + strHTdExit);
                }
                if (bUserName)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.UserName) + strHTdExit);
                }
                if (bPassword)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.Password) + strHTdExit);
                }
                if (bURL)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.Url) + strHTdExit);
                }
                if (bNotes)
                {
                    sbH.AppendLine(strHTdInit2 + StrUtil.StringToHtml(KPRes.Notes) + strHTdExit);
                }
                if (bCreation)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.CreationTime) + strHTdExit);
                }
                // if(bLastAcc) sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.LastAccessTime) + strHTdExit);
                if (bLastMod)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.LastModificationTime) + strHTdExit);
                }
                if (bExpire)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.ExpiryTime) + strHTdExit);
                }
                if (bTags)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.Tags) + strHTdExit);
                }
                if (bUuid)
                {
                    sbH.AppendLine(strHTdInit + StrUtil.StringToHtml(KPRes.Uuid) + strHTdExit);
                }
                sbH.Append("</tr>");                 // No terminating \r\n

                strTableInit += sbH.ToString();
                sb.AppendLine(strTableInit);

                eh = delegate(PwEntry pe)
                {
                    sb.AppendLine("<tr>");

                    WriteTabularIf(bGroup, sb, StrUtil.StringToHtml(pe.ParentGroup.Name), strCellPre, strCellPost);
                    WriteTabularIf(bTitle, sb, pe, PwDefs.TitleField, strCellPre, strCellPost);
                    WriteTabularIf(bUserName, sb, pe, PwDefs.UserNameField, strCellPre, strCellPost);

                    if (bPassword)
                    {
                        if (bMonoPasswords)
                        {
                            sb.Append("<td class=\"field_data\">" + (bSmallMono ?
                                                                     "<code><small>" : "<code>"));
                        }
                        else
                        {
                            sb.Append(strCellPre);
                        }

                        string strInner = StrUtil.StringToHtml(pe.Strings.ReadSafe(PwDefs.PasswordField));
                        if (strInner.Length > 0)
                        {
                            sb.Append(strInner);
                        }
                        else
                        {
                            sb.Append(@"&nbsp;");
                        }

                        if (bMonoPasswords)
                        {
                            sb.AppendLine(bSmallMono ? "</small></code></td>" : "</code></td>");
                        }
                        else
                        {
                            sb.AppendLine(strCellPost);
                        }
                    }

                    // WriteTabularIf(bURL, sb, pe, PwDefs.UrlField, strCellPre, strCellPost);
                    WriteTabularIf(bURL, sb, MakeUrlLink(pe.Strings.ReadSafe(PwDefs.UrlField),
                                                         strFontInit, strFontExit), strCellPre, strCellPost);

                    WriteTabularIf(bNotes, sb, pe, PwDefs.NotesField, strCellPre, strCellPost);

                    WriteTabularIf(bCreation, sb, StrUtil.StringToHtml(
                                       TimeUtil.ToDisplayString(pe.CreationTime)), strCellPre, strCellPost);
                    // WriteTabularIf(bLastAcc, sb, StrUtil.StringToHtml(
                    //	TimeUtil.ToDisplayString(pe.LastAccessTime)), strCellPre, strCellPost);
                    WriteTabularIf(bLastMod, sb, StrUtil.StringToHtml(
                                       TimeUtil.ToDisplayString(pe.LastModificationTime)), strCellPre, strCellPost);
                    WriteTabularIf(bExpire, sb, StrUtil.StringToHtml(pe.Expires ?
                                                                     TimeUtil.ToDisplayString(pe.ExpiryTime) : KPRes.NeverExpires),
                                   strCellPre, strCellPost);

                    WriteTabularIf(bTags, sb, StrUtil.StringToHtml(StrUtil.TagsToString(
                                                                       pe.Tags, true)), strCellPre, strCellPost);

                    WriteTabularIf(bUuid, sb, pe.Uuid.ToHexString(), strCellPre, strCellPost);

                    sb.AppendLine("</tr>");
                    return(true);
                };
            }
            else if (m_rbDetails.Checked)
            {
                sb.AppendLine(strTableInit);

                if (pgDataSource.Entries.UCount == 0)
                {
                    sb.AppendLine(@"<tr><td>&nbsp;</td></tr>");
                }

                eh = delegate(PwEntry pe)
                {
                    if ((pgLast != null) && (pgLast == pe.ParentGroup))
                    {
                        sb.AppendLine("<tr><td colspan=\"2\"><hr /></td></tr>");
                    }

                    if (bGroup)
                    {
                        WriteDetailsLine(sb, KPRes.Group, pe.ParentGroup.Name, bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bTitle)
                    {
                        WriteDetailsLine(sb, KPRes.Title, pe.Strings.ReadSafe(PwDefs.TitleField), bSmallMono, bMonoPasswords, strFontInit + "<b>", "</b>" + strFontExit);
                    }
                    if (bUserName)
                    {
                        WriteDetailsLine(sb, KPRes.UserName, pe.Strings.ReadSafe(PwDefs.UserNameField), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bPassword)
                    {
                        WriteDetailsLine(sb, KPRes.Password, pe.Strings.ReadSafe(PwDefs.PasswordField), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bURL)
                    {
                        WriteDetailsLine(sb, KPRes.Url, pe.Strings.ReadSafe(PwDefs.UrlField), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bNotes)
                    {
                        WriteDetailsLine(sb, KPRes.Notes, pe.Strings.ReadSafe(PwDefs.NotesField), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bCreation)
                    {
                        WriteDetailsLine(sb, KPRes.CreationTime, TimeUtil.ToDisplayString(
                                             pe.CreationTime), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    // if(bLastAcc) WriteDetailsLine(sb, KPRes.LastAccessTime, TimeUtil.ToDisplayString(
                    //	pe.LastAccessTime), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    if (bLastMod)
                    {
                        WriteDetailsLine(sb, KPRes.LastModificationTime, TimeUtil.ToDisplayString(
                                             pe.LastModificationTime), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bExpire)
                    {
                        WriteDetailsLine(sb, KPRes.ExpiryTime, (pe.Expires ? TimeUtil.ToDisplayString(
                                                                    pe.ExpiryTime) : KPRes.NeverExpires), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }

                    if (bAutoType)
                    {
                        foreach (AutoTypeAssociation a in pe.AutoType.Associations)
                        {
                            WriteDetailsLine(sb, KPRes.AutoType, a.WindowName +
                                             ": " + a.Sequence, bSmallMono, bMonoPasswords,
                                             strFontInit, strFontExit);
                        }
                    }

                    if (bTags)
                    {
                        WriteDetailsLine(sb, KPRes.Tags, StrUtil.TagsToString(
                                             pe.Tags, true), bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }
                    if (bUuid)
                    {
                        WriteDetailsLine(sb, KPRes.Uuid, pe.Uuid.ToHexString(),
                                         bSmallMono, bMonoPasswords, strFontInit, strFontExit);
                    }

                    foreach (KeyValuePair <string, ProtectedString> kvp in pe.Strings)
                    {
                        if (bCustomStrings && !PwDefs.IsStandardField(kvp.Key))
                        {
                            WriteDetailsLine(sb, kvp, bSmallMono, bMonoPasswords,
                                             strFontInit, strFontExit);
                        }
                    }

                    pgLast = pe.ParentGroup;
                    return(true);
                };
            }
            else
            {
                Debug.Assert(false);
            }

            gh = delegate(PwGroup pg)
            {
                if (pg.Entries.UCount == 0)
                {
                    return(true);
                }

                sb.Append("</table><br /><br /><h3>");                 // "</table><br /><hr /><h3>"
                sb.Append(StrUtil.StringToHtml(pg.GetFullPath(" - ", false)));
                sb.AppendLine("</h3>");
                sb.AppendLine(strTableInit);

                return(true);
            };

            pgDataSource.TraverseTree(TraversalMethod.PreOrder, gh, eh);

            if (m_rbTabular.Checked)
            {
                sb.AppendLine("</table>");
            }
            else if (m_rbDetails.Checked)
            {
                sb.AppendLine("</table><br />");
            }

            sb.AppendLine("</body></html>");

            try { UIUtil.SetWebBrowserDocument(m_wbMain, sb.ToString()); }
            catch (Exception) { Debug.Assert(NativeLib.IsUnix()); }            // Throws in Mono 2.0+
            try { m_wbMain.AllowNavigation = false; }
            catch (Exception) { Debug.Assert(false); }

            m_bBlockPreviewRefresh = false;
        }
Example #11
0
        private uint GetMinKdbxVersion()
        {
            if (m_uForceVersion != 0)
            {
                return(m_uForceVersion);
            }

            // See also KeePassKdb2x3.Export (KDBX 3.1 export module)

            uint uMin = 0;

            GroupHandler gh = delegate(PwGroup pg)
            {
                if (pg == null)
                {
                    Debug.Assert(false); return(true);
                }

                if (pg.Tags.Count != 0)
                {
                    uMin = Math.Max(uMin, FileVersion32_4_1);
                }
                if (pg.CustomData.Count != 0)
                {
                    uMin = Math.Max(uMin, FileVersion32_4);
                }

                return(true);
            };

            EntryHandler eh = delegate(PwEntry pe)
            {
                if (pe == null)
                {
                    Debug.Assert(false); return(true);
                }

                if (!pe.QualityCheck)
                {
                    uMin = Math.Max(uMin, FileVersion32_4_1);
                }
                if (pe.CustomData.Count != 0)
                {
                    uMin = Math.Max(uMin, FileVersion32_4);
                }

                return(true);
            };

            gh(m_pwDatabase.RootGroup);
            m_pwDatabase.RootGroup.TraverseTree(TraversalMethod.PreOrder, gh, eh);

            if (uMin >= FileVersion32_4_1)
            {
                return(uMin);                                      // All below is <= 4.1
            }
            foreach (PwCustomIcon ci in m_pwDatabase.CustomIcons)
            {
                if ((ci.Name.Length != 0) || ci.LastModificationTime.HasValue)
                {
                    return(FileVersion32_4_1);
                }
            }

            foreach (KeyValuePair <string, string> kvp in m_pwDatabase.CustomData)
            {
                DateTime?odt = m_pwDatabase.CustomData.GetLastModificationTime(kvp.Key);
                if (odt.HasValue)
                {
                    return(FileVersion32_4_1);
                }
            }

            if (uMin >= FileVersion32_4)
            {
                return(uMin);                                    // All below is <= 4
            }
            if (m_pwDatabase.DataCipherUuid.Equals(ChaCha20Engine.ChaCha20Uuid))
            {
                return(FileVersion32_4);
            }

            AesKdf kdfAes = new AesKdf();

            if (!m_pwDatabase.KdfParameters.KdfUuid.Equals(kdfAes.Uuid))
            {
                return(FileVersion32_4);
            }

            if (m_pwDatabase.PublicCustomData.Count != 0)
            {
                return(FileVersion32_4);
            }

            return(FileVersion32_3_1);            // KDBX 3.1 is sufficient
        }
Example #12
0
 AppCompatEditText GetPlatformControl(EntryHandler handler) =>
 handler.PlatformView;
Example #13
0
        void UpdateCursorStartPosition(EntryHandler entryHandler, int position)
        {
            var control = GetPlatformControl(entryHandler);

            control.SetSelection(position);
        }
Example #14
0
        int GetCursorStartPosition(EntryHandler entryHandler)
        {
            var control = GetPlatformControl(entryHandler);

            return(control.SelectionStart);
        }
Example #15
0
 Android.Views.TextAlignment GetNativeHorizontalTextAlignment(EntryHandler entryHandler) =>
 GetNativeEntry(entryHandler).TextAlignment;
Example #16
0
        private string GenerateHtmlDocument(bool bTemporary)
        {
            PwGroup pgDataSource = m_pgDataSource.CloneDeep();             // Sorting, ...

            int    nSortEntries     = m_cmbSortEntries.SelectedIndex;
            string strSortFieldName = null;

            if (nSortEntries == 0)
            {
            }                                     // No sort
            else if (nSortEntries == 1)
            {
                strSortFieldName = PwDefs.TitleField;
            }
            else if (nSortEntries == 2)
            {
                strSortFieldName = PwDefs.UserNameField;
            }
            else if (nSortEntries == 3)
            {
                strSortFieldName = PwDefs.PasswordField;
            }
            else if (nSortEntries == 4)
            {
                strSortFieldName = PwDefs.UrlField;
            }
            else if (nSortEntries == 5)
            {
                strSortFieldName = PwDefs.NotesField;
            }
            else
            {
                Debug.Assert(false);
            }
            if (strSortFieldName != null)
            {
                SortGroupEntriesRecursive(pgDataSource, strSortFieldName);
            }

            bool bGroup = m_cbGroups.Checked;
            bool bTitle = m_cbTitle.Checked, bUserName = m_cbUser.Checked;
            bool bPassword = m_cbPassword.Checked, bUrl = m_cbUrl.Checked;
            bool bNotes = m_cbNotes.Checked;
            bool bCreation = m_cbCreation.Checked, bLastMod = m_cbLastMod.Checked;
            // bool bLastAcc = m_cbLastAccess.Checked;
            bool bExpire        = m_cbExpire.Checked;
            bool bAutoType      = m_cbAutoType.Checked;
            bool bTags          = m_cbTags.Checked;
            bool bCustomStrings = m_cbCustomStrings.Checked;
            bool bUuid          = m_cbUuid.Checked;

            PfOptions p = new PfOptions();

            p.MonoPasswords = m_cbMonospaceForPasswords.Checked;
            if (m_rbMonospace.Checked)
            {
                p.MonoPasswords = false;                                   // Monospace anyway
            }
            p.SmallMono = m_cbSmallMono.Checked;
            p.SprMode   = m_cmbSpr.SelectedIndex;
            p.Rtl       = (this.RightToLeft == RightToLeft.Yes);
            p.Database  = m_pdContext;
            if (m_cbIcon.Checked)
            {
                p.ClientIcons = m_ilClientIcons;
            }

            if (m_rbSerif.Checked)
            {
                p.FontInit = "<span class=\"fserif\">";
                p.FontExit = "</span>";
            }
            else if (m_rbSansSerif.Checked)
            {
                p.FontInit = string.Empty;
                p.FontExit = string.Empty;
            }
            else if (m_rbMonospace.Checked)
            {
                p.FontInit = (p.SmallMono ? "<code><small>" : "<code>");
                p.FontExit = (p.SmallMono ? "</small></code>" : "</code>");
            }
            else
            {
                Debug.Assert(false);
            }

            GFunc <string, string> h = new GFunc <string, string>(StrUtil.StringToHtml);
            GFunc <string, string> c = delegate(string strRaw)
            {
                return(CompileText(strRaw, p, true, false));
            };
            GFunc <string, string> cs = delegate(string strRaw)
            {
                return(CompileText(strRaw, p, true, true));
            };

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<!DOCTYPE html>");

            sb.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\"");
            string strLang = Program.Translation.Properties.Iso6391Code;

            if (string.IsNullOrEmpty(strLang))
            {
                strLang = "en";
            }
            strLang = h(strLang);
            sb.Append(" xml:lang=\"" + strLang + "\" lang=\"" + strLang + "\"");
            if (p.Rtl)
            {
                sb.Append(" dir=\"rtl\"");
            }
            sb.AppendLine(">");

            sb.AppendLine("<head>");
            sb.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
            sb.AppendLine("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />");
            sb.AppendLine("<meta http-equiv=\"expires\" content=\"0\" />");
            sb.AppendLine("<meta http-equiv=\"cache-control\" content=\"no-cache\" />");
            sb.AppendLine("<meta http-equiv=\"pragma\" content=\"no-cache\" />");

            sb.Append("<title>");
            sb.Append(h(pgDataSource.Name));
            sb.AppendLine("</title>");

            sb.AppendLine("<style type=\"text/css\">");
            sb.AppendLine("/* <![CDATA[ */");

            sb.AppendLine("body {");
            sb.AppendLine("\tcolor: #000000;");
            sb.AppendLine("\tbackground-color: #FFFFFF;");
            sb.AppendLine("\tfont-family: \"Tahoma\", \"MS Sans Serif\", \"Sans Serif\", \"Verdana\", sans-serif;");
            sb.AppendLine("\tfont-size: 10pt;");
            sb.AppendLine("}");

            sb.AppendLine("h2 {");
            sb.AppendLine("\tcolor: #000000;");
            sb.AppendLine("\tbackground-color: #D0D0D0;");
            sb.AppendLine("\tpadding-left: 2pt;");
            sb.AppendLine("\tpadding-right: 2pt;");             // RTL support
            sb.AppendLine("}");
            sb.AppendLine("h3 {");
            sb.AppendLine("\tcolor: #000000;");
            sb.AppendLine("\tbackground-color: #D0D0D0;");
            sb.AppendLine("\tpadding-left: 2pt;");
            sb.AppendLine("\tpadding-right: 2pt;");             // RTL support
            sb.AppendLine("}");

            sb.AppendLine("table, th, td {");
            sb.AppendLine("\tborder: 0px none;");
            sb.AppendLine("\tborder-collapse: collapse;");
            sb.AppendLine("}");

            sb.AppendLine("table {");
            sb.AppendLine("\twidth: 100%;");
            sb.AppendLine("\ttable-layout: fixed;");
            sb.AppendLine("\tempty-cells: show;");
            sb.AppendLine("}");

            sb.AppendLine("th, td {");
            sb.AppendLine("\ttext-align: " + (p.Rtl ? "right;" : "left;"));
            sb.AppendLine("\tvertical-align: top;");
            sb.AppendLine("}");

            sb.AppendLine("th {");
            sb.AppendLine("\tfont-weight: bold;");
            sb.AppendLine("}");

            sb.AppendLine("a {");
            sb.AppendLine("\tcolor: #0000DD;");
            sb.AppendLine("\ttext-decoration: none;");
            sb.AppendLine("}");
            sb.AppendLine("a:hover, a:active {");
            sb.AppendLine("\tcolor: #6699FF;");
            sb.AppendLine("\ttext-decoration: underline;");
            sb.AppendLine("}");

            sb.AppendLine(".field_name {");
            sb.AppendLine("\t-webkit-hyphens: auto;");
            sb.AppendLine("\t-moz-hyphens: auto;");
            sb.AppendLine("\t-ms-hyphens: auto;");
            sb.AppendLine("\thyphens: auto;");
            sb.AppendLine("}");
            sb.AppendLine(".field_data {");
            // sb.AppendLine("\tword-break: break-all;");
            sb.AppendLine("\toverflow-wrap: break-word;");
            sb.AppendLine("\tword-wrap: break-word;");
            sb.AppendLine("}");

            sb.AppendLine(".fserif {");
            sb.AppendLine("\tfont-family: \"Times New Roman\", serif;");
            sb.AppendLine("}");

            sb.AppendLine(".icon_cli {");
            sb.AppendLine("\tdisplay: inline-block;");
            sb.AppendLine("\tmargin: 0px 0px 0px 0px;");
            sb.AppendLine("\tpadding: 0px 0px 0px 0px;");
            sb.AppendLine("\tborder: 0px none;");
            sb.AppendLine("\twidth: 1.1em;");
            sb.AppendLine("\theight: 1.1em;");
            sb.AppendLine("\tvertical-align: top;");
            sb.AppendLine("}");

            if (bTemporary)
            {
                // Add the temporary content identifier
                sb.AppendLine("." + Program.TempFilesPool.TempContentTag + " {");
                sb.AppendLine("\tfont-size: 10pt;");
                sb.AppendLine("}");
            }

            sb.AppendLine("/* ]]> */");
            sb.AppendLine("</style>");
            sb.AppendLine("</head><body>");

            sb.AppendLine("<h2>" + h(pgDataSource.Name) + "</h2>");
            WriteGroupNotes(sb, pgDataSource);

            EntryHandler ehInit = delegate(PwEntry pe)
            {
                p.Entry = pe;

                if (p.SprMode != 0)
                {
                    p.SprContext = new SprContext(pe, p.Database,
                                                  SprCompileFlags.NonActive, false, false);
                }
                else
                {
                    Debug.Assert(p.SprContext == null);
                }

                Application.DoEvents();
                return(true);
            };

            EntryHandler eh           = null;
            string       strTableInit = "<table>";
            PwGroup      pgLast       = null;

            if (m_rbTabular.Checked)
            {
                int nEquiCols = 0;
                if (bGroup)
                {
                    ++nEquiCols;
                }
                if (bTitle)
                {
                    ++nEquiCols;
                }
                if (bUserName)
                {
                    ++nEquiCols;
                }
                if (bPassword)
                {
                    ++nEquiCols;
                }
                if (bUrl)
                {
                    ++nEquiCols;
                }
                if (bNotes)
                {
                    nEquiCols += 2;
                }
                if (bCreation)
                {
                    ++nEquiCols;
                }
                // if(bLastAcc) ++nEquiCols;
                if (bLastMod)
                {
                    ++nEquiCols;
                }
                if (bExpire)
                {
                    ++nEquiCols;
                }
                if (bTags)
                {
                    ++nEquiCols;
                }
                if (bUuid)
                {
                    ++nEquiCols;
                }
                if (nEquiCols == 0)
                {
                    nEquiCols = 1;
                }

                string strColWidth = (100.0f / (float)nEquiCols).ToString(
                    "F2", NumberFormatInfo.InvariantInfo);
                string strColWidth2 = (200.0f / (float)nEquiCols).ToString(
                    "F2", NumberFormatInfo.InvariantInfo);

                string strHTdInit = "<th class=\"field_name\" style=\"width: " +
                                    strColWidth + "%;\">";
                string strHTdInit2 = "<th class=\"field_name\" style=\"width: " +
                                     strColWidth2 + "%;\">";
                string strHTdExit    = "</th>";
                string strDataTdInit = "<td class=\"field_data\">";
                string strDataTdExit = "</td>";

                p.CellInit = strDataTdInit + p.FontInit;
                p.CellExit = p.FontExit + strDataTdExit;

                StringBuilder sbH = new StringBuilder();
                sbH.AppendLine();
                sbH.Append("<tr>");
                if (bGroup)
                {
                    sbH.AppendLine(strHTdInit + h(KPRes.Group) + strHTdExit);
                }
                if (bTitle)
                {
                    sbH.AppendLine(strHTdInit + h(KPRes.Title) + strHTdExit);
                }
                if (bUserName)
                {
                    sbH.AppendLine(strHTdInit + h(KPRes.UserName) + strHTdExit);
                }
                if (bPassword)
                {
                    sbH.AppendLine(strHTdInit + h(KPRes.Password) + strHTdExit);
                }
                if (bUrl)
                {
                    sbH.AppendLine(strHTdInit + h(KPRes.Url) + strHTdExit);
                }
                if (bNotes)
                {
                    sbH.AppendLine(strHTdInit2 + h(KPRes.Notes) + strHTdExit);
                }
                if (bCreation)
                {
                    sbH.AppendLine(strHTdInit + h(KPRes.CreationTime) + strHTdExit);
                }
                // if(bLastAcc) sbH.AppendLine(strHTdInit + h(KPRes.LastAccessTime) + strHTdExit);
                if (bLastMod)
                {
                    sbH.AppendLine(strHTdInit + h(KPRes.LastModificationTime) + strHTdExit);
                }
                if (bExpire)
                {
                    sbH.AppendLine(strHTdInit + h(KPRes.ExpiryTime) + strHTdExit);
                }
                if (bTags)
                {
                    sbH.AppendLine(strHTdInit + h(KPRes.Tags) + strHTdExit);
                }
                if (bUuid)
                {
                    sbH.AppendLine(strHTdInit + h(KPRes.Uuid) + strHTdExit);
                }
                sbH.Append("</tr>");                 // No terminating \r\n

                strTableInit += sbH.ToString();
                sb.AppendLine(strTableInit);

                eh = delegate(PwEntry pe)
                {
                    ehInit(pe);

                    sb.AppendLine("<tr>");

                    WriteTabularIf(bGroup, sb, c(pe.ParentGroup.Name), p);
                    WriteTabularIf(bTitle, sb, pe, PwDefs.TitleField, p);
                    WriteTabularIf(bUserName, sb, pe, PwDefs.UserNameField, p);

                    if (bPassword)
                    {
                        if (p.MonoPasswords)
                        {
                            sb.Append(strDataTdInit + (p.SmallMono ?
                                                       "<code><small>" : "<code>"));
                        }
                        else
                        {
                            sb.Append(p.CellInit);
                        }

                        string strInner = cs(pe.Strings.ReadSafe(PwDefs.PasswordField));
                        if (strInner.Length == 0)
                        {
                            strInner = "&nbsp;";
                        }
                        sb.Append(strInner);

                        if (p.MonoPasswords)
                        {
                            sb.AppendLine((p.SmallMono ? "</small></code>" :
                                           "</code>") + strDataTdExit);
                        }
                        else
                        {
                            sb.AppendLine(p.CellExit);
                        }
                    }

                    // WriteTabularIf(bUrl, sb, pe, PwDefs.UrlField, p);
                    WriteTabularIf(bUrl, sb, MakeUrlLink(pe.Strings.ReadSafe(
                                                             PwDefs.UrlField), p), p);

                    WriteTabularIf(bNotes, sb, pe, PwDefs.NotesField, p);

                    WriteTabularIf(bCreation, sb, h(TimeUtil.ToDisplayString(
                                                        pe.CreationTime)), p);
                    // WriteTabularIf(bLastAcc, sb, h(TimeUtil.ToDisplayString(
                    //	pe.LastAccessTime)), p);
                    WriteTabularIf(bLastMod, sb, h(TimeUtil.ToDisplayString(
                                                       pe.LastModificationTime)), p);
                    WriteTabularIf(bExpire, sb, h(pe.Expires ? TimeUtil.ToDisplayString(
                                                      pe.ExpiryTime) : KPRes.NeverExpires), p);

                    WriteTabularIf(bTags, sb, h(StrUtil.TagsToString(pe.Tags, true)), p);

                    WriteTabularIf(bUuid, sb, pe.Uuid.ToHexString(), p);

                    sb.AppendLine("</tr>");
                    return(true);
                };
            }
            else if (m_rbDetails.Checked)
            {
                sb.AppendLine(strTableInit);

                if (pgDataSource.Entries.UCount == 0)
                {
                    sb.AppendLine(@"<tr><td>&nbsp;</td></tr>");
                }

                eh = delegate(PwEntry pe)
                {
                    ehInit(pe);

                    if ((pgLast != null) && (pgLast == pe.ParentGroup))
                    {
                        sb.AppendLine("<tr><td colspan=\"2\"><hr /></td></tr>");
                    }

                    if (bGroup)
                    {
                        WriteDetailsLine(sb, KPRes.Group, pe.ParentGroup.Name, p);
                    }
                    if (bTitle)
                    {
                        PfOptions pSub = p.CloneShallow();
                        pSub.FontInit = MakeIconImg(pe.IconId, pe.CustomIconUuid, pe,
                                                    p) + pSub.FontInit + "<b>";
                        pSub.FontExit = "</b>" + pSub.FontExit;

                        WriteDetailsLine(sb, KPRes.Title, pe.Strings.ReadSafe(
                                             PwDefs.TitleField), pSub);
                    }
                    if (bUserName)
                    {
                        WriteDetailsLine(sb, KPRes.UserName, pe.Strings.ReadSafe(
                                             PwDefs.UserNameField), p);
                    }
                    if (bPassword)
                    {
                        WriteDetailsLine(sb, KPRes.Password, pe.Strings.ReadSafe(
                                             PwDefs.PasswordField), p);
                    }
                    if (bUrl)
                    {
                        WriteDetailsLine(sb, KPRes.Url, pe.Strings.ReadSafe(
                                             PwDefs.UrlField), p);
                    }
                    if (bNotes)
                    {
                        WriteDetailsLine(sb, KPRes.Notes, pe.Strings.ReadSafe(
                                             PwDefs.NotesField), p);
                    }
                    if (bCreation)
                    {
                        WriteDetailsLine(sb, KPRes.CreationTime, TimeUtil.ToDisplayString(
                                             pe.CreationTime), p);
                    }
                    // if(bLastAcc) WriteDetailsLine(sb, KPRes.LastAccessTime, TimeUtil.ToDisplayString(
                    //	pe.LastAccessTime), p);
                    if (bLastMod)
                    {
                        WriteDetailsLine(sb, KPRes.LastModificationTime, TimeUtil.ToDisplayString(
                                             pe.LastModificationTime), p);
                    }
                    if (bExpire)
                    {
                        WriteDetailsLine(sb, KPRes.ExpiryTime, (pe.Expires ? TimeUtil.ToDisplayString(
                                                                    pe.ExpiryTime) : KPRes.NeverExpires), p);
                    }

                    if (bAutoType)
                    {
                        foreach (AutoTypeAssociation a in pe.AutoType.Associations)
                        {
                            WriteDetailsLine(sb, KPRes.AutoType, a.WindowName +
                                             ": " + a.Sequence, p);
                        }
                    }

                    if (bTags)
                    {
                        WriteDetailsLine(sb, KPRes.Tags, StrUtil.TagsToString(
                                             pe.Tags, true), p);
                    }
                    if (bUuid)
                    {
                        WriteDetailsLine(sb, KPRes.Uuid, pe.Uuid.ToHexString(), p);
                    }

                    foreach (KeyValuePair <string, ProtectedString> kvp in pe.Strings)
                    {
                        if (bCustomStrings && !PwDefs.IsStandardField(kvp.Key))
                        {
                            WriteDetailsLine(sb, kvp, p);
                        }
                    }

                    pgLast = pe.ParentGroup;
                    return(true);
                };
            }
            else
            {
                Debug.Assert(false);
            }

            GroupHandler gh = delegate(PwGroup pg)
            {
                if (pg.Entries.UCount == 0)
                {
                    return(true);
                }

                sb.Append("</table><br /><br /><h3>");                 // "</table><br /><hr /><h3>"
                // sb.Append(MakeIconImg(pg.IconId, pg.CustomIconUuid, pg, p));
                sb.Append(h(pg.GetFullPath(" - ", false)));
                sb.AppendLine("</h3>");
                WriteGroupNotes(sb, pg);
                sb.AppendLine(strTableInit);

                return(true);
            };

            pgDataSource.TraverseTree(TraversalMethod.PreOrder, gh, eh);

            if (m_rbTabular.Checked)
            {
                sb.AppendLine("</table>");
            }
            else if (m_rbDetails.Checked)
            {
                sb.AppendLine("</table><br />");
            }

            sb.AppendLine("</body></html>");

            string strDoc = sb.ToString();

#if DEBUG
            XmlUtilEx.ValidateXml(strDoc, true);
#endif
            return(strDoc);
        }
Example #17
0
 Android.Views.GravityFlags GetNativeVerticalTextAlignment(EntryHandler entryHandler) =>
 GetNativeEntry(entryHandler).Gravity;
Example #18
0
 static AppCompatEditText GetNativeEntry(EntryHandler entryHandler) =>
 entryHandler.NativeView;
Example #19
0
        double GetNativeCharacterSpacing(EntryHandler entryHandler)
        {
            var entry = GetNativeEntry(entryHandler);

            return(entry.AttributedText.GetCharacterSpacing());
        }
Example #20
0
        static int GetCursorStartPosition(EntryHandler entryHandler)
        {
            var control = GetNativeEntry(entryHandler);

            return(control.SelectionStart);
        }
Example #21
0
 string GetNativeText(EntryHandler entryHandler) =>
 GetNativeEntry(entryHandler).Text;
Example #22
0
        static void UpdateCursorStartPosition(EntryHandler entryHandler, int position)
        {
            var control = GetNativeEntry(entryHandler);

            control.SetSelection(position);
        }
Example #23
0
 Color GetNativeTextColor(EntryHandler entryHandler) =>
 GetNativeEntry(entryHandler).TextColor.ToColor();
Example #24
0
        bool GetNativeIsPassword(EntryHandler entryHandler)
        {
            var inputType = GetNativeEntry(entryHandler).InputType;

            return(inputType.HasFlag(InputTypes.TextVariationPassword) || inputType.HasFlag(InputTypes.NumberVariationPassword));
        }
Example #25
0
 string GetNativePlaceholder(EntryHandler entryHandler) =>
 GetNativeEntry(entryHandler).Placeholder;
Example #26
0
 bool GetNativeIsTextPredictionEnabled(EntryHandler entryHandler) =>
 !GetNativeEntry(entryHandler).InputType.HasFlag(InputTypes.TextFlagNoSuggestions);
Example #27
0
 bool GetNativeIsReadOnly(EntryHandler entryHandler) =>
 !GetNativeEntry(entryHandler).UserInteractionEnabled;
Example #28
0
        bool GetNativeIsReadOnly(EntryHandler entryHandler)
        {
            var editText = GetNativeEntry(entryHandler);

            return(!editText.Focusable && !editText.FocusableInTouchMode);
        }
Example #29
0
 bool GetNativeIsEmailKeyboard(EntryHandler entryHandler) =>
 GetNativeEntry(entryHandler).KeyboardType == UIKeyboardType.EmailAddress;
Example #30
0
 UIReturnKeyType GetNativeReturnType(EntryHandler entryHandler) =>
 GetNativeEntry(entryHandler).ReturnKeyType;