コード例 #1
0
ファイル: Form1.cs プロジェクト: Meindert66/T8SuitePro
        private void CompareToFile(string filename)
        {
            if (m_currentfile != "")
            {
                if (m_symbols.Count > 0)
                {
                    dockManager1.BeginUpdate();
                    try
                    {
                        DockPanel dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500));
                        CompareResults tabdet = new CompareResults();
                        tabdet.Dock = DockStyle.Fill;
                        tabdet.Filename = filename;
                        tabdet.onSymbolSelect += new CompareResults.NotifySelectSymbol(tabdet_onSymbolSelect);
                        dockPanel.Controls.Add(tabdet);
                        dockPanel.Text = "Compare results: " + Path.GetFileName(filename);
                        dockPanel.DockTo(dockManager1, DockingStyle.Left, 1);

                        dockPanel.Width = 700;

                        SymbolCollection compare_symbols = new SymbolCollection();
                        FileInfo fi = new FileInfo(filename);
                        logger.Debug("Opening compare file");
                        TryToOpenFile(filename, out compare_symbols, (int)fi.Length);
                        System.Windows.Forms.Application.DoEvents();
                        logger.Debug("Start compare");
                        SetProgress("Start comparing symbols in files");
                        SetProgressPercentage(0);
                        System.Windows.Forms.Application.DoEvents();
                        System.Data.DataTable dt = new System.Data.DataTable();
                        dt.Columns.Add("SYMBOLNAME");
                        dt.Columns.Add("SRAMADDRESS", Type.GetType("System.Int32"));
                        dt.Columns.Add("FLASHADDRESS", Type.GetType("System.Int32"));
                        dt.Columns.Add("LENGTHBYTES", Type.GetType("System.Int32"));
                        dt.Columns.Add("LENGTHVALUES", Type.GetType("System.Int32"));
                        dt.Columns.Add("DESCRIPTION");
                        dt.Columns.Add("ISCHANGED", Type.GetType("System.Boolean"));
                        dt.Columns.Add("CATEGORY", Type.GetType("System.Int32")); //0
                        dt.Columns.Add("DIFFPERCENTAGE", Type.GetType("System.Double"));
                        dt.Columns.Add("DIFFABSOLUTE", Type.GetType("System.Int32"));
                        dt.Columns.Add("DIFFAVERAGE", Type.GetType("System.Double"));
                        dt.Columns.Add("CATEGORYNAME");
                        dt.Columns.Add("SUBCATEGORYNAME");
                        dt.Columns.Add("SymbolNumber1", Type.GetType("System.Int32"));
                        dt.Columns.Add("SymbolNumber2", Type.GetType("System.Int32"));
                        dt.Columns.Add("Userdescription");
                        dt.Columns.Add("MissingInOriFile", Type.GetType("System.Boolean"));
                        dt.Columns.Add("MissingInCompareFile", Type.GetType("System.Boolean"));

                        string ht = string.Empty;
                        double diffperc = 0;
                        int diffabs = 0;
                        double diffavg = 0;
                        int percentageDone = 0;
                        int symNumber = 0;

                        XDFCategories cat = XDFCategories.Undocumented;
                        XDFSubCategory subcat = XDFSubCategory.Undocumented;
                        if (compare_symbols.Count > 0)
                        {
                            CompareResults cr = new CompareResults();
                            cr.ShowAddressesInHex = m_appSettings.ShowAddressesInHex;
                            cr.SetFilterMode(m_appSettings.ShowAddressesInHex);
                            SymbolTranslator st = new SymbolTranslator();

                            foreach (SymbolHelper sh_compare in compare_symbols)
                            {
                                try
                                {
                                    symNumber++;
                                    percentageDone = (symNumber * 50) / compare_symbols.Count;
                                    if (Convert.ToInt32(barProgress.EditValue) != percentageDone)
                                    {
                                        barProgress.EditValue = percentageDone;
                                        System.Windows.Forms.Application.DoEvents();
                                    }
                                }
                                catch (Exception E)
                                {
                                    logger.Debug(E.Message);
                                }

                                string compareName = sh_compare.SmartVarname;
                                foreach (SymbolHelper sh_org in m_symbols)
                                {
                                    string originalName = sh_org.SmartVarname;
                                    if (compareName.Equals(originalName) && compareName != String.Empty)
                                    {
                                        if (sh_compare.Flash_start_address > 0 && sh_compare.Flash_start_address < 0x100000)
                                        {
                                            if (sh_org.Flash_start_address > 0 && sh_org.Flash_start_address < 0x100000)
                                            {
                                                if (!CompareSymbolToCurrentFile(compareName, (int)sh_compare.Flash_start_address, sh_compare.Length, filename, out diffperc, out diffabs, out diffavg))
                                                {
                                                    sh_org.createAndUpdateCategory(sh_org.SmartVarname);
                                                    dt.Rows.Add(originalName, sh_compare.Start_address, sh_compare.Flash_start_address, sh_compare.Length, sh_compare.Length, st.TranslateSymbolToHelpText(compareName, out ht, out cat, out subcat), false, 0, diffperc, diffabs, diffavg, sh_org.Category, "", sh_org.Symbol_number, sh_compare.Symbol_number, sh_org.Userdescription);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            symNumber = 0;
                            string varnamecomp = string.Empty;
                            foreach (SymbolHelper shtest in compare_symbols)
                            {
                                try
                                {
                                    symNumber++;
                                    percentageDone = 50 + (symNumber * 25) / compare_symbols.Count;
                                    if (Convert.ToInt32(barProgress.EditValue) != percentageDone)
                                    {
                                        barProgress.EditValue = percentageDone;
                                        System.Windows.Forms.Application.DoEvents();
                                    }
                                }
                                catch (Exception E)
                                {
                                    logger.Debug(E.Message);
                                }
                                bool _foundSymbol = false;
                                varnamecomp = shtest.SmartVarname;
                                if (IsSymbolCalibration(varnamecomp))
                                {
                                    foreach (SymbolHelper shoritest in m_symbols)
                                    {
                                        if (varnamecomp == shoritest.SmartVarname)
                                        {
                                            _foundSymbol = true;
                                            break;
                                        }
                                    }
                                    if (!_foundSymbol)
                                    {
                                        // add this symbol to the MissingInOriCollection
                                        dt.Rows.Add(varnamecomp, shtest.Start_address, shtest.Flash_start_address, shtest.Length, shtest.Length, st.TranslateSymbolToHelpText(varnamecomp, out ht, out cat, out subcat), false, 0, 0, 0, 0, "Missing in original", "", 0, shtest.Symbol_number, shtest.Userdescription, true, false);
                                    }
                                }
                            }

                            symNumber = 0;
                            foreach (SymbolHelper shtest in m_symbols)
                            {
                                try
                                {
                                    symNumber++;
                                    percentageDone = 75 + (symNumber * 25) / compare_symbols.Count;
                                    if (Convert.ToInt32(barProgress.EditValue) != percentageDone)
                                    {
                                        barProgress.EditValue = percentageDone;
                                        System.Windows.Forms.Application.DoEvents();
                                    }
                                }
                                catch (Exception E)
                                {
                                    logger.Debug(E.Message);
                                }
                                bool _foundSymbol = false;
                                varnamecomp = shtest.SmartVarname;
                                if (IsSymbolCalibration(varnamecomp))
                                {
                                    foreach (SymbolHelper shoritest in compare_symbols)
                                    {
                                        if (varnamecomp == shoritest.SmartVarname)
                                        {
                                            _foundSymbol = true;
                                            break;
                                        }
                                    }
                                    if (!_foundSymbol)
                                    {
                                        // add this symbol to the MissingInCompCollection
                                        dt.Rows.Add(varnamecomp, shtest.Start_address, shtest.Flash_start_address, shtest.Length, shtest.Length, st.TranslateSymbolToHelpText(varnamecomp, out ht, out cat, out subcat), false, 0, 0, 0, 0, "Missing in compare", "", 0, shtest.Symbol_number, shtest.Userdescription, false, true);
                                    }
                                }
                            }

                            tabdet.OriginalSymbolCollection = m_symbols;
                            tabdet.OriginalFilename = m_currentfile;
                            tabdet.CompareFilename = filename;
                            tabdet.CompareSymbolCollection = compare_symbols;
                            tabdet.OpenGridViewGroups(tabdet.gridControl1, 1);
                            tabdet.gridControl1.DataSource = dt.Copy();
                            SetProgressIdle();
                        }
                    }
                    catch (Exception E)
                    {
                        logger.Debug(E.Message);
                    }
                    dockManager1.EndUpdate();
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Meindert66/T8SuitePro
        private void barButtonItem23_ItemClick(object sender, ItemClickEventArgs e)
        {
            // ask the user for which value to search and if searching should include symbolnames and/or symbol description
            if (m_currentfile != "")
            {
                SymbolCollection result_Collection = new SymbolCollection();
                frmSearchMaps searchoptions = new frmSearchMaps();
                if (searchoptions.ShowDialog() == DialogResult.OK)
                {

                    SetProgress("Start searching data...");
                    SetProgressPercentage(0);

                    System.Windows.Forms.Application.DoEvents();
                    int cnt = 0;
                    SetProgress("Searching...");
                    foreach (SymbolHelper sh in m_symbols)
                    {

                        SetProgressPercentage((cnt * 100) / m_symbols.Count);
                        bool hit_found = false;
                        if (searchoptions.UseSpecificMapLength)
                        {
                            if (sh.Length != (int)searchoptions.MapLength)
                            {
                                continue;
                            }
                        }
                        if (searchoptions.IncludeSymbolNames)
                        {
                            if (searchoptions.SearchForNumericValues)
                            {
                                if (sh.Varname.Contains(searchoptions.NumericValueToSearchFor.ToString()))
                                {
                                    hit_found = true;
                                }
                            }
                            if (searchoptions.SearchForStringValues)
                            {
                                if (searchoptions.StringValueToSearchFor != string.Empty)
                                {
                                    if (sh.Varname.Contains(searchoptions.StringValueToSearchFor))
                                    {
                                        hit_found = true;
                                    }
                                }
                            }
                        }
                        if (searchoptions.IncludeSymbolDescription)
                        {
                            if (searchoptions.SearchForNumericValues)
                            {
                                if (sh.Description.Contains(searchoptions.NumericValueToSearchFor.ToString()))
                                {
                                    hit_found = true;
                                }
                            }
                            if (searchoptions.SearchForStringValues)
                            {
                                if (searchoptions.StringValueToSearchFor != string.Empty)
                                {
                                    if (sh.Description.Contains(searchoptions.StringValueToSearchFor))
                                    {
                                        hit_found = true;
                                    }
                                }
                            }
                        }
                        // now search the symbol data
                        if (sh.Flash_start_address < m_currentfile_size)
                        {
                            byte[] symboldata = readdatafromfile(m_currentfile, (int)sh.Flash_start_address, sh.Length);
                            if (searchoptions.SearchForNumericValues)
                            {
                                if (isSixteenBitTable(sh.Varname))
                                {
                                    for (int i = 0; i < symboldata.Length / 2; i += 2)
                                    {
                                        float value = Convert.ToInt32(symboldata.GetValue(i)) * 256;
                                        value += Convert.ToInt32(symboldata.GetValue(i + 1));
                                        value *= (float)GetMapCorrectionFactor(sh.Varname);
                                        value += (float)GetMapCorrectionOffset(sh.Varname);
                                        if (value == (float)searchoptions.NumericValueToSearchFor)
                                        {
                                            hit_found = true;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < symboldata.Length; i++)
                                    {
                                        float value = Convert.ToInt32(symboldata.GetValue(i));
                                        value *= (float)GetMapCorrectionFactor(sh.Varname);
                                        value += (float)GetMapCorrectionOffset(sh.Varname);
                                        if (value == (float)searchoptions.NumericValueToSearchFor)
                                        {
                                            hit_found = true;
                                        }
                                    }
                                }
                            }
                            if (searchoptions.SearchForStringValues)
                            {
                                if (searchoptions.StringValueToSearchFor.Length > symboldata.Length)
                                {
                                    // possible...
                                    string symboldataasstring = System.Text.Encoding.ASCII.GetString(symboldata);
                                    if (symboldataasstring.Contains(searchoptions.StringValueToSearchFor))
                                    {
                                        hit_found = true;
                                    }
                                }
                            }
                        }

                        if (hit_found)
                        {
                            // add to collection
                            result_Collection.Add(sh);
                        }
                        cnt++;
                    }
                    SetProgressIdle();
                    if (result_Collection.Count == 0)
                    {
                        MessageBox.Show("No results found...");
                    }
                    else
                    {
                        // start result screen
                        dockManager1.BeginUpdate();
                        try
                        {
                            SymbolTranslator st = new SymbolTranslator();
                            DockPanel dockPanel = dockManager1.AddPanel(new System.Drawing.Point(-500, -500));
                            CompareResults tabdet = new CompareResults();
                            tabdet.ShowAddressesInHex = m_appSettings.ShowAddressesInHex;
                            tabdet.SetFilterMode(m_appSettings.ShowAddressesInHex);
                            tabdet.Dock = DockStyle.Fill;
                            tabdet.UseForFind = true;
                            tabdet.Filename = openFileDialog1.FileName;
                            tabdet.onSymbolSelect += new CompareResults.NotifySelectSymbol(tabdet_onSymbolSelectForFind);
                            dockPanel.Controls.Add(tabdet);
                            string resultText = "Search results: ";
                            if (searchoptions.SearchForNumericValues)
                            {
                                resultText += " number " + searchoptions.NumericValueToSearchFor.ToString();
                            }
                            if (searchoptions.SearchForStringValues)
                            {
                                resultText += " string " + searchoptions.StringValueToSearchFor;
                            }
                            dockPanel.Text = resultText;

                            dockPanel.DockTo(dockManager1, DockingStyle.Left, 1);

                            dockPanel.Width = 700;

                            System.Data.DataTable dt = new System.Data.DataTable();
                            dt.Columns.Add("SYMBOLNAME");
                            dt.Columns.Add("SRAMADDRESS", Type.GetType("System.Int32"));
                            dt.Columns.Add("FLASHADDRESS", Type.GetType("System.Int32"));
                            dt.Columns.Add("LENGTHBYTES", Type.GetType("System.Int32"));
                            dt.Columns.Add("LENGTHVALUES", Type.GetType("System.Int32"));
                            dt.Columns.Add("DESCRIPTION");
                            dt.Columns.Add("ISCHANGED", Type.GetType("System.Boolean"));
                            dt.Columns.Add("CATEGORY"); //0
                            dt.Columns.Add("DIFFPERCENTAGE", Type.GetType("System.Double"));
                            dt.Columns.Add("DIFFABSOLUTE", Type.GetType("System.Int32"));
                            dt.Columns.Add("DIFFAVERAGE", Type.GetType("System.Double"));
                            dt.Columns.Add("CATEGORYNAME");
                            dt.Columns.Add("SUBCATEGORYNAME");
                            dt.Columns.Add("SymbolNumber1", Type.GetType("System.Int32"));
                            dt.Columns.Add("SymbolNumber2", Type.GetType("System.Int32"));
                            string category = "";
                            string ht = string.Empty;
                            double diffperc = 0;
                            int diffabs = 0;
                            double diffavg = 0;
                            XDFCategories cat = XDFCategories.Undocumented;
                            XDFSubCategory subcat = XDFSubCategory.Undocumented;
                            foreach (SymbolHelper shfound in result_Collection)
                            {
                                string helptext = st.TranslateSymbolToHelpText(shfound.Varname, out ht, out cat, out subcat);
                                shfound.createAndUpdateCategory(shfound.SmartVarname);
                                dt.Rows.Add(shfound.SmartVarname, shfound.Start_address, shfound.Flash_start_address, shfound.Length, shfound.Length, helptext, false, 0, 0, 0, 0, shfound.Category, "", shfound.Symbol_number, shfound.Symbol_number);
                            }
                            tabdet.CompareSymbolCollection = result_Collection;
                            tabdet.OpenGridViewGroups(tabdet.gridControl1, 1);
                            tabdet.gridControl1.DataSource = dt.Copy();

                        }
                        catch (Exception E)
                        {
                            logger.Debug(E.Message);
                        }
                        dockManager1.EndUpdate();

                    }

                }
            }
        }