コード例 #1
0
ファイル: PatchForm.cs プロジェクト: europop/morrgraphext
 private void PatchForm_Load(object sender, EventArgs e)
 {
     tvPatch.Nodes.Clear();
     List<String> files = new List<String>(Directory.GetFiles("mge3", "*.mcp", SearchOption.AllDirectories));
     files.Add(patchSettings); // last of all
     foreach (String file in files) {
         INIFile mcpFile = new INIFile(file, new INIFile.INIVariableDef[] { INIFile.iniDefEmpty }, Encoding.Default);
         String[] sections = mcpFile.getSections();
         foreach (String Section in sections) {
             Patch patch = new Patch(mcpFile, Section);
             String[] parents = patch.Parent.Split(new String[] { Patch.SepInternal.ToString() }, StringSplitOptions.RemoveEmptyEntries);
             TreeNodeCollection nodes = tvPatch.Nodes;
             TreeNode[] exist;
             for (int i = 0; i < parents.Length; i++) {
                 exist = nodes.Find(parents[i].ToLower(), false);
                 if (exist.Length > 0) nodes = exist[0].Nodes;
                 else {
                     TreeNode node = nodes.Add(parents[i].ToLower(), parents[i]);
                     node.Checked = true;
                     nodes = node.Nodes;
                 }
             }
             exist = nodes.Find(Section.ToLower(), false);
             if (exist.Length > 0) {
                 Patch existing = (Patch)exist[0].Tag;
                 bool update = existing == null;
                 if (!update) {
                     if (patch.Version <= existing.Version) continue;
                     if (patch.Original == null && patch.Patched == null && patch.Attach == null) {
                         exist[0].Checked = existing.Checked = patch.Checked;
                         existing.Removed = patch.Removed || existing.Removed;
                         existing.Expanded = patch.Expanded;
                         continue;
                     }
                     update = true;
                 }
                 if (update) {
                     exist[0].Checked = patch.Checked;
                     exist[0].Tag = patch;
                     continue;
                 }
             } else {
                 TreeNode node = nodes.Add(Section.ToLower(), Section);
                 node.Tag = patch;
                 node.Checked = patch.Checked;
                 node.ToolTipText = "";
                 foreach(String language in Languages)
                     if (node.ToolTipText == "")
                         foreach(Unit description in patch.Description)
                             if (language == description.Name) { node.ToolTipText = description.Hex.Replace("\t", "\n"); break; }
             }
         }
     }
     RemoveEmptyNodes(tvPatch.Nodes);
     UpdateColour(tvPatch.Nodes, true);
     ExpandNodes(tvPatch.Nodes);
     tvPatch.Sort();
     loaded = true;
 }
コード例 #2
0
ファイル: PatchEditor.cs プロジェクト: europop/morrgraphext
 private void bAddSection_Click(object sender, EventArgs e)
 {
     String section = tbNewSection.Text.Trim();
     if (section.Length == 0) return;
     bool contains = false;  // Instead of non case sensitive lbSections.Items.Contains(section)
     foreach (String name in lbSections.Items) if (name.ToLower() == section.ToLower()) { contains = true; section = name; break; }
     if (!contains) {
         Patch patch;
         if (tbNewSection.Tag != null) {
             patch = selections.Sections[(String)lbSections.SelectedItem];
             selections.Sections.Remove(lbSections.SelectedItem.ToString());
             lbSections.Items.Remove(lbSections.SelectedItem);
             RestoreButton();
         } else patch = new Patch("Morrowind.exe" + Patch.SepInternal.ToString() + "Misc");
         lbSections.Items.Add(section);
         selections.Sections.Add(section, patch);
     }
     lbSections.SelectedItem = section;
     tbNewSection.Text = "";
     if (!contains) HistoryUpdate(); // last of all
 }
コード例 #3
0
ファイル: PatchEditor.cs プロジェクト: europop/morrgraphext
 private void tsmiPatchByFile_Click(object sender, EventArgs e)
 {
     if (!bNew_Click()) return;
     String original = SelectExecutableFile("Open Original file for comparison...");
     if (original == null) return;
     AddBinaryFile(original);
     this.Text = original;
     String patched;
     do {
         patched = SelectExecutableFile("Open Patched file for comparison...");
         if (patched == null) return;
     } while (patched == original);
     AddBinaryFile(patched);
     this.Text = patched;
     byte[] bOriginal = BinaryFiles[original.ToLower()];
     byte[] bPatched = BinaryFiles[patched.ToLower()];
     if(bOriginal.Length != bPatched.Length) {
         MessageBox.Show("Files for comparison must be equal in size!", Statics.strings["Warning"], MessageBoxButtons.OK, MessageBoxIcon.Warning);
         this.Text = "";
         return;
     }
     String section = patched.Substring(patched.LastIndexOf("\\") + 1).ToLower().Replace(".", "_");
     foreach (Char c in illegal) section = section.Replace(c, '_');
     Patch patch = new Patch(original.Substring(original.LastIndexOf("\\")+1) + "\\Difference");
     List<Unit> uOriginal = new List<Unit>();
     List<Unit> uPatch = new List<Unit>();
     uint address = 0;    // We must start after PE header
     for (uint i = 1; i < bOriginal.Length; i++ ) {
         if (bOriginal[i] == bPatched[i]) address = 0;
         else {
             if (address == 0) {
                 address = i;
                 uOriginal.Add(new Unit(address));
                 uPatch.Add(new Unit(address));
             }
             uOriginal[uOriginal.Count - 1].Hex += String.Format("{0:X2} ", bOriginal[i]);
             uPatch[uPatch.Count - 1].Hex += String.Format("{0:X2} ", bPatched[i]);
         }
     }
     patch.Original = uOriginal.ToArray();
     patch.Patched = uPatch.ToArray();
     if(uOriginal.Count > 0) {
         lbSections.Items.Add(section);
         selections.Sections.Add(section, patch);
         lbSections.SelectedIndex = lbSections.Items.Count - 1;
         HistoryUpdate();
     } else {
         MessageBox.Show("Selected files are identical.", Statics.strings["Message"], MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     BinaryFiles.Remove(original.ToLower());
     BinaryFiles.Remove(patched.ToLower());
 }
コード例 #4
0
ファイル: PatchEditor.cs プロジェクト: europop/morrgraphext
 private String[] GetAttachedNames(Patch section)
 {
     List<String> names = new List<String>();
     if (section != null) {
         foreach (Patch patch in selections.Sections.Values) {
             if (section.Parent.StartsWith(patch.Parent)) {
                 if (patch.Attach != null) foreach (Unit attachment in patch.Attach) names.Add(attachment.Name);
             }
         }
     }
     names.Sort();
     return names.ToArray();
 }