/// <summary> /// Reads a v2 type DB (r748), by FemShep. Returns list of read entries. /// Contains the following columns: /// Plot ID /// Type (as int) /// Game (as int) /// Category1 (as string) /// Category2 (as string) /// State/Value (as string) /// Broken (as bool (stored as byte)) /// ME2 ID (as int) /// ME3 ID (as int) /// Notes (as string) /// </summary> /// <param name="fs">Filestream advanced past the version indicator</param> private List <PlotVarEntry> readVersion2DB(FileStream fs) { PlotVarEntry p; entries = new List <PlotVarEntry>(); int count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.id = ReadInt(fs); p.type = ReadInt(fs); p.game = ReadInt(fs); p.category1 = ReadString(fs); p.state = ReadString(fs); p.broken = ReadBool(fs); p.me2id = ReadInt(fs); p.me3id = ReadInt(fs); p.notes = ReadString(fs); entries.Add(p); } return(entries); }
private void commitTable() { //Commit the current edit to the table if (plotVarTable.IsCurrentCellDirty) { plotVarTable.CommitEdit(DataGridViewDataErrorContexts.Commit); } List <PlotVarEntry> commitingEntries = new List <PlotVarEntry>(); foreach (DataGridViewRow row in plotVarTable.Rows) { if ((string)row.Cells[COL_PLOTID].Value != null && ((string)row.Cells[COL_PLOTID].Value).Trim() != "") { PlotVarEntry pve = new PlotVarEntry(); pve.id = Convert.ToInt32((string)row.Cells[COL_PLOTID].Value); pve.type = StringToType((string)row.Cells[COL_VARTYPE].Value); pve.game = StringToGame((string)row.Cells[COL_GAME].Value); pve.category1 = row.Cells[COL_CATEGORY1].Value != null ? row.Cells[COL_CATEGORY1].Value.ToString() : ""; pve.state = row.Cells[COL_STATE].Value != null ? row.Cells[COL_STATE].Value.ToString() : ""; object broken = row.Cells[COL_BROKEN].Value; pve.broken = Convert.ToBoolean(broken); pve.me2id = row.Cells[COL_ME2SPEC].Value != null && !row.Cells[COL_ME2SPEC].Value.Equals("") ? Convert.ToInt32(row.Cells[COL_ME2SPEC].Value.ToString()) : 0; pve.me3id = row.Cells[COL_ME3SPEC].Value != null && !row.Cells[COL_ME3SPEC].Value.Equals("") ? Convert.ToInt32(row.Cells[COL_ME3SPEC].Value.ToString()) : 0; pve.notes = row.Cells[COL_NOTES].Value != null ? row.Cells[COL_NOTES].Value.ToString() : ""; commitingEntries.Add(pve); } } entries = commitingEntries; }
/// <summary> /// Reads the old style DB files from Pre-r748. /// Contains the following columns: /// ID (as int) /// Type (as int) /// Desc (as string) /// This file format has a different layout than v2 and up. /// </summary> /// <param name="fs">Filestream at the start of a v1 file</param> /// <returns>List of imported entries. Desc is mapped to the state column.</returns> private List <PlotVarEntry> readVersion1DB(FileStream fs) { PlotVarEntry p; entries = new List <PlotVarEntry>(); int count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.id = ReadInt(fs); p.type = ReadInt(fs); string desc = ReadString(fs); p.category1 = Regex.Match(desc, @"\[(.*?)\]").Groups[1].Value; p.state = desc.Substring(p.category1.Length > 0 ? p.category1.Length + 2 : 0).Trim(); p.game = GAME_ME1; p.broken = false; entries.Add(p); } count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.id = ReadInt(fs); p.type = ReadInt(fs); string desc = ReadString(fs); p.category1 = Regex.Match(desc, @"\[(.*?)\]").Groups[1].Value; p.state = desc.Substring(p.category1.Length > 0 ? p.category1.Length + 2 : 0).Trim(); p.game = GAME_ME2; p.broken = false; entries.Add(p); } count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.id = ReadInt(fs); p.type = ReadInt(fs); string desc = ReadString(fs); p.category1 = Regex.Match(desc, @"\[(.*?)\]").Groups[1].Value; p.state = desc.Substring(p.category1.Length > 0 ? p.category1.Length + 2 : 0).Trim(); p.game = GAME_ME3; p.broken = false; entries.Add(p); } return(entries); }
private void loadDatabaseToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.db|*.db"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FileStream fs = new FileStream(d.FileName, FileMode.Open, FileAccess.Read); BitConverter.IsLittleEndian = true; PlotVarEntry p; database = new DataBaseType(); database.ME1 = new List <PlotVarEntry>(); database.ME2 = new List <PlotVarEntry>(); database.ME3 = new List <PlotVarEntry>(); int count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.ID = ReadInt(fs); p.type = ReadInt(fs); p.Desc = ReadString(fs); database.ME1.Add(p); } count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.ID = ReadInt(fs); p.type = ReadInt(fs); p.Desc = ReadString(fs); database.ME2.Add(p); } count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.ID = ReadInt(fs); p.type = ReadInt(fs); p.Desc = ReadString(fs); database.ME3.Add(p); } fs.Close(); RefreshLists(); MessageBox.Show("Done."); } }
private void editToolStripMenuItem1_Click(object sender, EventArgs e) { int n = listBox1.SelectedIndex; if (n == -1) { return; } PlotVarEntry entry = new PlotVarEntry(); switch (MEVersion) { case 0: entry = database.ME1[n]; break; case 1: entry = database.ME2[n]; break; case 2: entry = database.ME3[n]; break; } PlotVarEditor ed = new PlotVarEditor(); ed.MdiParent = this.MdiParent; ed.Show(); ed.rtb1.Text = "{" + entry.ID + ", \"" + TypeToString(entry.type) + "\", \"" + entry.Desc + "\"};"; ed.WindowState = FormWindowState.Maximized; ed.parent = this; ed.version = MEVersion; ed.index = n; ed.toolStripButton1.Visible = false; ed.toolStripButton2.Visible = true; }
private void editToolStripMenuItem1_Click(object sender, EventArgs e) { int n = listBox1.SelectedIndex; if (n == -1) return; PlotVarEntry entry = new PlotVarEntry(); switch (MEVersion) { case 0: entry = database.ME1[n]; break; case 1: entry = database.ME2[n]; break; case 2: entry = database.ME3[n]; break; } PlotVarEditor ed = new PlotVarEditor(); ed.MdiParent = this.MdiParent; ed.Show(); ed.rtb1.Text = "{" + entry.ID + ", \"" + TypeToString(entry.type) + "\", \"" + entry.Desc + "\"};"; ed.WindowState = FormWindowState.Maximized; ed.parent = this; ed.version = MEVersion; ed.index = n; ed.toolStripButton1.Visible = false; ed.toolStripButton2.Visible = true; }
private void loadDatabaseToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.db|*.db"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FileStream fs = new FileStream(d.FileName, FileMode.Open, FileAccess.Read); BitConverter.IsLittleEndian = true; PlotVarEntry p; database = new DataBaseType(); database.ME1 = new List<PlotVarEntry>(); database.ME2 = new List<PlotVarEntry>(); database.ME3 = new List<PlotVarEntry>(); int count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.ID = ReadInt(fs); p.type = ReadInt(fs); p.Desc = ReadString(fs); database.ME1.Add(p); } count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.ID = ReadInt(fs); p.type = ReadInt(fs); p.Desc = ReadString(fs); database.ME2.Add(p); } count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.ID = ReadInt(fs); p.type = ReadInt(fs); p.Desc = ReadString(fs); database.ME3.Add(p); } fs.Close(); RefreshLists(); MessageBox.Show("Done."); } }
private void importFromCSVToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.csv|*.csv"; if (d.ShowDialog() == DialogResult.OK) { commitTable(); System.IO.StreamReader stringreader = new System.IO.StreamReader(d.FileName); var csv = new CsvReader(stringreader); var item = csv.GetRecords<PlotVarEntry>(); List<PlotVarEntry> importingEntries = new List<PlotVarEntry>(); while (csv.Read()) { PlotVarEntry p = new PlotVarEntry(); p.id = csv.GetField<int>(COL_PLOTID); p.type = CSVStringToType(csv.GetField<string>(COL_VARTYPE)); p.game = csv.GetField<int>(COL_GAME); p.category1 = csv.GetField<string>(COL_CATEGORY1); p.category2 = csv.GetField<string>(COL_CATEGORY2); p.state = csv.GetField<string>(COL_STATE); p.broken = csv.GetField<bool>(COL_BROKEN); p.me2id = csv.GetField<int>(COL_ME2SPEC); p.me3id = csv.GetField<int>(COL_ME3SPEC); p.notes = csv.GetField<string>(COL_NOTES); importingEntries.Add(p); } //csv.GetRecords<PlotVarEntry>().ToList(); stringreader.Close(); //import int recordsImported = 0, recordsUpdated = 0; foreach (PlotVarEntry pve in importingEntries) { bool import = true; foreach (PlotVarEntry ent in entries) { if (ent.id == pve.id && ent.game == pve.game) { import = false; bool recordUpdated = false; //same entry, merge empty values //vartype if (ent.type != pve.type) { ent.type = pve.type; recordUpdated = true; } //broken if (ent.broken != pve.broken) { ent.broken = pve.broken; recordUpdated = true; } //me2 if (ent.me2id != pve.me2id) { ent.me2id = pve.me2id; recordUpdated = true; } //me3id if (ent.me3id != pve.me3id) { ent.me3id = pve.me3id; recordUpdated = true; } //category if (ent.category1 == null || ent.category1.Equals("")) { ent.category1 = pve.category1; recordUpdated = true; } //state if (ent.state == null || ent.state.Equals("")) { ent.state = pve.state; recordUpdated = true; } //notes if (ent.notes == null || ent.notes.Equals("")) { ent.notes = pve.notes; recordUpdated = true; } if (recordUpdated) { recordsUpdated++; } } } if (import) { recordsImported++; entries.Add(pve); } } RefreshTable(); status.Text = "Imported from CSV into DB: " + d.FileName + " | " + recordsImported + " records imported | " + recordsUpdated + " records upated"; } }
/// <summary> /// Reads the old style DB files from Pre-r748. /// Contains the following columns: /// ID (as int) /// Type (as int) /// Desc (as string) /// This file format has a different layout than v2 and up. /// </summary> /// <param name="fs">Filestream at the start of a v1 file</param> /// <returns>List of imported entries. Desc is mapped to the state column.</returns> private List<PlotVarEntry> readVersion1DB(FileStream fs) { PlotVarEntry p; entries = new List<PlotVarEntry>(); int count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.id = ReadInt(fs); p.type = ReadInt(fs); string desc = ReadString(fs); p.category1 = Regex.Match(desc, @"\[(.*?)\]").Groups[1].Value; p.state = desc.Substring(p.category1.Length > 0 ? p.category1.Length + 2 : 0).Trim(); p.game = GAME_ME1; p.broken = false; entries.Add(p); } count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.id = ReadInt(fs); p.type = ReadInt(fs); string desc = ReadString(fs); p.category1 = Regex.Match(desc, @"\[(.*?)\]").Groups[1].Value; p.state = desc.Substring(p.category1.Length > 0 ? p.category1.Length + 2 : 0).Trim(); p.game = GAME_ME2; p.broken = false; entries.Add(p); } count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.id = ReadInt(fs); p.type = ReadInt(fs); string desc = ReadString(fs); p.category1 = Regex.Match(desc, @"\[(.*?)\]").Groups[1].Value; p.state = desc.Substring(p.category1.Length > 0 ? p.category1.Length + 2 : 0).Trim(); p.game = GAME_ME3; p.broken = false; entries.Add(p); } return entries; }
/// <summary> /// Reads a v2 type DB (r748), by FemShep. Returns list of read entries. /// Contains the following columns: /// Plot ID /// Type (as int) /// Game (as int) /// Category1 (as string) /// Category2 (as string) /// State/Value (as string) /// Broken (as bool (stored as byte)) /// ME2 ID (as int) /// ME3 ID (as int) /// Notes (as string) /// </summary> /// <param name="fs">Filestream advanced past the version indicator</param> private List<PlotVarEntry> readVersion2DB(FileStream fs) { PlotVarEntry p; entries = new List<PlotVarEntry>(); int count = ReadInt(fs); for (int i = 0; i < count; i++) { p = new PlotVarEntry(); p.id = ReadInt(fs); p.type = ReadInt(fs); p.game = ReadInt(fs); p.category1 = ReadString(fs); p.state = ReadString(fs); p.broken = ReadBool(fs); p.me2id = ReadInt(fs); p.me3id = ReadInt(fs); p.notes = ReadString(fs); entries.Add(p); } return entries; }
private void commitTable() { //Commit the current edit to the table if (plotVarTable.IsCurrentCellDirty) { plotVarTable.CommitEdit(DataGridViewDataErrorContexts.Commit); } List<PlotVarEntry> commitingEntries = new List<PlotVarEntry>(); foreach (DataGridViewRow row in plotVarTable.Rows) { if ((string)row.Cells[COL_PLOTID].Value != null && ((string)row.Cells[COL_PLOTID].Value).Trim() != "") { PlotVarEntry pve = new PlotVarEntry(); pve.id = Convert.ToInt32((string)row.Cells[COL_PLOTID].Value); pve.type = StringToType((string)row.Cells[COL_VARTYPE].Value); pve.game = StringToGame((string)row.Cells[COL_GAME].Value); pve.category1 = row.Cells[COL_CATEGORY1].Value != null ? row.Cells[COL_CATEGORY1].Value.ToString() : ""; pve.state = row.Cells[COL_STATE].Value != null ? row.Cells[COL_STATE].Value.ToString() : ""; object broken = row.Cells[COL_BROKEN].Value; pve.broken = Convert.ToBoolean(broken); pve.me2id = row.Cells[COL_ME2SPEC].Value != null && !row.Cells[COL_ME2SPEC].Value.Equals("") ? Convert.ToInt32(row.Cells[COL_ME2SPEC].Value.ToString()) : 0; pve.me3id = row.Cells[COL_ME3SPEC].Value != null && !row.Cells[COL_ME3SPEC].Value.Equals("") ? Convert.ToInt32(row.Cells[COL_ME3SPEC].Value.ToString()) : 0; pve.notes = row.Cells[COL_NOTES].Value != null ? row.Cells[COL_NOTES].Value.ToString() : ""; commitingEntries.Add(pve); } } entries = commitingEntries; }
private void importFromCSVToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.csv|*.csv"; if (d.ShowDialog() == DialogResult.OK) { commitTable(); System.IO.StreamReader stringreader = new System.IO.StreamReader(d.FileName); var csv = new CsvReader(stringreader); var item = csv.GetRecords <PlotVarEntry>(); List <PlotVarEntry> importingEntries = new List <PlotVarEntry>(); while (csv.Read()) { PlotVarEntry p = new PlotVarEntry(); p.id = csv.GetField <int>(COL_PLOTID); p.type = CSVStringToType(csv.GetField <string>(COL_VARTYPE)); p.game = csv.GetField <int>(COL_GAME); p.category1 = csv.GetField <string>(COL_CATEGORY1); p.category2 = csv.GetField <string>(COL_CATEGORY2); p.state = csv.GetField <string>(COL_STATE); p.broken = csv.GetField <bool>(COL_BROKEN); p.me2id = csv.GetField <int>(COL_ME2SPEC); p.me3id = csv.GetField <int>(COL_ME3SPEC); p.notes = csv.GetField <string>(COL_NOTES); importingEntries.Add(p); } //csv.GetRecords<PlotVarEntry>().ToList(); stringreader.Close(); //import int recordsImported = 0, recordsUpdated = 0; foreach (PlotVarEntry pve in importingEntries) { bool import = true; foreach (PlotVarEntry ent in entries) { if (ent.id == pve.id && ent.game == pve.game) { import = false; bool recordUpdated = false; //same entry, merge empty values //vartype if (ent.type != pve.type) { ent.type = pve.type; recordUpdated = true; } //broken if (ent.broken != pve.broken) { ent.broken = pve.broken; recordUpdated = true; } //me2 if (ent.me2id != pve.me2id) { ent.me2id = pve.me2id; recordUpdated = true; } //me3id if (ent.me3id != pve.me3id) { ent.me3id = pve.me3id; recordUpdated = true; } //category if (ent.category1 == null || ent.category1.Equals("")) { ent.category1 = pve.category1; recordUpdated = true; } //state if (ent.state == null || ent.state.Equals("")) { ent.state = pve.state; recordUpdated = true; } //notes if (ent.notes == null || ent.notes.Equals("")) { ent.notes = pve.notes; recordUpdated = true; } if (recordUpdated) { recordsUpdated++; } } } if (import) { recordsImported++; entries.Add(pve); } } RefreshTable(); status.Text = "Imported from CSV into DB: " + d.FileName + " | " + recordsImported + " records imported | " + recordsUpdated + " records upated"; } }
public void RefreshLists() { listBox1.Items.Clear(); List <PlotVarEntry> temp = new List <PlotVarEntry>(); if (MEVersion == 0) { temp = database.ME1; } if (MEVersion == 1) { temp = database.ME2; } if (MEVersion == 2) { temp = database.ME3; } bool run = true; while (run) { run = false; for (int i = 0; i < temp.Count - 1; i++) { switch (SortStyle) { case 0: if (temp[i].ID > temp[i + 1].ID) { run = true; PlotVarEntry t = temp[i]; temp[i] = temp[i + 1]; temp[i + 1] = t; } break; case 1: if (temp[i].type > temp[i + 1].type) { run = true; PlotVarEntry t = temp[i]; temp[i] = temp[i + 1]; temp[i + 1] = t; } break; case 2: if (string.Compare(temp[i].Desc, temp[i + 1].Desc) < 0) { run = true; PlotVarEntry t = temp[i]; temp[i] = temp[i + 1]; temp[i + 1] = t; } break; } } } foreach (PlotVarEntry p in temp) { listBox1.Items.Add("ID: " + p.ID + " TYPE: " + TypeToString(p.type) + " DESCRIPTION: " + p.Desc); } status.Text = "Elements: " + listBox1.Items.Count; }