예제 #1
0
        /*OBSOLETE: Header Files will be loaded and parsed in the Parse button click event handler.
         * /// <summary>
         * /// Loads the data of all the header files set in the header file names textbox into the HeaderDeclareParser object in the form,
         * /// which will then make the header data files available for parsing and extracting their type definition and structure data.
         * /// </summary>
         * /// <param name="sender"></param>
         * /// <param name="e"></param>
         * private void btnLoadHeaderFiles_Click(object sender, EventArgs e)
         * {
         *  try
         *  {
         *      DateTime datStart = DateTime.Now;
         *
         *      if (txtHeaderFileNames.Text.Trim() == "")
         *      {
         *          MessageBox.Show("No header files set to be loaded!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
         *          return;
         *      }//end if
         *
         *      m_Parser.ClearHeaderData();
         *
         *      string[] aryHeaderFileNames = txtHeaderFileNames.Text.
         *                                                      Split(new string[] { "\r\n", ",", ";" }, StringSplitOptions.RemoveEmptyEntries)
         *                                                      .Select(filename => filename.Trim())
         *                                                      .Where(filename => File.Exists(filename))
         *                                                      .ToArray();
         *
         *      foreach (string strHeaderFileName in aryHeaderFileNames)
         *      {
         *          m_Parser.AppendHeaderFromFile(strHeaderFileName);
         *      }//next strHeaderFileName
         *
         *      btnParse.Enabled = true;
         *
         *      TimeSpan tsElapsed = DateTime.Now.Subtract(datStart);
         *
         *      MessageBox.Show("Header files loaded into CHeaderDeclareParser object!  The header files can now be parsed.", "Headers Loaded",
         *                                  MessageBoxButtons.OK, MessageBoxIcon.Information);
         *
         *      if (chbShowHdrLoadTime.Checked)
         *          MessageBox.Show("Header Data File Loading Time: " + tsElapsed.TotalSeconds.ToString() + " seconds");
         *  }
         *  catch (Exception err)
         *  {
         *      ErrorHandler.ShowErrorMessage(err, "Error in btnLoadHeaderFiles_Click function of frmCHeaderExtract form.");
         *  }
         * }
         */

        #endregion

        #region Header Parsing and Extraction Functions, Event Handlers

        /// <summary>
        /// When the Parse button is clicked, all header data files will be loaded into the HeaderDeclareParser object of the form and then
        /// will be parsed and have the desired information extracted from the file into data objects.   The parser will extract all type definition,
        /// enumerations, structure and union information from the file and load them into their associated data objects in the data tables of a
        /// CHeaderDataSet data object.   Once all the data in the header data file (or set of files) is parsed, the extracted data can be
        /// queried and displayed in the form or extracted to other data file formats.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnParse_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime datStartTime = DateTime.Now;

                if (!LoadHeaderFiles())
                {
                    return;
                }

                this.Cursor = Cursors.WaitCursor;

                m_Parser.CurrentPos = 0;

                m_HeaderAccess.TypeDefsTable.Rows.Clear();
                m_HeaderAccess.StructuresTable.Rows.Clear();
                m_HeaderAccess.FieldsTable.Rows.Clear();

                TypeExtractor.PointerSizeBytes = Convert.ToInt32(txtPointerSize.Text);
                TypeExtractor.EnumSizeBytes    = Convert.ToInt32(txtEnumSize.Text);

                StructExtractor.PointerSizeBytes = Convert.ToInt32(txtPointerSize.Text);
                StructExtractor.EnumSizeBytes    = Convert.ToInt32(txtEnumSize.Text);

                do
                {
                    if (m_Parser.IsTypeDef())
                    {
                        string      strTypeDef = m_Parser.GetTypeDef();
                        TypeDefData tdData     = m_typeExt.ExtractTypeDefData(strTypeDef);

                        if (tdData != null)
                        {
                            m_HeaderAccess.AddTypeDefRow(tdData);
                        }
                    }
                    else if (m_Parser.IsEnum())
                    {
                        string      strEnum = m_Parser.GetEnum();
                        TypeDefData tdEnum  = m_typeExt.ExtractEnumData(strEnum);

                        if (tdEnum != null)
                        {
                            m_HeaderAccess.AddTypeDefRow(tdEnum);
                        }
                    }
                    else if (m_Parser.IsStruct())
                    {
                        string     strStruct = m_Parser.GetStructure();
                        StructData sdData    = m_structExt.ExtractStructData(strStruct);

                        if (sdData != null)
                        {
                            m_HeaderAccess.AddStructRow(sdData);
                            m_HeaderAccess.AddFieldRows(sdData.Fields);
                        }//end if
                    }
                    else
                    {
                        m_Parser.MoveNextItem();
                    }//end if
                } while (!m_Parser.EndOfFile);

                TimeSpan tsElapsed = DateTime.Now.Subtract(datStartTime);

                //Once the parsing operation completes successfully, all the structures/unions extracted from the header files will be initially
                //queried and loaded in the form.
                rbQryDisplayAll.Checked = true;
                btnQuery_Click(btnQuery, EventArgs.Empty);

                this.Cursor = Cursors.Default;
                MessageBox.Show("Header File Parsing Completed!", "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);

                if (chbShowParseTime.Checked)
                {
                    MessageBox.Show("Parsing Time: " + tsElapsed.TotalSeconds.ToString() + " seconds");
                }
            }
            catch (Exception err)
            {
                this.Cursor = Cursors.Default;
                ErrorHandler.ShowErrorMessage(err, "Error in btnParse_Click function of frmCHeaderExtract form.");
            }
        }