public static GCTNode FromTXT(string path) { GCTNode node = new GCTNode(); if (File.Exists(path)) { using (StreamReader sr = new StreamReader(path)) for (int i = 0; !sr.EndOfStream; i++) { string lastLine; while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) { ; } if (!String.IsNullOrEmpty(lastLine)) { node._name = lastLine; } lastLine = sr.ReadLine(); if (!String.IsNullOrEmpty(lastLine)) { node._gameName = lastLine; } while (!sr.EndOfStream) { while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) { ; } GCTCodeEntryNode e = new GCTCodeEntryNode(); List <GCTCodeLine> g = new List <GCTCodeLine>(); if (!String.IsNullOrEmpty(lastLine)) { e._name = lastLine; } else { break; } while (true) { lastLine = sr.ReadLine(); if (String.IsNullOrEmpty(lastLine)) { break; } string[] lines = lastLine.Split(' '); if (lines.Length < 2) { break; } uint val1, val2; if (uint.TryParse(lines[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val1)) { if (uint.TryParse(lines[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val2)) { GCTCodeLine l = new GCTCodeLine(val1, val2); g.Add(l); } else { break; } } else { break; } } e._lines = g.ToArray(); e._description = lastLine; node.AddChild(e); } } } return(node); }
public static GCTNode FromTXT(string path) { GCTNode node = new GCTNode(); if (File.Exists(path)) { bool anyEnabled = false; using (StreamReader sr = new StreamReader(path)) { for (int i = 0; !sr.EndOfStream; i++) { string lastLine; while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) { ; } if (!String.IsNullOrEmpty(lastLine)) { node._name = lastLine; } lastLine = sr.ReadLine(); if (!String.IsNullOrEmpty(lastLine)) { node._gameName = lastLine; } while (!sr.EndOfStream) { while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) { ; } GCTCodeEntryNode e = new GCTCodeEntryNode(); List <GCTCodeLine> g = new List <GCTCodeLine>(); if (!String.IsNullOrEmpty(lastLine)) { e._name = lastLine; } else { break; } bool?codeEnabled = null; while (true) { lastLine = sr.ReadLine(); if (String.IsNullOrEmpty(lastLine)) { break; } bool lineEnabled = lastLine.StartsWith("* "); if (lineEnabled) { anyEnabled = true; lastLine = lastLine.Substring(2); } if (codeEnabled == null) { codeEnabled = lineEnabled; } else if (codeEnabled != lineEnabled) { break; } string[] lines = lastLine.Split(' '); if (lines.Length < 2) { break; } uint val1, val2; if (uint.TryParse(lines[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val1)) { if (uint.TryParse(lines[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val2)) { GCTCodeLine l = new GCTCodeLine(val1, val2); g.Add(l); } else { break; } } else { break; } } List <string> description = new List <string>(); while (!String.IsNullOrEmpty(lastLine)) { description.Add(lastLine); lastLine = sr.ReadLine(); } e._enabled = codeEnabled ?? false; e._lines = g.ToArray(); e._description = String.Join(Environment.NewLine, description); node.AddChild(e, false); } } } if (anyEnabled == false) { // No codes enabled in file - enable all codes foreach (GCTCodeEntryNode e in node.Children) { e._enabled = true; } } } return(node); }
private void saveAllRememberedCodesToGCTToolStripMenuItem_Click(object sender, EventArgs e) { GCTNode g = new GCTNode(); foreach (CodeStorage w in BrawlLib.Properties.Settings.Default.Codes) { GCTCodeEntryNode r = new GCTCodeEntryNode(); r.LinesNoSpaces = w._code; r._name = w._name; r._description = w._description; g.AddChild(r); } SaveAs(g, true); }
private void lstCodes_SelectedIndexChanged(object sender, EventArgs e) { if (panel1.Enabled = lstCodes.SelectedIndices.Count > 0) { _updating = true; _codeEntry = lstCodes.Items[lstCodes.SelectedIndices[0]].Tag as GCTCodeEntryNode; txtDesc.Text = _codeEntry._description; txtCode.Text = _codeEntry.DisplayLines; textBox1.Text = _codeEntry._name; string s = _codeEntry.LinesNoSpaces; int i = 0; _codeEntrySavedIndex = -1; foreach (CodeStorage c in BrawlLib.Properties.Settings.Default.Codes) { if (c._code == s) { btnAddRemoveCode.Text = "Forget Code"; _codeEntrySavedIndex = i; break; } i++; } if (_codeEntrySavedIndex == -1) btnAddRemoveCode.Text = "Remember Code"; _updating = false; } status.Text = ""; }
private void btnNewCode_Click(object sender, EventArgs e) { if (_updating) return; if (TargetNode == null) TargetNode = new GCTNode(); GCTCodeEntryNode n = new GCTCodeEntryNode() { _name = "New Code" }; TargetNode.AddChild(n); lstCodes.Items.Add(new ListViewItem() { Text = n.Name, Checked = true, Tag = n }); }
public static GCTNode FromTXT(string path) { GCTNode node = new GCTNode(); if (File.Exists(path)) using (StreamReader sr = new StreamReader(path)) for (int i = 0; !sr.EndOfStream; i++) { string lastLine; while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) ; if (!String.IsNullOrEmpty(lastLine)) node._name = lastLine; lastLine = sr.ReadLine(); if (!String.IsNullOrEmpty(lastLine)) node._gameName = lastLine; while (!sr.EndOfStream) { while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) ; GCTCodeEntryNode e = new GCTCodeEntryNode(); List<GCTCodeLine> g = new List<GCTCodeLine>(); if (!String.IsNullOrEmpty(lastLine)) e._name = lastLine; else break; while (true) { lastLine = sr.ReadLine(); if (String.IsNullOrEmpty(lastLine)) break; string[] lines = lastLine.Split(' '); if (lines.Length < 2) break; uint val1, val2; if (uint.TryParse(lines[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val1)) if (uint.TryParse(lines[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val2)) { GCTCodeLine l = new GCTCodeLine(val1, val2); g.Add(l); } else break; else break; } e._lines = g.ToArray(); e._description = lastLine; node.AddChild(e); } } return node; }