private void CommandCode_TextChanged()

in TpmRcDecoder/TpmRcDecoder.Universal/CommandCodes.xaml.cs [3224:3276]


        private void CommandCode_TextChanged(object sender, TextChangedEventArgs e)
        {
            string inStr = CommandCode.Text.Trim();
            uint commandCode = ~0u;
            if (inStr.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
            {
                try
                {
                    commandCode = UInt32.Parse(inStr.Substring(2).Trim(), NumberStyles.HexNumber);
                }
                catch (FormatException)
                { }
            }
            else
            {
                try
                {
                    commandCode = UInt32.Parse(inStr, NumberStyles.Integer);
                }
                catch (FormatException)
                { }
            }
            if (commandCode == ~0u)
            {
                SetIndex(-1, 0, "", m_InvalidCommandDescription);
                return;
            }

            // TPM 1.2
            int index = 0;
            foreach (TPMCommandDescription descr in m_TPM12Commands)
            {
                if (commandCode == descr.Ordinal)
                {
                    SetIndex(index, descr.Ordinal, descr.Name, descr.Description);
                    return;
                }
                index++;
            }
            // TPM 2.0
            foreach (TPMCommandDescription descr in m_TPM20Commands)
            {
                if (commandCode == descr.Ordinal)
                {
                    SetIndex(index, descr.Ordinal, descr.Name, descr.Description);
                    return;
                }
                index++;
            }

            // no matching command found, set defaults
            SetIndex(-1, 0, "", m_InvalidCommandDescription);
        }