protected override bool OnExecute() { World world = ExoEngine.ActiveWorld; // serialize World -> XML //Debug2.Push( "XmlSerializer.Serialize( world )" ); try { StreamWriter sOut = new StreamWriter(world.FileName, false, System.Text.Encoding.Default, 1); XmlSerializer xmlOut = new System.Xml.Serialization.XmlSerializer(typeof(World)); xmlOut.Serialize(sOut, world, new XmlSerializerNamespaces()); sOut.Close(); } catch (Exception e) { string fileName = BugTracking.WriteExceptionRecord(e); ExoEngine.Error("Error save World to file '" + world.FileName + "'.\n" + "Please send this bug report to [email protected]:\n" + fileName); return(false); } //Debug2.Pop(); ExoEngine.ActiveWorld.Dirty = false; ExoEngine.UpdateAll(); return(true); }
protected override bool OnExecute() { if (ExoEngine.ActiveWorld != null) { if (ExoEngine.Commands.Execute(typeof(FileClose)) != true) { return(false); } } string strFileName = null; if (this.Params != null) { if (this.Params[0] is string) { strFileName = (string)this.Params[0]; } } else { OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = false; ofd.Title = "Open World"; ofd.Filter = ExoEngine.sWorldFileFilter; ofd.InitialDirectory = ExoEngine.sWorldPath; DialogResult result = ofd.ShowDialog(); if (result != DialogResult.OK) { return(false); } strFileName = ofd.FileName; } if (strFileName == null || File.Exists(strFileName) == false) { return(false); } // deserialize XML -> World //Debug2.Push( "XmlSerializer.Deserialize( world )" ); World world = null; try { FileStream sIn = new FileStream(strFileName, FileMode.Open); XmlSerializer xmlIn = new System.Xml.Serialization.XmlSerializer(typeof(World)); world = (World)xmlIn.Deserialize(sIn); sIn.Close(); } catch (Exception e) { string fileName = BugTracking.WriteExceptionRecord(e); ExoEngine.Error("Error loading World from file '" + strFileName + "'.\n" + "Please send this bug report to [email protected]:\n" + fileName); return(false); } //Debug2.Pop(); world.FileName = strFileName; world.Dirty = false; world.Reset(); ExoEngine.ActiveWorld = world; ExoEngine.UpdateAll(); return(true); }