private void btnSaveProfile_Click(object sender, EventArgs e) { string str = Interaction.InputBox("Please enter a name for the profile:"); if (str == null || str.Length <= 0) { return; } if (!Directory.Exists("profiles")) { Directory.CreateDirectory("profiles"); } if (System.IO.File.Exists("profiles/" + str + ".xml")) { if (MessageBox.Show("There is already a profile file '" + str + ".xml'. Overwrite?", "Warning", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes) { return; } } DiffProfile p = new DiffProfile(); p.Name = str; p.Generate(lstPatches); p.Save("profiles/" + str + ".xml"); }
static public DiffProfile Load(string filename) { FileStream str = null; try { str = new FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); XmlSerializer s = new XmlSerializer(typeof(DiffProfile)); DiffProfile profile = (DiffProfile)s.Deserialize(str); str.Close(); profile.FullPath = new FileInfo(filename).FullName; return(profile); } catch (Exception) { //MessageBox.Show("Error deserializing last patches:\n" + ex.ToString()); if (str != null) { str.Close(); } return(null); } }
private void btnApply_Click(object sender, EventArgs e) { if (lstProfiles.SelectedIndex < 0 || lstProfiles.SelectedIndex >= Profiles.Count) { return; } DiffProfile p = Profiles[lstProfiles.SelectedIndex]; p.Apply(ref ((frmMain)this.Owner).lstPatches, ref ((frmMain)this.Owner).file); this.Close(); }
private void btnApplyLast_Click(object sender, EventArgs e) { DiffProfile profile = DiffProfile.Load("lastPatches.xml"); if (profile == null) { MessageBox.Show("Error loading last patches!"); return; } profile.Apply(ref lstPatches, ref file); }
private void frmProfiles_Shown(object sender, EventArgs e) { lstProfiles.Items.Clear(); if (!Directory.Exists("profiles")) { return; } DirectoryInfo dir = new DirectoryInfo("profiles"); FileInfo[] files = dir.GetFiles("*.xml", SearchOption.TopDirectoryOnly); foreach (FileInfo f in files) { try { DiffProfile profile = DiffProfile.Load(f.FullName); if (profile == null) { continue; } Profiles.Add(profile); if (f.Name.Replace(".xml", "") == profile.Name) { lstProfiles.Items.Add(profile.Name); } else { lstProfiles.Items.Add(profile.Name + "(" + f.Name + ")"); } } catch (Exception) { continue; } } lstProfiles_SelectedIndexChanged(null, null); }
private void btnDelete_Click(object sender, EventArgs e) { if (lstProfiles.SelectedIndex < 0 || lstProfiles.SelectedIndex >= Profiles.Count) { return; } DiffProfile p = Profiles[lstProfiles.SelectedIndex]; if (MessageBox.Show("Do you really want to delete '" + p.Name + "' ?", "Warning", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes) { return; } if (p.FullPath != null) { File.Delete(p.FullPath); } Profiles.Remove(p); lstProfiles.Items.RemoveAt(lstProfiles.SelectedIndex); }
private void lstProfiles_SelectedIndexChanged(object sender, EventArgs e) { if (lstProfiles.SelectedIndex < 0 || lstProfiles.SelectedIndex >= Profiles.Count) { txtPatches.Text = ""; grpProfile.Enabled = false; grpProfile.Text = ""; return; } grpProfile.Enabled = true; DiffProfile p = Profiles[lstProfiles.SelectedIndex]; grpProfile.Text = p.Name; txtPatches.Text = ""; foreach (DiffProfileEntry entry in p.Entries) { string str = "* " + entry.PatchName; if (entry.Inputs.Count > 0) { str += " ("; int num = 0; string[] inputs = new string[entry.Inputs.Count]; foreach (DiffProfileInput i in entry.Inputs) { inputs[num++] = "$" + i.name + "=" + i.value; } str += string.Join(", ", inputs) + ")"; } txtPatches.Text += str + "\r\n"; } }
private void btnSave_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Exe file (*.exe)|*.exe"; sfd.FileName = file.FileInfo.Name.Replace(".xdiff", "_patched.exe"); sfd.DefaultExt = "*.exe"; sfd.OverwritePrompt = true; sfd.InitialDirectory = new System.IO.FileInfo(txtExeFile.Text).DirectoryName; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.IO.FileStream str = new System.IO.FileStream("lastPatches.xml", System.IO.FileMode.Create, System.IO.FileAccess.Write); SoapFormatter soap = new SoapFormatter(); IEnumerable <int> patches = rightPatches.Where(patch => patch != int.MaxValue); soap.Serialize(str, patches.ToArray <int>()); str.Close(); //int i = 0; //foreach (KeyValuePair<int, DiffPatchBase> p in file.xPatches) //{ // if (p.Value is DiffPatchGroup) // continue; // /*if (rightPatches.Contains(p.Key)) // ((DiffPatch)file.xPatches[p.Key]).Apply = true; // else // ((DiffPatch)file.xPatches[p.Key]).Apply = false;*/ //} foreach (TreeNode n in lstPatches.Nodes) { if (n.Tag is DiffPatch) { ((DiffPatch)n.Tag).Apply = n.Checked; } foreach (TreeNode m in n.Nodes) { if (m.Tag is DiffPatch) { ((DiffPatch)m.Tag).Apply = m.Checked; } } } /*foreach (KeyValuePair<string, DiffPatch> p in indexedPatches) * { * if (rightPatches.Contains(i)) * file.Patches[p.Key].Apply = true; * else * file.Patches[p.Key].Apply = false; * i++; * }*/ DiffProfile profile = new DiffProfile(); profile.Name = "Last Patches"; profile.Generate(lstPatches); profile.Save("lastPatches.xml"); file.Patch(txtExeFile.Text, sfd.FileName); } }