/// <summary> /// The save recursive. /// </summary> /// <param name="outputFilePath">The output file path.</param> /// <param name="parsed">The parsed.</param> /// <param name="pb">The pb.</param> /// <remarks></remarks> public void SaveRecursive(string outputFilePath, bool parsed, ToolStripProgressBar pb) { ArrayList metas = RecursivelyLoadMetas(parsed, pb); #region Get name tag name // Contains the orignal meta name string origName = ((Meta)metas[0]).name; Globals.askForName metaRename = new Globals.askForName("Enter new name for Meta", "Select Exported tag name:", "&Export Recursively", origName, origName.Substring(origName.LastIndexOf('\\') + 1), true); if (metaRename.ShowDialog() == DialogResult.Cancel) { pb.Value = 0; return; } // Contains the changed meta name string newName = metaRename.getTextBoxValue(); metaRename.Dispose(); #endregion // If set to true, will rename any linked tags with the same tag names // eg. [eqip] objects\powerups\shotgun_ammo\shotgun_ammo renamed to objects\powerups\shotgun_ammo_max\shotgun_ammo_max // would also have it's name changed in [hltm] & [mode] bool recursivelyRenameTags = false; if (newName != this.name) { if (MessageBox.Show("Do you wish to recursively rename similar tags?\n", "Rename recursively?", MessageBoxButtons.YesNo) == DialogResult.Yes) recursivelyRenameTags = true; } int y = newName.LastIndexOf("\\") + 1; StreamWriter SW = new StreamWriter(new FileStream( outputFilePath + "\\" + newName.Substring(y, newName.Length - y) + ".info", FileMode.Create)); for (int x = 0; x < metas.Count; x++) { Meta m = (Meta)metas[x]; string temp1 = m.name; #region Recursive Renaming List<string> backup = new List<string>(); // Backup all the items PointsToTagName values & // change these to reflect recursive renaming // Rename the first Meta if (x == 0 && !recursivelyRenameTags) temp1 = newName; else if (recursivelyRenameTags && temp1 == origName) { temp1 = newName; for (int i = 0; i < m.items.Count; i++) { switch (m.items[i].type) { case ItemType.Ident: backup.Add(((Ident)m.items[i]).pointstotagname); if (((Ident)m.items[i]).pointstotagname == this.name) ((Ident)m.items[i]).pointstotagname = newName; break; case ItemType.Reflexive: backup.Add(((Reflexive)m.items[i]).pointstotagname); if (((Reflexive)m.items[i]).pointstotagname == this.name) ((Reflexive)m.items[i]).pointstotagname = newName; break; default: backup.Add(string.Empty); break; } } } #endregion // directory to create int loc = temp1.LastIndexOf("\\") + 1; string temp2 = outputFilePath + "\\" + temp1.Substring(0, loc); Directory.CreateDirectory(temp2); // name of meta string tempname = temp1.Substring(loc, temp1.Length - loc); string temp3 = temp2 + tempname + "." + m.type; temp3 = temp3.Replace("<", "_"); temp3 = temp3.Replace(">", "_"); m.SortItemsByOffset(); m.SaveMetaToFile(temp3, false); #region Recursive Renaming Restore // Restore Items PointsToTagName values if (recursivelyRenameTags) { for (int i = 0; i < m.items.Count; i++) { switch (m.items[i].type) { case ItemType.Ident: if (((Ident)m.items[i]).pointstotagname == this.name) ((Ident)m.items[i]).pointstotagname = backup[i]; break; case ItemType.Reflexive: if (((Reflexive)m.items[i]).pointstotagname == this.name) ((Reflexive)m.items[i]).pointstotagname = backup[i]; break; } } backup.Clear(); } #endregion SW.WriteLine(temp3); } SW.Flush(); SW.Close(); // Reset Progress Bar pb.Value = 0; }
/// <summary> /// The save recursive. /// </summary> /// <param name="outputFilePath">The output file path.</param> /// <param name="parsed">The parsed.</param> /// <param name="pb">The pb.</param> /// <remarks></remarks> public void SaveRecursive(string outputFilePath, bool parsed, ToolStripProgressBar pb) { ArrayList metas = RecursivelyLoadMetas(parsed, pb); #region Get name tag name // Contains the orignal meta name string origName = ((Meta)metas[0]).name; Globals.askForName metaRename = new Globals.askForName("Enter new name for Meta", "Select Exported tag name:", "&Export Recursively", origName, origName.Substring(origName.LastIndexOf('\\') + 1), true); if (metaRename.ShowDialog() == DialogResult.Cancel) { pb.Value = 0; return; } // Contains the changed meta name string newName = metaRename.getTextBoxValue(); metaRename.Dispose(); #endregion // If set to true, will rename any linked tags with the same tag names // eg. [eqip] objects\powerups\shotgun_ammo\shotgun_ammo renamed to objects\powerups\shotgun_ammo_max\shotgun_ammo_max // would also have it's name changed in [hltm] & [mode] bool recursivelyRenameTags = false; if (newName != this.name) { if (MessageBox.Show("Do you wish to recursively rename similar tags?\n", "Rename recursively?", MessageBoxButtons.YesNo) == DialogResult.Yes) { recursivelyRenameTags = true; } } int y = newName.LastIndexOf("\\") + 1; StreamWriter SW = new StreamWriter(new FileStream( outputFilePath + "\\" + newName.Substring(y, newName.Length - y) + ".info", FileMode.Create)); for (int x = 0; x < metas.Count; x++) { Meta m = (Meta)metas[x]; string temp1 = m.name; #region Recursive Renaming List <string> backup = new List <string>(); // Backup all the items PointsToTagName values & // change these to reflect recursive renaming // Rename the first Meta if (x == 0 && !recursivelyRenameTags) { temp1 = newName; } else if (recursivelyRenameTags && temp1 == origName) { temp1 = newName; for (int i = 0; i < m.items.Count; i++) { switch (m.items[i].type) { case ItemType.Ident: backup.Add(((Ident)m.items[i]).pointstotagname); if (((Ident)m.items[i]).pointstotagname == this.name) { ((Ident)m.items[i]).pointstotagname = newName; } break; case ItemType.Reflexive: backup.Add(((Reflexive)m.items[i]).pointstotagname); if (((Reflexive)m.items[i]).pointstotagname == this.name) { ((Reflexive)m.items[i]).pointstotagname = newName; } break; default: backup.Add(string.Empty); break; } } } #endregion // directory to create int loc = temp1.LastIndexOf("\\") + 1; string temp2 = outputFilePath + "\\" + temp1.Substring(0, loc); Directory.CreateDirectory(temp2); // name of meta string tempname = temp1.Substring(loc, temp1.Length - loc); string temp3 = temp2 + tempname + "." + m.type; temp3 = temp3.Replace("<", "_"); temp3 = temp3.Replace(">", "_"); m.SortItemsByOffset(); m.SaveMetaToFile(temp3, false); #region Recursive Renaming Restore // Restore Items PointsToTagName values if (recursivelyRenameTags) { for (int i = 0; i < m.items.Count; i++) { switch (m.items[i].type) { case ItemType.Ident: if (((Ident)m.items[i]).pointstotagname == this.name) { ((Ident)m.items[i]).pointstotagname = backup[i]; } break; case ItemType.Reflexive: if (((Reflexive)m.items[i]).pointstotagname == this.name) { ((Reflexive)m.items[i]).pointstotagname = backup[i]; } break; } } backup.Clear(); } #endregion SW.WriteLine(temp3); } SW.Flush(); SW.Close(); // Reset Progress Bar pb.Value = 0; }