private void SaveManifestButton_Click(object sender, EventArgs e) { if (SaveFileDialog.ShowDialog() != DialogResult.OK) { return; } try { var filename = SaveFileDialog.FileName; var xml = ProjectManifestTextBox.Text; var xmldoc = new XmlDocument(); xmldoc.LoadXml(xml); var pso = XmlPso.GetPso(xmldoc); var bytes = pso.Save(); File.WriteAllBytes(filename, bytes); } catch (Exception ex) { MessageBox.Show("Error saving _manifest.ymf file:\n" + ex.ToString()); } }
public bool SaveMeta(XmlDocument doc) { //if explorer is in edit mode, and the current RpfFileEntry is valid, convert XML to the //current meta format and then save the file into the RPF. //otherwise, save the generated file to disk? //(currently just return false and revert to XML file save) if (!(exploreForm?.EditMode ?? false)) { return(false); } if (rpfFileEntry?.Parent == null) { return(false); } byte[] data = null; #if !DEBUG try #endif { switch (metaFormat) { default: case MetaFormat.XML: return(false); //what are we even doing here? case MetaFormat.RSC: var meta = XmlMeta.GetMeta(doc); if ((meta.DataBlocks?.Data == null) || (meta.DataBlocks.Count == 0)) { MessageBox.Show("Schema not supported.", "Cannot import Meta XML"); return(false); } data = ResourceBuilder.Build(meta, 2); //meta is RSC "Version":2 (it's actually a type identifier, not a version!) break; case MetaFormat.PSO: var pso = XmlPso.GetPso(doc); if ((pso.DataSection == null) || (pso.DataMapSection == null) || (pso.SchemaSection == null)) { MessageBox.Show("Schema not supported.", "Cannot import PSO XML"); return(false); } data = pso.Save(); break; case MetaFormat.RBF: var rbf = XmlRbf.GetRbf(doc); if (rbf.current == null) { MessageBox.Show("Schema not supported.", "Cannot import RBF XML"); return(false); } data = rbf.Save(); break; case MetaFormat.Ynd: var ynd = XmlYnd.GetYnd(doc); if (ynd.NodeDictionary == null) { MessageBox.Show("Schema not supported.", "Cannot import YND XML"); return(false); } data = ynd.Save(); break; case MetaFormat.CacheFile: MessageBox.Show("Sorry, CacheFile import is not supported.", "Cannot import CacheFile XML"); return(false); } } #if !DEBUG catch (Exception ex) { MessageBox.Show("Exception encountered!\r\n" + ex.ToString(), "Cannot convert XML"); return(false); } #endif if (data == null) { MessageBox.Show("Schema not supported. (Unspecified error - data was null!)", "Cannot convert XML"); return(false); } if (!rpfFileEntry.Path.ToLowerInvariant().StartsWith("mods")) { if (MessageBox.Show("This file is NOT located in the mods folder - Are you SURE you want to save this file?\r\nWARNING: This could cause permanent damage to your game!!!", "WARNING: Are you sure about this?", MessageBoxButtons.YesNo) != DialogResult.Yes) { return(false);//that was a close one } } try { if (!(exploreForm?.EnsureRpfValidEncryption(rpfFileEntry.File) ?? false)) { return(false); } var newentry = RpfFile.CreateFile(rpfFileEntry.Parent, rpfFileEntry.Name, data); if (newentry != rpfFileEntry) { } rpfFileEntry = newentry; exploreForm?.RefreshMainListViewInvoke(); //update the file details in explorer... modified = false; StatusLabel.Text = metaFormat.ToString() + " file saved successfully at " + DateTime.Now.ToString(); return(true); //victory! } catch (Exception ex) { MessageBox.Show("Error saving file to RPF! The RPF archive may be corrupted...\r\n" + ex.ToString(), "Really Bad Error"); } return(false); }