/// <summary> /// Handles the <see cref="CommandLineSwitch.SaveMaps"/> switch. /// </summary> /// <param name="values">The values passed to the switch at the command line.</param> /// <returns>True if completed without errors; false if there were any errors.</returns> static bool HandleSwitch_SaveMaps(string[] values) { var ret = true; var camera = new Camera2D(GameData.ScreenSize); var dynamicEntityFactory = EditorDynamicEntityFactory.Instance; var contentPath = ContentPaths.Dev; // Get the maps var mapInfos = MapHelper.FindAllMaps(); // For each map, load it then save it foreach (var mapInfo in mapInfos) { // Load EditorMap map; try { map = new EditorMap(mapInfo.ID, camera, GetTimeDummy.Instance); map.Load(contentPath, true, dynamicEntityFactory); } catch (Exception ex) { const string errmsg = "Failed to load map ID `{0}`. Exception: {1}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, mapInfo.ID, ex); } Debug.Fail(string.Format(errmsg, mapInfo.ID, ex)); map = null; ret = false; } // Save try { if (map != null) { MapHelper.SaveMap(map, false); } } catch (Exception ex) { const string errmsg = "Failed to save map `{0}`. Exception: {1}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, mapInfo, ex); } Debug.Fail(string.Format(errmsg, mapInfo, ex)); ret = false; } } return(ret); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Form.Closing"/> event. /// </summary> /// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs"/> that contains the event data.</param> protected override void OnClosing(CancelEventArgs e) { const string confirmMsg = @"Do you wish to save the map ({0}) before closing? If you do not save, all changes will be lost."; // Save? var map = mapScreen.Map; if (map != null) { if (MessageBox.Show(string.Format(confirmMsg, map), "Save before closing?", MessageBoxButtons.YesNo) == DialogResult.Yes) { MapHelper.SaveMap(map); } } base.OnClosing(e); }