示例#1
0
        private void compareTable(PcmFile cmpPCM)
        {
            int id = findTableDataId(td, cmpPCM.tableDatas);

            if (id < 0)
            {
                Logger("Table not found");
                return;
            }
            TableData cmpTd = cmpPCM.tableDatas[id];
            int       row   = dataGridView1.Rows.Add();

            dataGridView1.Rows[row].HeaderCell.Value       = cmpPCM.FileName;
            dataGridView1.Rows[row].Cells["OS"].Value      = cmpPCM.OS;
            dataGridView1.Rows[row].Cells["Segment"].Value = cmpPCM.GetSegmentName(cmpTd.addrInt);
            int segNr = cmpPCM.GetSegmentNumber(cmpTd.addrInt);

            if (segNr > -1)
            {
                dataGridView1.Rows[row].Cells["PN"].Value    = cmpPCM.segmentinfos[segNr].PN;
                dataGridView1.Rows[row].Cells["Stock"].Value = cmpPCM.segmentinfos[segNr].Stock;
            }
            dataGridView1.Rows[row].Cells["Table Name"].Value    = cmpTd.TableName;
            dataGridView1.Rows[row].Cells["Table Address"].Value = cmpTd.Address;
            dataGridView1.Rows[row].Cells["Current Value"].Value = peekTableValues(id, cmpPCM);
            //dataGridView1.Rows[row].Height = 50;
        }
