Ejemplo n.º 1
0
        /// <summary>Convert to a rich text form with the builder.</summary>
        /// <param name="builder"></param>
        public void ToRichText(RichTextBuilder builder)
        {
            if (IsTarget)
            {
                builder.ForegroundColor = Color.Blue;
                builder.AppendFormat("<{0}> ", AddressString);
            }

            if (IsFunction)
            {
                builder.ForegroundColor = Color.DarkGreen;
            }
            else if (IsPointer)
            {
                builder.ForegroundColor = Color.Purple;
            }
            builder.Append(ToStringValue());

            if (IsInvalid)
            {
                builder.ForegroundColor = Color.Red;
                builder.Append(" <<" + Errors.Replace("\n", "; ") + ">>");
            }

            builder.ForegroundColor = Color.Black;
        }
Ejemplo n.º 2
0
        public void EmptyTextTest()
        {
            var builder = new RichTextBuilder();
            var rtf     = builder.ToRtf();

            Console.WriteLine(rtf);
        }
Ejemplo n.º 3
0
        public void CanControlSymbols()
        {
            var builder = new RichTextBuilder();

            builder.Text("!!!").LineBreak()
            .Text("Joh.")
            .NonBreakingSpace()
            .Text("Seb.")
            .NonBreakingSpace()
            .Text("Bach ")
            .Italic()
            .Text("multi").Plain().NonBreakingHyphen().Text("valued ")
            .Text("trans")
            .OptionalHyphen()
            .Text("po")
            .OptionalHyphen()
            .Text("si")
            .OptionalHyphen()
            .Text("tion");

            var rtf = builder.ToRtf();
            int i   = rtf.IndexOf("!!!", StringComparison.Ordinal);

            Assert.Equal("!!!\\line Joh.\\~Seb.\\~Bach \\i multi\\plain\\_valued trans\\-po\\-si\\-tion}", rtf.Substring(i));
        }
Ejemplo n.º 4
0
        public void CanWrapLongLines()
        {
            var builder = new RichTextBuilder();

            builder.LineLimit = 20;             // insert newline if line exceeds 20 chars
            builder.Text("The newline has no meaning to RTF").LineBreak();
            builder.Text("except it acts as a delimiter for commands.").LineBreak();
            builder.Text("We can therefore inject a newline every once ");
            builder.Text("in a while - even within a word - to avoid ");
            builder.Text("excessively long lines in the RTF file.");
            var rtf = builder.ToRtf();

            _output.WriteLine(rtf);

            int i = rtf.IndexOf("The newl", StringComparison.Ordinal);

            Assert.True(i > 0);
            var lines    = rtf.Substring(i).Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            var expected = new[]
            {
                "The newline has no m", "eaning to RTF\\line e",
                "xcept it acts as a d", "elimiter for command",
                "s.\\line We can there", "fore inject a newlin",
                "e every once in a wh", "ile - even within a ",
                "word - to avoid exce", "ssively long lines i",
                "n the RTF file.}"
            };

            Assert.Equal(expected.Length, lines.Length);
            for (int j = 0; j < expected.Length; j++)
            {
                Assert.Equal(expected[j], lines[j]);
            }
        }
Ejemplo n.º 5
0
        private void PopulateNotes(string value)
        {
            Debug.Assert(!mNotesEditingActive, "Can't populate while editing!");

            var builder = new RichTextBuilder {
                DefaultFont = Font
            };

            if (String.IsNullOrEmpty(value))
            {
                // Populate it with a watermark
                builder.Append(KPRes.Notes, FontStyle.Italic);
                builder.Build(mNotes);
                mNotes.SelectAll();
                mNotes.SelectionColor = SystemColors.GrayText;
                mNotes.Select(0, 0);
                mNotes.ReadOnly = true;
            }
            else
            {
                builder.Append(NotesRtfHelpers.ReplaceFormattingTags(value));
                builder.Build(mNotes);

                UIUtil.RtfLinkifyReferences(mNotes, false);
                NotesRtfHelpers.RtfLinkifyUrls(mNotes);
            }
        }
Ejemplo n.º 6
0
        public void CanEmptyText()
        {
            var builder = new RichTextBuilder();
            var rtf     = builder.ToRtf();

            _output.WriteLine(rtf);
            const string expected = @"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil Microsoft Sans Serif;}}}";

            Assert.Equal(expected, rtf.Replace("\n", "").Replace("\r", ""));
        }
Ejemplo n.º 7
0
        public virtual void ToRichText(RichTextBuilder builder)
        {
            string format;

            if (OpcodeFormats.TryGetValue(Opcode, out format))
            {
                for (int index = 0; index < format.Length; index++)
                {
                    if (format[index] == '{')
                    {
                        if (format[index + 1] == '{')
                        {
                            index++;
                            builder.Append('{');
                        }
                        else
                        {
                            int end;

                            for (end = ++index; format[end] != '}'; end++)
                            {
                                ;
                            }
                            int           operandIndex = int.Parse(format.Substring(index, end - index));
                            ScriptOperand operand      = GetOperand(operandIndex);
                            operand.ToRichText(builder);
                            index = end;
                        }
                    }
                    else
                    {
                        builder.Append(format[index]);
                    }
                }
            }
            else
            {
                if (IsOpcodeDefined)
                {
                    builder.Append(Opcode.ToString());
                }
                else
                {
                    builder.ForegroundColor = Color.Red;
                    builder.AppendFormat("{0:X2}", (int)Opcode);
                    builder.ForegroundColor = Color.Black;
                }

                foreach (ScriptOperand operand in Operands)
                {
                    builder.Append(" ");
                    operand.ToRichText(builder);
                }
            }
        }
