private void tR2MergerToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "tr2 database (.tr2)|*.tr2"; ofd.ShowDialog(); if ((ofd.FileName != "") && (ofd.FileName != null)) { TR2 filler = new TR2(ofd.FileName); DataGridView fillerView = new DataGridView(); fillerView.Rows.Clear(); fillerView.Columns.Clear(); // Adding header column DataGridViewTextBoxColumn headColumn = new DataGridViewTextBoxColumn(); headColumn.Name = filler.fileName; fillerView.Columns.Add(headColumn); // Adding dynamic columns for (int i = 0; i < filler.columnNum; i++) { DataGridViewTextBoxColumn currColumn = new DataGridViewTextBoxColumn(); if (filler.columnsList[i].dataLenght == filler.columnsList[i].singleDataLenght) { currColumn.ValueType = Type.GetType(filler.columnsList[i].dataType); } else { currColumn.ValueType = "".GetType(); } currColumn.Name = filler.columnsList[i].name; fillerView.Columns.Add(currColumn); } // Adding Rows for (int i = 0; i < filler.rowNum; i++) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell[] cells = new DataGridViewTextBoxCell[filler.columnNum + 1]; cells[0] = new DataGridViewTextBoxCell(); cells[0].Value = filler.rowHeaderValues[i]; for (int j = 1; j <= filler.columnNum; j++) { cells[j] = new DataGridViewTextBoxCell(); if (filler.columnsList[j - 1].dataLenght != filler.columnsList[j - 1].singleDataLenght) { int doneTot = 0; string currValue = ""; byte[] dataBuffer = (byte[])filler.columnsList[j - 1].data[i]; if (dataBuffer != null) { while (doneTot != dataBuffer.Length) { byte[] valueBuffer = new byte[filler.columnsList[j - 1].singleDataLenght]; Buffer.BlockCopy(dataBuffer, doneTot, valueBuffer, 0, valueBuffer.Length); currValue += TR2Utils.ConvertNumber(valueBuffer); doneTot += valueBuffer.Length; if (doneTot != filler.columnsList[j - 1].dataLenght) { currValue += " | "; } } } else { currValue = null; } cells[j].Value = currValue; } else { cells[j].Value = filler.columnsList[j - 1].data[i]; } } row.Cells.AddRange(cells); fillerView.Rows.Add(row); } // Checking Fillers for (int i = 0; i < dataTable.Rows.Count; i++) { for (int index = 0; index < fillerView.Rows.Count - 1; index++) { if (fillerView.Rows[index].Cells[0].Value.Equals(dataTable.Rows[i].Cells[0].Value)) { for (int j = 0; j < fillerView.Rows[index].Cells.Count; j++) { dataTable.Rows[i].Cells[j].Value = fillerView.Rows[index].Cells[j].Value; } break; } } } } }
public void OpenTR2(string TR2fileName) { tr2Path = TR2fileName; loadedTR2 = new TR2(tr2Path); // Adding header column DataGridViewTextBoxColumn headColumn = new DataGridViewTextBoxColumn(); headColumn.ValueType = Type.GetType("System.Int32"); headColumn.Name = loadedTR2.fileName; dataTable.Columns.Add(headColumn); columnListBox.Items.Add(loadedTR2.fileName); // Adding dynamic columns for (int i = 0; i < loadedTR2.columnNum; i++) { DataGridViewTextBoxColumn currColumn = new DataGridViewTextBoxColumn(); if (loadedTR2.columnsList[i].dataLenght == loadedTR2.columnsList[i].singleDataLenght) { int int8 = 0; Int16 int16 = 0; Int32 int32 = 0; UInt16 uint16 = 0; switch (loadedTR2.columnsList[i].dataType.ToLower()) { case "int8": currColumn.ValueType = int8.GetType(); break; case "uint8": currColumn.ValueType = int8.GetType(); break; case "int16": currColumn.ValueType = int16.GetType(); break; case "uint16": currColumn.ValueType = uint16.GetType(); break; case "int32": currColumn.ValueType = int32.GetType(); break; case "utf-8": currColumn.ValueType = "".GetType(); break; case "ascii": currColumn.ValueType = "".GetType(); break; default: currColumn.ValueType = Type.GetType(loadedTR2.columnsList[i].dataType); break; } } else { currColumn.ValueType = "".GetType(); } currColumn.Name = loadedTR2.columnsList[i].name; dataTable.Columns.Add(currColumn); columnListBox.Items.Add(currColumn.Name); } columnListBox.SelectedIndex = 0; // Adding Rows for (int i = 0; i < loadedTR2.rowNum; i++) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell[] cells = new DataGridViewTextBoxCell[loadedTR2.columnNum + 1]; cells[0] = new DataGridViewTextBoxCell(); cells[0].Value = loadedTR2.rowHeaderValues[i]; for (int j = 1; j <= loadedTR2.columnNum; j++) { cells[j] = new DataGridViewTextBoxCell(); if (loadedTR2.columnsList[j - 1].dataLenght != loadedTR2.columnsList[j - 1].singleDataLenght) { int doneTot = 0; string currValue = ""; byte[] dataBuffer = (byte[])loadedTR2.columnsList[j - 1].data[i]; if (dataBuffer != null) { while (doneTot != dataBuffer.Length) { byte[] valueBuffer = new byte[loadedTR2.columnsList[j - 1].singleDataLenght]; Buffer.BlockCopy(dataBuffer, doneTot, valueBuffer, 0, valueBuffer.Length); currValue += TR2Utils.ConvertNumber(valueBuffer); doneTot += valueBuffer.Length; if (doneTot != dataBuffer.Length) { currValue += " | "; } } } else { currValue = null; } cells[j].Value = currValue; } else { if (loadedTR2.columnsList[j - 1].dataLenght == -1) { string laStringa = (string)loadedTR2.columnsList[j - 1].data[i]; cells[j].Value = laStringa.Replace("\n", "\\n"); } else { cells[j].Value = loadedTR2.columnsList[j - 1].data[i]; } } } row.Cells.AddRange(cells); dataTable.Rows.Add(row); } }