示例#2
0
        public string exportXdf(PcmFile basefile, List <TableData> tdList1)
        {
            PCM    = basefile;
            tdList = tdList1;
            string        retVal       = "";
            string        tableRows    = "";
            String        tableText    = "";
            string        templateTxt  = "";
            int           lastCategory = 0;
            int           dtcCategory  = 0;
            int           uniqId       = 0x100;
            List <int>    uniqIds      = new List <int>();
            List <string> tableNames   = new List <string>(); //Store constant id/name for later use

            try
            {
                string fName   = Path.Combine(Application.StartupPath, "Templates", "xdfheader.txt");
                string xdfText = ReadTextFile(fName);
                xdfText = xdfText.Replace("REPLACE-TIMESTAMP", DateTime.Today.ToString("MM/dd/yyyy H:mm"));
                xdfText = xdfText.Replace("REPLACE-OSID", basefile.OS);
                xdfText = xdfText.Replace("REPLACE-BINSIZE", basefile.fsize.ToString("X"));
                for (int s = 1; s < basefile.tableCategories.Count; s++)
                {
                    tableText   += "     <CATEGORY index = \"0x" + (s - 1).ToString("X") + "\" name = \"" + basefile.tableCategories[s] + "\" />" + Environment.NewLine;
                    lastCategory = s;
                }
                dtcCategory  = lastCategory + 1;
                tableText   += "     <CATEGORY index = \"0x" + (dtcCategory - 1).ToString("X") + "\" name = \"DTC\" />" + Environment.NewLine;
                lastCategory = dtcCategory + 1;
                tableText   += "     <CATEGORY index = \"0x" + (lastCategory - 1).ToString("X") + "\" name = \"Other\" />";
                xdfText      = xdfText.Replace("REPLACE-CATEGORYNAME", tableText) + Environment.NewLine;

                fName    = Path.Combine(Application.StartupPath, "Templates", basefile.configFile + "-checksum.txt");
                xdfText += ReadTextFile(fName);


                //Add OS ID:
                fName       = Path.Combine(Application.StartupPath, "Templates", "xdfconstant.txt");
                templateTxt = ReadTextFile(fName);
                tableText   = templateTxt.Replace("REPLACE-TABLEID", uniqId.ToString("X"));
                uniqId++;
                tableText = tableText.Replace("REPLACE-LINKMATH", "");
                tableText = tableText.Replace("REPLACE-MATH", "x");

                tableText = tableText.Replace("REPLACE-TABLEDESCRIPTION", "DON&apos;T MODIFY");
                tableText = tableText.Replace("REPLACE-TABLETITLE", "OS ID - Don&apos;t modify, must match XDF!");
                tableText = tableText.Replace("REPLACE-BITS", "32");
                tableText = tableText.Replace("REPLACE-MINVALUE", basefile.OS);
                tableText = tableText.Replace("REPLACE-MAXVALUE", basefile.OS);
                tableText = tableText.Replace("REPLACE-TABLEADDRESS", basefile.segmentAddressDatas[basefile.OSSegment].PNaddr.Address.ToString("X"));
                tableText = tableText.Replace("REPLACE-CATEGORY", (basefile.OSSegment + 1).ToString("X"));
                xdfText  += tableText;

                fName       = Path.Combine(Application.StartupPath, "Templates", "xdfconstant.txt");
                templateTxt = ReadTextFile(fName);
                for (int t = 0; t < tdList.Count; t++)
                {
                    //Add all constants
                    if (tdList[t].Rows < 2 && tdList[t].OutputType != OutDataType.Flag)
                    {
                        string tableName = tdList[t].TableName.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;");;
                        if (tdList[t].TableName == null || tdList[t].TableName.Length == 0)
                        {
                            tableName = tdList[t].Address;
                        }
                        tableText = templateTxt.Replace("REPLACE-TABLETITLE", tableName);
                        int s = basefile.GetSegmentNumber(tdList[t].addrInt);
                        if (s == -1)
                        {
                            s = lastCategory;
                        }
                        tableText = tableText.Replace("REPLACE-CATEGORY", (s + 1).ToString("X"));
                        tableText = tableText.Replace("REPLACE-TABLEID", uniqId.ToString("X"));
                        uniqIds.Add(uniqId);
                        tableNames.Add(tdList[t].TableName.ToLower());
                        uniqId++;

                        string linkTxt = "";
                        string mathTxt = tdList[t].Math.ToLower();
                        if (mathTxt.Contains("raw:"))
                        {
                            mathTxt = linkConversionRaw(mathTxt, out linkTxt);
                        }
                        tableText = tableText.Replace("REPLACE-LINKMATH", linkTxt);
                        tableText = tableText.Replace("REPLACE-MATH", mathTxt);

                        tableText = tableText.Replace("REPLACE-TABLEADDRESS", ((uint)(tdList[t].addrInt + tdList[t].Offset)).ToString("X"));
                        string descr = tdList[t].TableDescription.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;");
                        tableText = tableText.Replace("REPLACE-TABLEDESCRIPTION", descr);
                        tableText = tableText.Replace("REPLACE-BITS", getBits(tdList[t].DataType).ToString());
                        tableText = tableText.Replace("REPLACE-MINVALUE", tdList[t].Min.ToString());
                        tableText = tableText.Replace("REPLACE-MAXVALUE", tdList[t].Max.ToString());
                        xdfText  += tableText;      //Add generated table to end of xdfText
                    }
                }


                fName       = Path.Combine(Application.StartupPath, "Templates", "xdftable.txt");
                templateTxt = ReadTextFile(fName);
                for (int t = 0; t < tdList.Count; t++)
                {
                    //Add all tables
                    if (tdList[t].Rows > 1)
                    {
                        string tableName = tdList[t].TableName.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;");
                        if (tdList[t].TableName == null || tdList[t].TableName.Length == 0)
                        {
                            tableName = tdList[t].Address;
                        }
                        tableText = templateTxt.Replace("REPLACE-TABLETITLE", tableName);
                        int s = basefile.GetSegmentNumber(tdList[t].addrInt);
                        if (s == -1)
                        {
                            s = lastCategory;
                        }
                        if (tdList[t].Category != null && tdList[t].Category != "")
                        {
                            for (int c = 1; c < PCM.tableCategories.Count; c++)
                            {
                                if (PCM.tableCategories[c] == tdList[t].Category)
                                {
                                    tableText = tableText.Replace("REPLACE-CATEGORY", c.ToString());
                                    break;
                                }
                            }
                        }
                        else
                        {
                            tableText = tableText.Replace("REPLACE-CATEGORY", s.ToString());
                        }

                        /*if (tdList[t].Values.StartsWith("Enum: ") && !descr.ToLower().Contains("enum"))
                         * {
                         *  string[] hParts = tdList[t].Values.Substring(6).Split(',');
                         *  for (int x = 0; x < hParts.Length; x++)
                         *  {
                         *      descr += Environment.NewLine + hParts[x];
                         *  }
                         * }*/

                        string linkTxt = "";
                        string mathTxt = tdList[t].Math.ToLower();
                        if (mathTxt.Contains("table:"))
                        {
                            mathTxt = linkConversionTable(mathTxt, uniqIds, tableNames, out linkTxt);
                        }
                        if (mathTxt.Contains("raw:"))
                        {
                            string tmpTxt = "";
                            mathTxt  = linkConversionRaw(mathTxt, out tmpTxt);
                            linkTxt += tmpTxt;
                        }
                        tableText = tableText.Replace("REPLACE-LINKMATH", linkTxt);
                        tableText = tableText.Replace("REPLACE-MATH", mathTxt);

                        tableText = tableText.Replace("REPLACE-TABLEID", uniqId.ToString("X"));
                        uniqId++;
                        tableText = tableText.Replace("REPLACE-UNITS", tdList[t].Units);
                        tableText = tableText.Replace("REPLACE-ROWCOUNT", tdList[t].Rows.ToString());
                        tableText = tableText.Replace("REPLACE-COLCOUNT", tdList[t].Columns.ToString());
                        tableText = tableText.Replace("REPLACE-BITS", getBits(tdList[t].DataType).ToString());
                        tableText = tableText.Replace("REPLACE-DECIMALS", tdList[t].Decimals.ToString());
                        tableText = tableText.Replace("REPLACE-OUTPUTTYPE", ((ushort)tdList[t].OutputType).ToString());
                        tableText = tableText.Replace("REPLACE-TABLEADDRESS", ((uint)(tdList[t].addrInt + tdList[t].Offset)).ToString("X"));
                        string descr = tdList[t].TableDescription.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;");
                        tableText = tableText.Replace("REPLACE-TABLEDESCRIPTION", descr);
                        tableText = tableText.Replace("REPLACE-MINVALUE", tdList[t].Min.ToString());
                        tableText = tableText.Replace("REPLACE-MAXVALUE", tdList[t].Max.ToString());
                        int tableFlags = 0;
                        if (getSigned(tdList[t].DataType))
                        {
                            tableFlags++;
                        }
                        if (tdList[t].RowMajor == false)
                        {
                            tableFlags += 4;
                        }
                        tableText = tableText.Replace("REPLACE-TYPEFLAGS", tableFlags.ToString("X2"));

                        tableRows = "";
                        if (tdList[t].RowHeaders == "")
                        {
                            for (int d = 0; d < tdList[t].Rows; d++)
                            {
                                tableRows += "     <LABEL index=\"" + d.ToString() + "\" value=\"" + d.ToString() + "\" />";
                                if (d < tdList[t].Rows - 1)
                                {
                                    tableRows += Environment.NewLine;
                                }
                            }
                        }
                        else
                        {
                            string[] hParts = tdList[t].RowHeaders.Split(',');
                            for (int row = 0; row < hParts.Length; row++)
                            {
                                tableRows += "     <LABEL index=\"" + row.ToString() + "\" value=\"" + hParts[row] + "\" />";
                                if (row < hParts.Length - 1)
                                {
                                    tableRows += Environment.NewLine;
                                }
                            }
                        }
                        tableText = tableText.Replace("REPLACE-TABLEROWS", tableRows);
                        string tableCols = "";
                        if (tdList[t].ColumnHeaders == "")
                        {
                            for (int d = 0; d < tdList[t].Columns; d++)
                            {
                                tableCols += "     <LABEL index=\"" + d.ToString() + "\" value=\"" + d.ToString() + "\" />";
                                if (d < tdList[t].Columns - 1)
                                {
                                    tableCols += Environment.NewLine;
                                }
                            }
                        }
                        else
                        {
                            string[] hParts = tdList[t].ColumnHeaders.Split(',');
                            for (int col = 0; col < hParts.Length; col++)
                            {
                                tableCols += "     <LABEL index=\"" + col.ToString() + "\" value=\"" + hParts[col] + "\" />";
                                if (col < hParts.Length - 1)
                                {
                                    tableCols += Environment.NewLine;
                                }
                            }
                        }
                        tableText = tableText.Replace("REPLACE-TABLECOLS", tableCols);

                        xdfText += tableText;       //Add generated table to end of xdfText
                    }
                }


                fName       = Path.Combine(Application.StartupPath, "Templates", "xdfFlag.txt");
                templateTxt = ReadTextFile(fName);
                for (int t = 0; t < tdList.Count; t++)
                {
                    //Add all constants
                    if (tdList[t].OutputType == OutDataType.Flag)
                    {
                        string tableName = tdList[t].TableName.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;");
                        if (tdList[t].TableName == null || tdList[t].TableName.Length == 0)
                        {
                            tableName = tdList[t].Address;
                        }
                        tableText = templateTxt.Replace("REPLACE-TABLETITLE", tableName);
                        int s = basefile.GetSegmentNumber(tdList[t].addrInt);
                        if (s == -1)
                        {
                            s = lastCategory;
                        }
                        tableText = tableText.Replace("REPLACE-CATEGORY", (s + 1).ToString("X"));
                        tableText = tableText.Replace("REPLACE-TABLEID", uniqId.ToString("X"));
                        uniqId++;
                        tableText = tableText.Replace("REPLACE-TABLEADDRESS", ((uint)(tdList[t].addrInt + tdList[t].Offset)).ToString("X"));
                        tableText = tableText.Replace("REPLACE-TABLEDESCRIPTION", "");
                        tableText = tableText.Replace("REPLACE-BITS", getBits(tdList[t].DataType).ToString());
                        tableText = tableText.Replace("REPLACE-MINVALUE", tdList[t].Min.ToString());
                        tableText = tableText.Replace("REPLACE-MAXVALUE", tdList[t].Max.ToString());
                        tableText = tableText.Replace("REPLACE-MASK", tdList[t].BitMask);
                        xdfText  += tableText;      //Add generated table to end of xdfText
                    }
                }

                xdfText += "</XDFFORMAT>" + Environment.NewLine;
                string defFname = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Tunerpro Files", "Bin Definitions", basefile.OS + "-generated.xdf");
                string fileName = SelectSaveFile("XDF Files(*.xdf)|*.xdf|ALL Files (*.*)|*.*", defFname);
                if (fileName.Length == 0)
                {
                    return("");
                }
                retVal += "Writing to file: " + Path.GetFileName(fileName);
                WriteTextFile(fileName, xdfText);
                retVal += " [OK]";
            }
            catch (Exception ex)
            {
                var st = new StackTrace(ex, true);
                // Get the top stack frame
                var frame = st.GetFrame(st.FrameCount - 1);
                // Get the line number from the stack frame
                var line = frame.GetFileLineNumber();
                retVal += ("Export XDF, line " + line + ": " + ex.Message);
            }
            return(retVal);
        }