using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Mesen.GUI.Config; namespace Mesen.GUI.Debugger { public class DebugWorkspaceManager { private static DebugWorkspace _workspace; private static string _romName; private static object _lock = new object(); public static void SaveWorkspace() { if(_workspace != null) { lock(_lock) { if(_workspace != null) { _workspace.WatchValues = new List(WatchManager.WatchEntries); _workspace.Labels = new List(LabelManager.GetLabels()); _workspace.Breakpoints = new List(BreakpointManager.Breakpoints); _workspace.Save(); } } } } public static void Clear() { lock(_lock) { _workspace = null; _romName = null; } } public static void ResetWorkspace() { if(_workspace != null) { lock(_lock) { if(_workspace != null) { _workspace.Breakpoints = new List(); _workspace.Labels = new List(); _workspace.WatchValues = new List(); _workspace.Save(); Clear(); } } } } public static void SetupWorkspace() { lock(_lock) { if(_workspace != null) { //Setup labels if(_workspace.Labels.Count == 0) { LabelManager.ResetLabels(); if(!ConfigManager.Config.DebugInfo.DisableDefaultLabels) { LabelManager.SetDefaultLabels(InteropEmu.FdsGetSideCount() > 0); } } else { LabelManager.ResetLabels(); LabelManager.SetLabels(_workspace.Labels, false); } //Load watch entries WatchManager.WatchEntries = _workspace.WatchValues; //Load breakpoints BreakpointManager.SetBreakpoints(_workspace.Breakpoints); } } } public static DebugWorkspace GetWorkspace(bool forceReload = false) { string romName = InteropEmu.GetRomInfo().GetRomName(); if(_workspace == null || _romName != romName || forceReload) { lock(_lock) { if(_workspace == null || _romName != romName || forceReload) { if(_workspace != null) { SaveWorkspace(); } _romName = InteropEmu.GetRomInfo().GetRomName(); _workspace = DebugWorkspace.GetWorkspace(); SetupWorkspace(); } } } return _workspace; } } }