/// <summary> /// Starts API monitoring and intercepting of debug output /// </summary> public void Start() { bool canConnectDebugger = this.XboxViewItem.XboxDevice.ConnectDebugger(false); if (!canConnectDebugger) { MessageBoxResult result = MessageBox.Show("Another debugging session with this Xbox is already present. Do you want to connect anyway?", "Error", MessageBoxButton.YesNo, MessageBoxImage.Exclamation); if (result == MessageBoxResult.Yes) { canConnectDebugger = this.XboxViewItem.XboxDevice.ConnectDebugger(true); } } if (!canConnectDebugger) { this.XboxViewItem.DebugOutputViewModel = null; } else { this.debugOutputWindow = new DebugOutputWindow(this); this.debugOutputWindow.Closing += this.OnWindowClosing; this.OutputDebugStringASymbolSession = new DebugOutputMonitorAPISession(this, this.XboxViewItem.XboxDevice.MonitorAPI("OutputDebugStringA", this.InterceptAPICall), false); this.OutputDebugStringWSymbolSession = new DebugOutputMonitorAPISession(this, this.XboxViewItem.XboxDevice.MonitorAPI("OutputDebugStringW", this.InterceptAPICall), false); this.monitorAPISessions.Add(this.OutputDebugStringASymbolSession); this.monitorAPISessions.Add(this.OutputDebugStringWSymbolSession); this.XboxViewItem.XboxDevice.StartMonitoringDebugOutput(this.ReceiveDebugOutput); this.XboxViewItem.XboxDevice.StartMonitoringTitleFailures(this.OnTitleFailure); // Read XML config file for debug string XmlDocument configFile = new XmlDocument(); configFile.Load(@"DebugStrings.cfg"); XmlNodeList nodes = configFile.DocumentElement.SelectNodes("/DebugStringsConfig/GoodPrefixes/GoodPrefix"); foreach (XmlNode n in nodes) { this.safeDebugOutputPrefixText.Add(n.InnerText); } // Read XML config file for API monitor symbols configFile = new XmlDocument(); configFile.Load(@"MonitorAPISymbols.cfg"); nodes = configFile.DocumentElement.SelectNodes("/MonitorAPISymbols/MonitorAPISymbol"); foreach (XmlNode n in nodes) { this.MonitorAPISymbols.Add(new MonitorAPISymbol(n.InnerText)); } // Compose a unique name. TODO: verify valid file and path name string folderName = DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + "_DebugOutput"; this.logDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "CAT", folderName); Directory.CreateDirectory(this.logDirectory); this.Log("Debug Output For: " + this.XboxViewItem.XboxDevice.Name); this.debugOutputWindow.Show(); } }
/// <summary> /// Removes a symbol from API monitoring /// </summary> /// <param name="session">Session associated with symbol to remove</param> private void RemoveSymbol(DebugOutputMonitorAPISession session) { string symbolName = session.MonitorAPISession.SymbolName; this.MonitorAPISessions.Remove(session); session.MonitorAPISession.Dispose(); foreach (MonitorAPISymbol symbol in this.MonitorAPISymbols) { if (symbol.SymbolName == symbolName) { symbol.IsAvailable = true; break; } } }
/// <summary> /// Resets the called status of a symbol /// </summary> /// <param name="session">Session associated with the symbol to reset the called status of</param> private void ResetCalled(DebugOutputMonitorAPISession session) { session.MonitorAPISession.WasCalled = false; }