Ejemplo n.º 8
0
 private static void EvAppendEntryFieldString(RichTextBuilder rb,
                                              string strItemSeparator, string strName, string strValue)
 {
     if (string.IsNullOrEmpty(strValue))
     {
         return;
     }
     rb.Append(strName, System.Drawing.FontStyle.Bold, null, null, ":", " ");
     rb.Append(strValue);
     rb.Append(strItemSeparator);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Convert to rich text.
        /// </summary>
        /// <param name="builder"></param>
        public void ToRichText(RichTextBuilder builder)
        {
            builder.AppendFormat("{0}: ", AddressString);
            Opcode.ToRichText(builder);

            for (int index = 0; index < Operands.Count; index++)
            {
                builder.Append(index == 0 ? " " : ", ");
                Operands[index].ToRichText(builder);
            }
        }
Ejemplo n.º 10
0
        public void CanUnicodeChars()
        {
            var builder = new RichTextBuilder();

            builder.Text("Lab\u0393Value");
            var rtf = builder.ToRtf();

            _output.WriteLine(rtf);
            int i = rtf.IndexOf("Lab", StringComparison.Ordinal);

            Assert.True(i > 0);
            Assert.Equal(@"Lab\u915*Value}", rtf.Substring(i));
        }
Ejemplo n.º 11
0
 private static void EvAppendEntryFieldProtectedString(RichTextBuilder rb,
                                                       string strItemSeparator, string strName, string strKeyProtectedString, PwEntry pe)
 {
     if (pe.Strings.Get(strKeyProtectedString).IsProtected)
     {
         EvAppendEntryFieldString(rb, strItemSeparator, strName, PwDefs.HiddenPassword);
     }
     else
     {
         EvAppendEntryFieldString(
             rb, strItemSeparator, strName,
             pe.Strings.Get(strKeyProtectedString).ReadString());
     }
 }
Ejemplo n.º 12
0
        public void CanDefaultFont()
        {
            var builder = new RichTextBuilder();

            builder.SetDefaultFont("Arial");
            var rtf = builder.Text("Hello").ToRtf();

            _output.WriteLine(rtf);
            int i = rtf.IndexOf("\\fonttbl", StringComparison.Ordinal);
            int j = rtf.IndexOf(" Arial;", StringComparison.Ordinal);
            int k = rtf.IndexOf("Hello", StringComparison.Ordinal);

            Assert.True(i > 0 && j > i && k > j);
        }
Ejemplo n.º 13
0
    // Start is called before the first frame update
    void Start()
    {
        _rich = new RichTextBuilder();

        _out.AddItem(_rich.B().C("61fa68").T("t5word").C("5df3f5").T("@").C("61fa68").T("tmac").C("6771fe").T(" ~/proj/craft").Print());
        _out.AddItem(_rich.B().C("e5b0ff").T("胖子").E().T("进行了").C("6771fe").T("魔法").E().T("攻击").Print());

        _battle = new BattleField();
        _battle.ForceAlly(1);
        _battle.ForceAlly(2, 3);
        _battle.ForceAlly(3, 2);

        _unit = new Unit("Player");
        _unit.UpdateBattleProperties();
        var hp     = _unit.GetProperty <MaxValueProperty>(PropertyType.Health);
        var cri    = _unit.GetProperty <ValueProperty>(PropertyType.CriticalRate);
        var cridmg = _unit.GetProperty <ValueProperty>(PropertyType.CriticalDamage);

        hp.Base     = 100;
        hp.Current  = 65;
        cri.Base    = 0.50f;
        cridmg.Base = 2.00f;
        _act        = _unit.AddSkill(new AttackAct("attack", 0, TargetType.One, new AttackFactors(magicFactorA: 0)));

        _unit2 = CreateTestUnit("史莱姆皇帝");
        _unit3 = CreateTestUnit("白金之星");

        _battle.AddUnit(_unit, 1, 1);

        _battle.AddUnit(_unit2, 2, 1);
        _battle.AddUnit(CreateTestUnit("金属史莱姆"), 2, 1);
        _battle.AddUnit(CreateTestUnit("岩石史莱姆"), 2, 1);
        _battle.AddUnit(CreateTestUnit("火焰史莱姆"), 2, 1);

        _battle.AddUnit(CreateTestUnit("野狼首领"), 2, 2);
        _battle.AddUnit(CreateTestUnit("野狼"), 2, 2);
        _battle.AddUnit(CreateTestUnit("野狼"), 2, 2);

        _battle.AddUnit(_unit3, 3, 2);

        ShowUnit(_unit);
        ShowUnit(_unit2);
        ShowUnit(_unit3);

        var playerForce  = _battle.AllTarget.GetForce(1);
        var enemiesForce = _battle.AllTarget.GetForce(2);

        _player.SetForce(playerForce, OnUnitClick);
        _enemies.SetForce(enemiesForce, OnUnitClick);
    }
Ejemplo n.º 14
0
        public static string GetParameterInfoRTF([NotNull] PropertyInfo property)
        {
            Assert.ArgumentNotNull(property, nameof(property));

            string displayType = GetParameterDisplayType(property);
            string description = GetParameterDescription(property);

            var rtf = new RichTextBuilder();

            rtf.FontSize(8);
            rtf.Bold(property.Name).Text(" (").Text(displayType).Text(")");
            rtf.LineBreak();
            rtf.Text(description);

            return(rtf.ToRtf());
        }
Ejemplo n.º 15
0
        public void CanFontChange()
        {
            var builder = new RichTextBuilder();

            builder.SetDefaultFont("Arial");
            builder.Text("Start").LineBreak();
            builder.Begin().Font("Times New Roman");
            builder.Text("Times New Roman").End().LineBreak();
            builder.Begin().Font("Arial").Text("Arial").End().LineBreak();
            var rtf = builder.ToRtf();

            _output.WriteLine(rtf);
            int i = rtf.IndexOf(@"{\f1 Times New Roman}", StringComparison.Ordinal);
            int j = rtf.IndexOf(@"{\f0 Arial}", StringComparison.Ordinal);

            Assert.True(i > 0 && j > i);
        }
Ejemplo n.º 16
0
        public static string ReplaceFormattingTags(string strNotes)
        {
            // This code copied from KeePass.Forms.MainForm.ShowEntryDetails (MainForm_Functions.cs). It is not otherwise exposed.
            KeyValuePair <string, string> kvpBold = RichTextBuilder.GetStyleIdCodes(
                FontStyle.Bold);
            KeyValuePair <string, string> kvpItalic = RichTextBuilder.GetStyleIdCodes(
                FontStyle.Italic);
            KeyValuePair <string, string> kvpUnderline = RichTextBuilder.GetStyleIdCodes(
                FontStyle.Underline);

            strNotes = strNotes.Replace(@"<b>", kvpBold.Key);
            strNotes = strNotes.Replace(@"</b>", kvpBold.Value);
            strNotes = strNotes.Replace(@"<i>", kvpItalic.Key);
            strNotes = strNotes.Replace(@"</i>", kvpItalic.Value);
            strNotes = strNotes.Replace(@"<u>", kvpUnderline.Key);
            strNotes = strNotes.Replace(@"</u>", kvpUnderline.Value);

            return(strNotes);
        }
Ejemplo n.º 17
0
        public void CanFormattedText()
        {
            var builder = new RichTextBuilder();

            builder.LineLimit = 999;             // long lines are fine for this test
            builder.Text("This is ").Bold("bold").Text(" and ").Italic("italic").Text(" text.");
            builder.LineBreak();
            builder.Text("And this is ");
            builder.Begin().Bold().Italic().Text("Bold Italic").End().Text(" text.");
            var rtf = builder.ToRtf();

            _output.WriteLine(rtf);
            int i = rtf.IndexOf("This is ", StringComparison.Ordinal);

            Assert.True(i > 0);
            Assert.Equal(
                @"This is {\b bold} and {\i italic} text.\line And this is {\b\i Bold Italic} text.}",
                rtf.Substring(i));
        }
Ejemplo n.º 18
0
        /// <summary></summary>
        public void ToRichText(RichTextBuilder builder)
        {
            Color foregroundColor = builder.ForegroundColor;

            try {
                if (!IsValid)
                {
                    builder.ForegroundColor = Color.Red;
                }

                switch (Type)
                {
                default:
                    builder.Append(this);
                    break;
                }
            } finally {
                builder.ForegroundColor = foregroundColor;
            }
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            int    maxEditions      = 2;
            int    insertionCost    = 1;
            int    deletionCost     = 1;
            int    substitutionCost = 2;
            int    errorCost        = -1;
            Stream inputStream      = Console.OpenStandardInput();
            Stream outputStream     = Console.OpenStandardOutput();

            LevenshteinDistanceAnalyzer analyzer = new LevenshteinDistanceAnalyzer(maxEditions, insertionCost, deletionCost, substitutionCost, errorCost);
            WordParser     parser = new WordParser(inputStream);
            RichTextWriter writer = new RichTextWriter(outputStream);
            StaticWordDictionaryBuilder dictionaryBuilder = new StaticWordDictionaryBuilder(parser, analyzer);
            RichTextBuilder             textBuilder       = new RichTextBuilder(parser);
            WordNeighborsFormater       formater          = new WordNeighborsFormater();

            SpellCheckProcessor.SpellChecker spellChecker = new SpellCheckProcessor.SpellChecker(dictionaryBuilder, textBuilder, "===");
            spellChecker.Check(writer, formater, 2);
            writer.Flush();
        }
Ejemplo n.º 20
0
        public static string Skill(SkillDescriptor Desc)
        {
            var Builder = new RichTextBuilder();

            Builder
            .Chunk($"{Desc.Name}\n", Color.red)
            .Msg("------------------\n")
            .Chunk($"冷却:{Desc.CD}s\n", Color.green)
            .Chunk($"消耗:{Desc.Cost}\n", Color.blue);

            if (Desc.Radius > 0)
            {
                Builder.Chunk($"半径:{Desc.Radius}\n", Color.blue);
            }

            /*if (!string.IsNullOrWhiteSpace(Desc.About))
             * {
             *  Builder.Msg("------------------\n")
             *      .Chunk(Desc.About, Color.white, 20);
             * }*/

            return(Builder.GetRichText());
        }
Ejemplo n.º 21
0
        /// <summary></summary>
        public void ToRichText(RichTextBuilder builder)
        {
            Color foregroundColor = builder.ForegroundColor;

            try {
                if (!IsValid)
                    builder.ForegroundColor = Color.Red;

                switch (Type) {
                    default:
                        builder.Append(this);
                        break;
                }
            } finally {
                builder.ForegroundColor = foregroundColor;
            }
        }
Ejemplo n.º 22
0
        public override System.Windows.Forms.Control Browse(Action <double> progressUpdateCallback = null)
        {
            RichTextBuilder builder    = new RichTextBuilder();
            bool            indentNext = false;

            //builder.Append(@"{\rtf\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\par ");
            builder.UnderlineStyle = RichTextUnderlineStyle.Double;

            foreach (ScriptInstruction instruction in Instructions)
            {
                string codeName = CodeAddressName(instruction.Address);

                if (codeName != null)
                {
                    builder.AppendFormat("\n==============================\n{0}\n==============================\n", codeName);
                }

                if (instruction.IsTarget)
                {
                    builder.IsUnderlined = true;
                }
                builder.AppendFormat("{0:X}h", instruction.Address);
                if (instruction.IsTarget)
                {
                    builder.IsUnderlined = false;
                }
                builder.Append(":\t");

                if (indentNext)
                {
                    builder.Append("\t");
                }
                instruction.ToRichText(builder);
                //builder.Append(instruction.ToString());
                builder.Append("\n");
                if (instruction.IsBranch && !indentNext)
                {
                    builder.Append("\n");
                }
                indentNext = instruction.IsTest;
            }

            builder.Append(ExceptionEnd);
            var output = builder.ToString();

            BetterRichTextBox box = new BetterRichTextBox()
            {
                ReadOnly  = false,
                Multiline = true,
                //ScrollBars = ScrollBars.Vertical,
                Rtf      = output,
                WordWrap = false,
            };

            Font normal     = box.Font;
            var  underlined = new Font(normal, FontStyle.Underline);
            bool recurse    = false;

            box.SelectionChanged += (object sender, EventArgs args) => {
                if (recurse)
                {
                    return;
                }

                try {
                    Point scrollPosition = box.ScrollPosition;
                    int   resetStart = box.SelectionStart, resetLength = box.SelectionLength;
                    box.BeginUpdate();

                    recurse = true;
                    var    start = box.SelectionStart;
                    string text  = box.Text;

                    if (!IsIdentifier(text, start) && !IsIdentifier(text, start - 1))
                    {
                        return;
                    }
                    while (IsIdentifier(text, start - 1))
                    {
                        start--;
                    }

                    int end = box.SelectionStart;
                    while (IsIdentifier(text, end))
                    {
                        end++;
                    }

                    string searchText = text.Substring(start, end - start);

                    box.SelectAll();
                    //box.SelectionFont = normal;
                    box.SelectionBackColor = Color.Transparent;

                    start = 0;
                    while (true)
                    {
                        start = text.IndexOf(searchText, start);
                        if (start < 0)
                        {
                            break;
                        }

                        if (!IsIdentifier(text, start - 1) && !IsIdentifier(text, start + searchText.Length))
                        {
                            box.Select(start, searchText.Length);
                            //box.SelectionFont = underlined;
                            box.SelectionBackColor = Color.Yellow;
                        }

                        start += searchText.Length;
                    }

                    box.Select(resetStart, resetLength);
                    box.ScrollPosition = scrollPosition;
                } finally {
                    box.EndUpdate();
                    box.Invalidate();
                    recurse = false;
                }
            };

            box.LinkClicked += (sender, args) => {
                throw new Exception();
            };


            return(box);
        }
Ejemplo n.º 23
0
        /// <summary>Convert to a rich text form with the builder.</summary>
        /// <param name="builder"></param>
        public void ToRichText(RichTextBuilder builder)
        {
            if (IsTarget) {
                builder.ForegroundColor = Color.Blue;
                builder.AppendFormat("<{0}> ", AddressString);
            }

            if (IsFunction)
                builder.ForegroundColor = Color.DarkGreen;
            else if (IsPointer)
                builder.ForegroundColor = Color.Purple;
            builder.Append(ToStringValue());

            if (IsInvalid) {
                builder.ForegroundColor = Color.Red;
                builder.Append(" <<" + Errors.Replace("\n", "; ") + ">>");
            }

            builder.ForegroundColor = Color.Black;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Convert to rich text.
        /// </summary>
        /// <param name="builder"></param>
        public void ToRichText(RichTextBuilder builder)
        {
            builder.AppendFormat("{0}: ", AddressString);
            Opcode.ToRichText(builder);

            for (int index = 0; index < Operands.Count; index++) {
                builder.Append(index == 0 ? " " : ", ");
                Operands[index].ToRichText(builder);
            }
        }
Ejemplo n.º 25
0
        /// <summary>Produce a rich text document that examines the file.</summary>
        /// <returns></returns>
        public override System.Windows.Forms.Control Browse(Action<double> progressUpdateCallback = null)
        {
            var box = new BetterRichTextBox() {
                Multiline = true,
                ReadOnly = true,
                WordWrap = true,
            };

            bool recurse = false;

            box.SelectionChanged += (object sender, EventArgs args) => {
                if (recurse)
                    return;

                try {
                    Point scrollPosition = box.ScrollPosition;
                    int resetStart = box.SelectionStart, resetLength = box.SelectionLength;
                    box.BeginUpdate();

                    recurse = true;
                    var start = box.SelectionStart;
                    string text = box.Text;

                    if (!IsIdentifier(text, start) && !IsIdentifier(text, start - 1))
                        return;
                    while (IsIdentifier(text, start - 1))
                        start--;

                    int end = box.SelectionStart;
                    while (IsIdentifier(text, end))
                        end++;

                    string searchText = text.Substring(start, end - start);

                    box.SelectAll();
                    //box.SelectionFont = normal;
                    box.SelectionBackColor = Color.Transparent;

                    start = 0;
                    while (true) {
                        start = text.IndexOf(searchText, start);
                        if (start < 0)
                            break;

                        if (!IsIdentifier(text, start - 1) && !IsIdentifier(text, start + searchText.Length)) {
                            box.Select(start, searchText.Length);
                            //box.SelectionFont = underlined;
                            box.SelectionBackColor = Color.Yellow;
                        }

                        start += searchText.Length;
                    }

                    box.Select(resetStart, resetLength);
                    box.ScrollPosition = scrollPosition;
                } finally {
                    box.EndUpdate();
                    box.Invalidate();
                    recurse = false;
                }
            };

            RichTextBuilder builder = new RichTextBuilder();

            foreach (EffectInstruction instruction in Instructions) {
                instruction.ToRichText(builder);
                builder.Append("\n");
            }

            box.Rtf = builder.ToString();
            return box;
        }
Ejemplo n.º 26
0
        public override System.Windows.Forms.Control Browse(Action<double> progressUpdateCallback = null)
        {
            RichTextBuilder builder = new RichTextBuilder();
            bool indentNext = false;

            //builder.Append(@"{\rtf\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\par ");
            builder.UnderlineStyle = RichTextUnderlineStyle.Double;

            foreach (ScriptInstruction instruction in Instructions) {
                string codeName = CodeAddressName(instruction.Address);

                if (codeName != null)
                    builder.AppendFormat("\n==============================\n{0}\n==============================\n", codeName);

                if (instruction.IsTarget)
                    builder.IsUnderlined = true;
                builder.AppendFormat("{0:X}h", instruction.Address);
                if (instruction.IsTarget)
                    builder.IsUnderlined = false;
                builder.Append(":\t");

                if (indentNext)
                    builder.Append("\t");
                instruction.ToRichText(builder);
                //builder.Append(instruction.ToString());
                builder.Append("\n");
                if (instruction.IsBranch && !indentNext)
                    builder.Append("\n");
                indentNext = instruction.IsTest;
            }

            builder.Append(ExceptionEnd);
            var output = builder.ToString();

            BetterRichTextBox box = new BetterRichTextBox() {
                ReadOnly = false,
                Multiline = true,
                //ScrollBars = ScrollBars.Vertical,
                Rtf = output,
                WordWrap = false,
            };

            Font normal = box.Font;
            var underlined = new Font(normal, FontStyle.Underline);
            bool recurse = false;

            box.SelectionChanged += (object sender, EventArgs args) => {
                if (recurse)
                    return;

                try {
                    Point scrollPosition = box.ScrollPosition;
                    int resetStart = box.SelectionStart, resetLength = box.SelectionLength;
                    box.BeginUpdate();

                    recurse = true;
                    var start = box.SelectionStart;
                    string text = box.Text;

                    if (!IsIdentifier(text, start) && !IsIdentifier(text, start - 1))
                        return;
                    while (IsIdentifier(text, start - 1))
                        start--;

                    int end = box.SelectionStart;
                    while (IsIdentifier(text, end))
                        end++;

                    string searchText = text.Substring(start, end - start);

                    box.SelectAll();
                    //box.SelectionFont = normal;
                    box.SelectionBackColor = Color.Transparent;

                    start = 0;
                    while (true) {
                        start = text.IndexOf(searchText, start);
                        if (start < 0)
                            break;

                        if (!IsIdentifier(text, start - 1) && !IsIdentifier(text, start + searchText.Length)) {
                            box.Select(start, searchText.Length);
                            //box.SelectionFont = underlined;
                            box.SelectionBackColor = Color.Yellow;
                        }

                        start += searchText.Length;
                    }

                    box.Select(resetStart, resetLength);
                    box.ScrollPosition = scrollPosition;
                } finally {
                    box.EndUpdate();
                    box.Invalidate();
                    recurse = false;
                }
            };

            box.LinkClicked += (sender, args) => {
                throw new Exception();
            };

            return box;
        }
Ejemplo n.º 27
0
        private void InitPlaceholdersBox()
        {
            const string VkcBreak = @"<break />";

            string[] vSpecialKeyCodes = new string[] {
                "TAB", "ENTER", "UP", "DOWN", "LEFT", "RIGHT",
                "HOME", "END", "PGUP", "PGDN",
                "INSERT", "DELETE", VkcBreak,
                "BACKSPACE", "BREAK", "CAPSLOCK",
                "ESC", "HELP", "NUMLOCK", "PRTSC", "SCROLLLOCK", VkcBreak,
                "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
                "F13", "F14", "F15", "F16", VkcBreak,
                "ADD", "SUBTRACT", "MULTIPLY", "DIVIDE"
            };

            string[] vSpecialPlaceholders = new string[] {
                "GROUP", "GROUPPATH", "PASSWORD_ENC", "URL:RMVSCM",
                "C:Comment", VkcBreak,
                "DELAY 1000", "DELAY=200", "VKEY 65",
                "PICKCHARS", "PICKCHARS:Password:C=3",
                "NEWPASSWORD", "HMACOTP", "CLEARFIELD", VkcBreak,
                "APPDIR", "DB_PATH", "DB_DIR", "DB_NAME", "DB_BASENAME", "DB_EXT",
                "ENV_DIRSEP", VkcBreak,
                "DT_SIMPLE", "DT_YEAR", "DT_MONTH", "DT_DAY", "DT_HOUR", "DT_MINUTE",
                "DT_SECOND", "DT_UTC_SIMPLE", "DT_UTC_YEAR", "DT_UTC_MONTH",
                "DT_UTC_DAY", "DT_UTC_HOUR", "DT_UTC_MINUTE", "DT_UTC_SECOND"
            };

            RichTextBuilder rb = new RichTextBuilder();

            rb.AppendLine(KPRes.StandardFields, FontStyle.Bold, null, null, ":", null);

            rb.Append("{" + PwDefs.TitleField + "} ");
            rb.Append("{" + PwDefs.UserNameField + "} ");
            rb.Append("{" + PwDefs.PasswordField + "} ");
            rb.Append("{" + PwDefs.UrlField + "} ");
            rb.Append("{" + PwDefs.NotesField + "}");

            bool bCustomInitialized = false, bFirst = true;

            foreach (KeyValuePair <string, ProtectedString> kvp in m_vStringDict)
            {
                if (!PwDefs.IsStandardField(kvp.Key))
                {
                    if (bCustomInitialized == false)
                    {
                        rb.AppendLine();
                        rb.AppendLine();
                        rb.AppendLine(KPRes.CustomFields, FontStyle.Bold, null, null, ":", null);
                        bCustomInitialized = true;
                    }

                    if (!bFirst)
                    {
                        rb.Append(" ");
                    }
                    rb.Append("{" + PwDefs.AutoTypeStringPrefix + kvp.Key + "}");
                    bFirst = false;
                }
            }

            rb.AppendLine();
            rb.AppendLine();
            rb.AppendLine(KPRes.KeyboardKeyModifiers, FontStyle.Bold, null, null, ":", null);
            rb.Append(KPRes.KeyboardKeyShift + @": +, ");
            rb.Append(KPRes.KeyboardKeyCtrl + @": ^, ");
            rb.Append(KPRes.KeyboardKeyAlt + @": %");

            rb.AppendLine();
            rb.AppendLine();
            rb.AppendLine(KPRes.SpecialKeys, FontStyle.Bold, null, null, ":", null);
            bFirst = true;
            foreach (string strNav in vSpecialKeyCodes)
            {
                if (strNav == VkcBreak)
                {
                    rb.AppendLine(); rb.AppendLine(); bFirst = true;
                }
                else
                {
                    if (!bFirst)
                    {
                        rb.Append(" ");
                    }
                    rb.Append("{" + strNav + "}");
                    bFirst = false;
                }
            }

            rb.AppendLine();
            rb.AppendLine();
            rb.AppendLine(KPRes.OtherPlaceholders, FontStyle.Bold, null, null, ":", null);
            bFirst = true;
            foreach (string strPH in vSpecialPlaceholders)
            {
                if (strPH == VkcBreak)
                {
                    rb.AppendLine(); rb.AppendLine(); bFirst = true;
                }
                else
                {
                    if (!bFirst)
                    {
                        rb.Append(" ");
                    }
                    rb.Append("{" + strPH + "}");
                    bFirst = false;
                }
            }

            rb.Build(m_rtbPlaceholders);

            LinkifyRtf(m_rtbPlaceholders);
        }
Ejemplo n.º 28
0
        public void InitEx(PwEntry pe)
        {
            btn_Reload.Enabled = false;
            btn_Reload.Visible = false;

            RichTextBuilder rb = new RichTextBuilder();

            string strItemSeperator = Environment.NewLine;

            EvAppendEntryFieldProtectedString(rb, strItemSeperator, "Title", PwDefs.TitleField, pe);
            EvAppendEntryFieldProtectedString(rb, strItemSeperator, "Username", PwDefs.UserNameField, pe);
            EvAppendEntryFieldProtectedString(rb, strItemSeperator, "URL", PwDefs.UrlField, pe);

            this.Text = this.Text + " - " + pe.Strings.ReadSafe(PwDefs.TitleField);


            string         r           = "";
            string         totpAlready = "No";
            KP2faC_Website curWebsite  = null;
            bool           bPossible   = false;

            if ((pe.Strings.Exists("otp") && pe.Strings.Get("otp") != null) ||
                (pe.Strings.Exists("TOTP Seed") && pe.Strings.Get("TOTP Seed") != null))
            {
                totpAlready = "Yes";
            }
            string url = pe.Strings.ReadSafe(PwDefs.UrlField);

            pb_trafficlight.Image = Properties.Resources.trafficlight_orange;
            if (String.IsNullOrEmpty(url))
            {
                r = "No Url set. A Url is needed to check for 2fa support";
            }
            else
            {
                if (KP2faCheckerExt.dictKp2fac_WebsiteByDomain.Count > 0)
                {
                    string   prettifiedUrl = KP2faCheckerExt.prettifyUrl(url, KP2faCheckerExt.prettifyMode.AllWithoutTld);
                    string[] domainArray   = prettifiedUrl.Split('.').Reverse().ToArray();

                    var curDict = KP2faCheckerExt.dictKp2fac_WebsiteByDomain;
                    for (int i = 0; i < domainArray.Length; i++)
                    {
                        if (curDict.ContainsKey(domainArray[i]))
                        {
                            if (curDict[domainArray[i]] is KP2faC_Website)
                            {
                                if (((KP2faC_Website)curDict[domainArray[i]]).is2faPosssible())
                                {
                                    if (i == domainArray.Length - 1)
                                    {
                                        r                     = "Yes" + r;
                                        bPossible             = true;
                                        pb_trafficlight.Image = Properties.Resources.trafficlight_green;
                                    }
                                }
                                else
                                {
                                    r = "No" + r;
                                    pb_trafficlight.Image = Properties.Resources.trafficlight_red;
                                }
                                curWebsite = (KP2faC_Website)curDict[domainArray[i]];
                            }
                            else
                            {
                                curDict = (Dictionary <string, object>)curDict[domainArray[i]];
                                if (i == domainArray.Length - 1)
                                {
                                    if (curDict.ContainsKey("*") && curDict["*"] is KP2faC_Website)
                                    {
                                        if (((KP2faC_Website)curDict["*"]).is2faPosssible())
                                        {
                                            r                     = "Yes" + r;
                                            bPossible             = true;
                                            pb_trafficlight.Image = Properties.Resources.trafficlight_green;
                                        }
                                        else
                                        {
                                            r = "No" + r;
                                            pb_trafficlight.Image = Properties.Resources.trafficlight_red;
                                        }
                                        curWebsite = (KP2faC_Website)curDict["*"];
                                    }
                                }
                            }
                        }
                        else if (curDict.ContainsKey("*"))
                        {
                            if (curDict["*"] is KP2faC_Website)
                            {
                                if (((KP2faC_Website)curDict["*"]).is2faPosssible())
                                {
                                    r                     = "Yes" + r;
                                    bPossible             = true;
                                    pb_trafficlight.Image = Properties.Resources.trafficlight_green;
                                }
                                else
                                {
                                    r = "No" + r;
                                    pb_trafficlight.Image = Properties.Resources.trafficlight_red;
                                }
                                curWebsite = (KP2faC_Website)curDict["*"];
                            }
                            break;
                        }
                    }
                }
                else
                {
                    r = "Unknown. API Error!";
                    btn_Reload.Enabled = true;
                    btn_Reload.Visible = true;
                    btn_Reload.Tag     = pe;
                }
                if (string.IsNullOrEmpty(r))
                {
                    r = "Dont know!";
                }
            }
            EvAppendEntryFieldString(rb, strItemSeperator, "2FA already configured", totpAlready);
            rb.Build(rtb_Entry);

            rb = new RichTextBuilder();
            EvAppendEntryFieldString(rb, strItemSeperator, "2FA supported", r);
            if (bPossible && curWebsite != null)
            {
                rb.AppendLine();
                EvAppendEntryFieldString(rb, strItemSeperator, "Websitename", curWebsite.name);
                EvAppendEntryFieldString(rb, strItemSeperator, "2FA Options", curWebsite.getTfa());
                EvAppendEntryFieldString(rb, strItemSeperator, "Documentation", curWebsite.doc);
                if (!String.IsNullOrEmpty(curWebsite.exception))
                {
                    EvAppendEntryFieldString(rb, strItemSeperator, "Exception", curWebsite.exception);
                }
            }
            else if (!bPossible && curWebsite != null)
            {
                EvAppendEntryFieldString(rb, strItemSeperator, "This is wrong?", "Give a hint! https://toasted.top/kp2fac/");
                rb.AppendLine();
                EvAppendEntryFieldString(rb, strItemSeperator, "Tell them to support 2FA!", " ");
                if (!String.IsNullOrEmpty(curWebsite.email_address))
                {
                    EvAppendEntryFieldString(rb, strItemSeperator, "Email address", curWebsite.email_address);
                }
                if (!String.IsNullOrEmpty(curWebsite.facebook))
                {
                    EvAppendEntryFieldString(rb, strItemSeperator, "Facebook", curWebsite.facebook);
                }
                if (!String.IsNullOrEmpty(curWebsite.twitter))
                {
                    EvAppendEntryFieldString(rb, strItemSeperator, "Twitter", curWebsite.twitter);
                }
            }
            else
            {
                rb.AppendLine();
                EvAppendEntryFieldString(rb, strItemSeperator, "Is 2fa supported?", "Give a hint! https://toasted.top/kp2fac/");
            }

            rb.Build(rtb_2FA);
        }
Ejemplo n.º 29
0
        /// <summary>Produce a rich text document that examines the file.</summary>
        /// <returns></returns>
        public override System.Windows.Forms.Control Browse(Action <double> progressUpdateCallback = null)
        {
            var box = new BetterRichTextBox()
            {
                Multiline = true,
                ReadOnly  = true,
                WordWrap  = true,
            };

            bool recurse = false;

            box.SelectionChanged += (object sender, EventArgs args) => {
                if (recurse)
                {
                    return;
                }

                try {
                    Point scrollPosition = box.ScrollPosition;
                    int   resetStart = box.SelectionStart, resetLength = box.SelectionLength;
                    box.BeginUpdate();

                    recurse = true;
                    var    start = box.SelectionStart;
                    string text  = box.Text;

                    if (!IsIdentifier(text, start) && !IsIdentifier(text, start - 1))
                    {
                        return;
                    }
                    while (IsIdentifier(text, start - 1))
                    {
                        start--;
                    }

                    int end = box.SelectionStart;
                    while (IsIdentifier(text, end))
                    {
                        end++;
                    }

                    string searchText = text.Substring(start, end - start);

                    box.SelectAll();
                    //box.SelectionFont = normal;
                    box.SelectionBackColor = Color.Transparent;

                    start = 0;
                    while (true)
                    {
                        start = text.IndexOf(searchText, start);
                        if (start < 0)
                        {
                            break;
                        }

                        if (!IsIdentifier(text, start - 1) && !IsIdentifier(text, start + searchText.Length))
                        {
                            box.Select(start, searchText.Length);
                            //box.SelectionFont = underlined;
                            box.SelectionBackColor = Color.Yellow;
                        }

                        start += searchText.Length;
                    }

                    box.Select(resetStart, resetLength);
                    box.ScrollPosition = scrollPosition;
                } finally {
                    box.EndUpdate();
                    box.Invalidate();
                    recurse = false;
                }
            };

            RichTextBuilder builder = new RichTextBuilder();

            foreach (EffectInstruction instruction in Instructions)
            {
                instruction.ToRichText(builder);
                builder.Append("\n");
            }

            box.Rtf = builder.ToString();
            return(box);
        }
Ejemplo n.º 30
0
 TravelPanel()
 {
     _rt = new RichTextBuilder();
 }
Ejemplo n.º 31
0
        private void InitPlaceholdersBox()
        {
            const string VkcBreak = @"<break />";

            string[] vSpecialKeyCodes = new string[] {
                "TAB", "ENTER", "UP", "DOWN", "LEFT", "RIGHT",
                "HOME", "END", "PGUP", "PGDN",
                "INSERT", "DELETE", "SPACE", VkcBreak,
                "BACKSPACE", "BREAK", "CAPSLOCK", "ESC",
                "WIN", "LWIN", "RWIN", "APPS",
                "HELP", "NUMLOCK", "PRTSC", "SCROLLLOCK", VkcBreak,
                "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
                "F13", "F14", "F15", "F16", VkcBreak,
                "ADD", "SUBTRACT", "MULTIPLY", "DIVIDE",
                "NUMPAD0", "NUMPAD1", "NUMPAD2", "NUMPAD3", "NUMPAD4",
                "NUMPAD5", "NUMPAD6", "NUMPAD7", "NUMPAD8", "NUMPAD9"
            };

            string[] vSpecialPlaceholders = new string[] {
                "GROUP", "GROUP_PATH", "GROUP_NOTES", "PASSWORD_ENC",
                "URL:RMVSCM", "URL:SCM", "URL:HOST", "URL:PORT", "URL:PATH",
                "URL:QUERY", "URL:USERINFO", "URL:USERNAME", "URL:PASSWORD",
                // "BASE",
                "T-REPLACE-RX:/T/S/R/", "T-CONV:/T/C/",
                "C:Comment", VkcBreak,
                "DELAY 1000", "DELAY=200", "VKEY 13", "VKEY-NX 13", "VKEY-EX 13",
                "PICKCHARS", "PICKCHARS:Password:C=3",
                "NEWPASSWORD", "NEWPASSWORD:/Profile/", "HMACOTP", "CLEARFIELD",
                "APPACTIVATE " + KPRes.Title, "BEEP 800 200", VkcBreak,
                "APPDIR", "DB_PATH", "DB_DIR", "DB_NAME", "DB_BASENAME", "DB_EXT",
                "ENV_DIRSEP", "ENV_PROGRAMFILES_X86", VkcBreak,
                // "INTERNETEXPLORER", "FIREFOX", "OPERA", "GOOGLECHROME",
                // "SAFARI", VkcBreak,
                "DT_SIMPLE", "DT_YEAR", "DT_MONTH", "DT_DAY", "DT_HOUR", "DT_MINUTE",
                "DT_SECOND", "DT_UTC_SIMPLE", "DT_UTC_YEAR", "DT_UTC_MONTH",
                "DT_UTC_DAY", "DT_UTC_HOUR", "DT_UTC_MINUTE", "DT_UTC_SECOND"
            };

            RichTextBuilder rb = new RichTextBuilder();

            rb.AppendLine(KPRes.StandardFields, FontStyle.Bold, null, null, ":", null);

            rb.Append("{" + PwDefs.TitleField + "} ");
            rb.Append("{" + PwDefs.UserNameField + "} ");
            rb.Append("{" + PwDefs.PasswordField + "} ");
            rb.Append("{" + PwDefs.UrlField + "} ");
            rb.Append("{" + PwDefs.NotesField + "}");

            bool bCustomInitialized = false, bFirst = true;

            foreach (KeyValuePair <string, ProtectedString> kvp in m_vStringDict)
            {
                if (!PwDefs.IsStandardField(kvp.Key))
                {
                    if (bCustomInitialized == false)
                    {
                        rb.AppendLine();
                        rb.AppendLine();
                        rb.AppendLine(KPRes.CustomFields, FontStyle.Bold, null, null, ":", null);
                        bCustomInitialized = true;
                    }

                    if (!bFirst)
                    {
                        rb.Append(" ");
                    }
                    rb.Append("{" + PwDefs.AutoTypeStringPrefix + kvp.Key + "}");
                    bFirst = false;
                }
            }

            rb.AppendLine();
            rb.AppendLine();
            rb.AppendLine(KPRes.KeyboardKeyModifiers, FontStyle.Bold, null, null, ":", null);
            rb.Append(KPRes.KeyboardKeyShift + @": +, ");
            rb.Append(KPRes.KeyboardKeyCtrl + @": ^, ");
            rb.Append(KPRes.KeyboardKeyAlt + @": %");

            rb.AppendLine();
            rb.AppendLine();
            rb.AppendLine(KPRes.SpecialKeys, FontStyle.Bold, null, null, ":", null);
            bFirst = true;
            foreach (string strNav in vSpecialKeyCodes)
            {
                if (strNav == VkcBreak)
                {
                    rb.AppendLine(); rb.AppendLine(); bFirst = true;
                }
                else
                {
                    if (!bFirst)
                    {
                        rb.Append(" ");
                    }
                    rb.Append("{" + strNav + "}");
                    bFirst = false;
                }
            }

            rb.AppendLine();
            rb.AppendLine();
            rb.AppendLine(KPRes.OtherPlaceholders, FontStyle.Bold, null, null, ":", null);
            bFirst = true;
            foreach (string strPH in vSpecialPlaceholders)
            {
                if (strPH == VkcBreak)
                {
                    rb.AppendLine(); rb.AppendLine(); bFirst = true;
                }
                else
                {
                    if (!bFirst)
                    {
                        rb.Append(" ");
                    }
                    rb.Append("{" + strPH + "}");
                    bFirst = false;
                }
            }

            if (SprEngine.FilterPlaceholderHints.Count > 0)
            {
                rb.AppendLine();
                rb.AppendLine();
                rb.AppendLine(KPRes.PluginProvided, FontStyle.Bold, null, null, ":", null);
                bFirst = true;
                foreach (string strP in SprEngine.FilterPlaceholderHints)
                {
                    if (string.IsNullOrEmpty(strP))
                    {
                        continue;
                    }

                    if (!bFirst)
                    {
                        rb.Append(" ");
                    }
                    rb.Append(strP);
                    bFirst = false;
                }
            }

            rb.Build(m_rtbPlaceholders);

            LinkifyRtf(m_rtbPlaceholders);
        }
Ejemplo n.º 32
0
        public virtual void ToRichText(RichTextBuilder builder)
        {
            string format;

            if (OpcodeFormats.TryGetValue(Opcode, out format)) {
                for (int index = 0; index < format.Length; index++) {
                    if (format[index] == '{') {
                        if (format[index + 1] == '{') {
                            index++;
                            builder.Append('{');
                        } else {
                            int end;

                            for (end = ++index; format[end] != '}'; end++) ;
                            int operandIndex = int.Parse(format.Substring(index, end - index));
                            ScriptOperand operand = GetOperand(operandIndex);
                            operand.ToRichText(builder);
                            index = end;
                        }
                    } else
                        builder.Append(format[index]);
                }
            } else {
                if (IsOpcodeDefined)
                    builder.Append(Opcode.ToString());
                else {
                    builder.ForegroundColor = Color.Red;
                    builder.AppendFormat("{0:X2}", (int)Opcode);
                    builder.ForegroundColor = Color.Black;
                }

                foreach (ScriptOperand operand in Operands) {
                    builder.Append(" ");
                    operand.ToRichText(builder);
                }
            }
        }