public static ScriptProgressForm get() { if (obj == null) { obj = new ScriptProgressForm(); } return(obj); }
private void button8_Click(object sender, EventArgs e) { openFileDialog1.Filter = "Bass Ru Script (*.xml)|*.xml"; openFileDialog1.FilterIndex = 0; openFileDialog1.Multiselect = false; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { XmlDocument doc = new XmlDocument(); doc.Load(openFileDialog1.FileName); if (doc.DocumentElement.Name != "bassru-script") { throw new ApplicationException("Bad script root node"); } int max = 0; foreach (XmlNode nd in doc.DocumentElement.ChildNodes) { if (nd.NodeType == XmlNodeType.Element) { if (nd.Name == "load" || nd.Name == "import" || nd.Name == "export" || nd.Name == "save") { max++; } } } ScriptProgressForm.get().init(max); foreach (XmlNode nd in doc.DocumentElement.ChildNodes) { if (nd.NodeType == XmlNodeType.Element) { string cd = Directory.GetCurrentDirectory(); uint id = 0; string fl = ""; Config.FileInfo fi; BResource res = null; switch (nd.Name) { case "load": path = nd.Attributes["path"].Value; if (path[path.Length - 1] != '\\') { path += "\\"; } ScriptProgressForm.get().progress("load from " + path); button1.PerformClick(); Directory.SetCurrentDirectory(cd); break; case "import": case "export": id = uint.Parse(nd.Attributes["id"].Value); fl = nd.Attributes["file"].Value; ScriptProgressForm.get().progress(nd.Name + " " + id.ToString() + (nd.Name == "import"?" from ":" to ") + fl); fi = Config.get().findFile(id); if (fi.fid == 0) { throw new ApplicationException("Unknown file type " + id.ToString()); } res = BResourceHelper.getResource(fi.node); if (nd.Name == "import") { res.import(fl); } else { res.export(fl); } break; case "save": string pth = nd.Attributes["path"].Value; if (pth[pth.Length - 1] != '\\') { pth += "\\"; } ScriptProgressForm.get().progress("save to " + pth); SkyDisk.get().saveDiskAndDinner(pth + "sky.dsk"); Directory.SetCurrentDirectory(cd); break; } } } ScriptProgressForm.get().fini(); load(); } catch (Exception ex) { ScriptProgressForm.get().fini(); MessageBox.Show("Error while script run:" + ex.Message); load(); //throw; } } }
public static ScriptProgressForm get() { if (obj == null) obj = new ScriptProgressForm(); return obj; }