private void btnLoad_Click(object sender, EventArgs e) { file = new DiffFile(); if (txtDiffFile.Text.EndsWith(".xdiff")) { file.Load(txtDiffFile.Text, DiffType.xDiff); } else { file.Load(txtDiffFile.Text, DiffType.Diff); } lstPatches.Nodes.Clear(); if (file.xPatches.Count <= 0) { return; } int num = file.PatchCount(); if (file.Type == DiffType.xDiff) { leftPatches = new int[num]; rightPatches = new int[num]; } else { indexedPatches = file.Patches.ToArray(); leftPatches = new int[file.Patches.Count]; rightPatches = new int[file.Patches.Count]; } int i = 0; for (i = 0; i < leftPatches.Length; i++) { leftPatches[i] = int.MaxValue; rightPatches[i] = int.MaxValue; } i = 0; if (file.Type == DiffType.xDiff) { foreach (KeyValuePair <int, DiffPatchBase> p in file.xPatches) { if (p.Value is DiffPatchGroup) { TreeNodeEx node = new TreeNodeEx(p.Value.Name); node.Tag = file.xPatches[p.Value.ID]; //is this a reference or a copy? :x node.ActAsRadioGroup = true; foreach (DiffPatch p2 in ((DiffPatchGroup)p.Value).Patches) { TreeNodeEx n = new TreeNodeEx(p2.Name); n.Tag = file.xPatches[p2.ID]; node.Nodes.Add(n); } lstPatches.Nodes.Add(node); } else if (p.Value is DiffPatch && ((DiffPatch)p.Value).GroupID <= 0) { TreeNodeEx node = new TreeNodeEx(p.Value.Name); node.Tag = file.xPatches[p.Value.ID]; lstPatches.Nodes.Add(node); } } } else { foreach (KeyValuePair <string, DiffPatch> p in indexedPatches) { leftPatches[i] = i; //lstPatches.Items.Add(p.Value.Name); i++; } } grpDiff.Enabled = true; }
public void Apply(ref PatchList lstPatches, ref DiffFile file) { // Clear patches and inputs foreach (DiffPatchBase b in file.xPatches.Values) { if (b is DiffPatchGroup) { foreach (DiffPatch p in ((DiffPatchGroup)b).Patches) { p.Apply = false; foreach (DiffInput i in p.Inputs) { i.Value = null; } } } else if (b is DiffPatch) { ((DiffPatch)b).Apply = false; foreach (DiffInput i in ((DiffPatch)b).Inputs) { i.Value = null; } } } foreach (DiffProfileEntry entry in this.Entries) { DiffPatch patch = (DiffPatch)file.xPatches[entry.PatchID]; ((DiffPatch)file.xPatches[entry.PatchID]).Apply = true; foreach (DiffProfileInput j in entry.Inputs) { foreach (DiffInput k in patch.Inputs) { if (k.Name == j.name) { k.Value = j.value; } } } } // Lets just rebuild the whole thing =D lstPatches.Nodes.Clear(); foreach (KeyValuePair <int, DiffPatchBase> p in file.xPatches) { if (p.Value is DiffPatchGroup) { TreeNodeEx node = new TreeNodeEx(p.Value.Name); node.Tag = file.xPatches[p.Value.ID]; //is this a reference or a copy? :x node.ActAsRadioGroup = true; foreach (DiffPatch p2 in ((DiffPatchGroup)p.Value).Patches) { TreeNodeEx n = new TreeNodeEx(p2.Name); n.Tag = file.xPatches[p2.ID]; if (((DiffPatch)n.Tag).Apply) { n.Checked = true; node.Checked = true; } node.Nodes.Add(n); } lstPatches.Nodes.Add(node); } else if (p.Value is DiffPatch && ((DiffPatch)p.Value).GroupID <= 0) { TreeNodeEx node = new TreeNodeEx(p.Value.Name); node.Tag = file.xPatches[p.Value.ID]; if (((DiffPatch)node.Tag).Apply) { node.Checked = true; } lstPatches.Nodes.Add(node); } } }