Пример #1
0
 public FormErrorList(WinErrorInfo wei)
 {
     InitializeComponent();
     m_WEI           = wei;
     m_SelectedIndex = -1;
     CbLang.BeginUpdate();
     foreach (var item in WErrorItem.EnumLocales())
     {
         try
         {
             CbLang.Items.Add(item.ToString() + " - " + CultureInfo.GetCultureInfo((int)item).DisplayName);
         }
         catch
         {
         }
     }
     CbLang.SelectedIndex = 0;
 }
Пример #2
0
        /// <summary>
        /// Construir objeto con la lista de errores de Windows.
        /// </summary>
        public WinErrorInfo()
        {
            m_List      = new List <WErrorItem>();
            m_Separator = new char[] { ' ', '\t' };

            // Obtener stream.
            StreamReader sr = GetStreamErrorTextInstalled();

            if (sr == null)
            {
                sr = GetStreamErrorTextResource();
                if (sr == null)
                {
                    throw new Exception("Could not locate WinError.h");
                }
            }

            // Abrir fichero de errores "include\WinError.h".
            using (sr)
            {
                // Leer todas las líneas del fichero.
                while (true)
                {
                    string line = sr.ReadLine();
                    if (line == null)
                    {
                        break;
                    }
                    WErrorItem wei = ParseWinErrorLine(line.Trim());
                    if (wei == null)
                    {
                        continue;
                    }
                    List.Add(wei);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Parsear un línea de WinError.h
        /// </summary>
        /// <param name="str">Cadena de texto con la línea a parsear.</param>
        /// <returns>Información del error o null.</returns>
        private WErrorItem ParseWinErrorLine(string str)
        {
            // Los errores son del tipo:
            //    #define ERROR_TOO_MANY_OPEN_FILES        4L
            //    #define FWP_E_CALLOUT_NOTIFICATION_FAILED _HRESULT_TYPEDEF_(0x80320037L)
            if (str.Length < 20)
            {
                return(null);
            }
            if (!str.StartsWith("#define"))
            {
                return(null);
            }

            // Buscar nombre del '#define' asociado.
            int ndxDef1 = 7;
            int ndxDef2;

            try
            {
                while (char.IsSeparator(str[ndxDef1]))
                {
                    ++ndxDef1;
                }
                ndxDef2 = ndxDef1;
                while (!char.IsSeparator(str[ndxDef2]))
                {
                    ++ndxDef2;
                }
            }
            catch
            {
                return(null);
            }

            // Buscar código de error (terminado en L)
            int ndxCode1 = ndxDef2;
            int ndxCode2;

            try
            {
                while (!char.IsDigit(str[ndxCode1]))
                {
                    ++ndxCode1;
                }
                ndxCode2 = ndxCode1;
                while (str[ndxCode2] != 'L')
                {
                    ++ndxCode2;
                }
            }
            catch
            {
                return(null);
            }
            string strCode = str.Substring(ndxCode1, ndxCode2 - ndxCode1);
            uint   errCode;
            bool   fHex;

            if (strCode.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase))
            {
                if (!uint.TryParse(strCode.Substring(2), System.Globalization.NumberStyles.AllowHexSpecifier, null, out errCode))
                {
                    return(null);
                }
                fHex = true;
            }
            else
            {
                if (!uint.TryParse(strCode, out errCode))
                {
                    return(null);
                }
                fHex = false;
            }

            // Devolver información del error.
            WErrorItem wei = new WErrorItem();

            wei.DefineValue = str.Substring(ndxDef1, ndxDef2 - ndxDef1);
            wei.ErrorCode   = errCode;
            wei.Hexadecimal = fHex;
            return(wei);
        }