1 |
#define FORCE_ALL_LOGGING_FLAGS // when defined will force logging flags to ALL |
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.ComponentModel; |
5 |
using System.Data; |
6 |
using System.Drawing; |
7 |
using System.Linq; |
8 |
using System.Text; |
9 |
using System.Windows.Forms; |
10 |
using RomCheater.Logging; |
11 |
using RomCheater.Properties; |
12 |
using RomCheater.UserSettingsSupport; |
13 |
using RomCheater.PluginFramework.Core; |
14 |
using System.Diagnostics; |
15 |
using RomCheater.PluginFramework.Interfaces; |
16 |
using WeifenLuo.WinFormsUI.Docking; |
17 |
using RomCheater.Docking; |
18 |
|
19 |
namespace RomCheater |
20 |
{ |
21 |
public partial class Main : Form |
22 |
{ |
23 |
private Process Proc = new Process(); |
24 |
private DeserializeDockContent m_deserializeDockContent; |
25 |
private FloatingLogWindow m_LogWindow = new FloatingLogWindow(); |
26 |
private FloatingAboutBox m_AboutBox = new FloatingAboutBox(); |
27 |
private FloatingRamDumperDialog m_RamDump = new FloatingRamDumperDialog(); |
28 |
private PIDSelector m_PIDSelector = new PIDSelector(); |
29 |
//private bool log_window_expanded = false; |
30 |
//private double log_window_splitter_default_position = 1.4045; |
31 |
PluginLoader loader = null; |
32 |
IConfigPlugin ConfigPlugin = null; |
33 |
IInputPlugin InputPlugin = null; |
34 |
IWindowPlugin WindowPlugin = null; |
35 |
static Main() { SettingSubscriber.AddSubscriber(new Main(), Settings.Default); } |
36 |
private const string t = "RomCheater"; |
37 |
#region LogWriterSupport |
38 |
static LogWriter _LoggerInstance; |
39 |
static LogWriter LoggerInstance |
40 |
{ |
41 |
get { return _LoggerInstance; } |
42 |
set { _LoggerInstance = value; } |
43 |
} |
44 |
#endregion |
45 |
|
46 |
|
47 |
private void OnProcessChanged(object sender, ProcessChangedEventArgs e) |
48 |
{ |
49 |
Proc = Process.GetProcessById(e.ProcessID); |
50 |
} |
51 |
|
52 |
#region Dock Support |
53 |
private IDockContent GetContentFromPersistString(string persistString) |
54 |
{ |
55 |
if (persistString == typeof(FloatingLogWindow).ToString()) |
56 |
{ |
57 |
return m_LogWindow; |
58 |
} |
59 |
if (persistString == typeof(FloatingAboutBox).ToString()) |
60 |
{ |
61 |
return m_AboutBox; |
62 |
} |
63 |
if (persistString == typeof(FloatingRamDumperDialog).ToString()) |
64 |
{ |
65 |
return m_RamDump; |
66 |
} |
67 |
else |
68 |
{ |
69 |
// not sure if this is appropriate |
70 |
return null; |
71 |
} |
72 |
} |
73 |
public void SetupDocks() |
74 |
{ |
75 |
m_LogWindow = new FloatingLogWindow(); |
76 |
m_AboutBox = new FloatingAboutBox(); |
77 |
m_RamDump = new FloatingRamDumperDialog(); |
78 |
m_PIDSelector = new PIDSelector(); |
79 |
m_PIDSelector.OnSelectedProcessChanged += new EventHandler<ProcessChangedEventArgs>(OnProcessChanged); |
80 |
m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString); |
81 |
} |
82 |
public void ShowDocks() |
83 |
{ |
84 |
ShowLogWindow(); |
85 |
ShowRamDump(); |
86 |
ShowPidSelector(); |
87 |
} |
88 |
public void ShowLogWindow() |
89 |
{ |
90 |
m_LogWindow.Show(dockPanel); |
91 |
} |
92 |
public void ShowAboutBox() |
93 |
{ |
94 |
m_AboutBox.ShowDialog(); |
95 |
} |
96 |
public void ShowRamDump() |
97 |
{ |
98 |
m_RamDump.Show(dockPanel); |
99 |
} |
100 |
public void ShowPidSelector() |
101 |
{ |
102 |
//List<Process> procs = ConfigPlugin.ValidProcessesForPlugin; |
103 |
m_PIDSelector = new PIDSelector(ConfigPlugin); |
104 |
m_PIDSelector.OnSelectedProcessChanged += new EventHandler<ProcessChangedEventArgs>(OnProcessChanged); |
105 |
m_PIDSelector.Show(dockPanel); |
106 |
} |
107 |
#endregion |
108 |
|
109 |
|
110 |
public Main() : this(false) { } |
111 |
public Main(bool no_console_redirect) |
112 |
{ |
113 |
InitializeComponent(); |
114 |
load_loggerflags(); |
115 |
SetupDocks(); |
116 |
LoggerInstance = m_LogWindow.Logwriter; |
117 |
LoggerInstance.CreateNewLog(false); |
118 |
logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name); |
119 |
load_plugins(); |
120 |
if (no_console_redirect) |
121 |
LoggerInstance.RedirectConsoleOutput = false; |
122 |
|
123 |
} |
124 |
private void load_loggerflags() |
125 |
{ |
126 |
logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags); |
127 |
#if FORCE_ALL_LOGGING_FLAGS |
128 |
logger.SetLoggingFlags(loggerflags.ALL); |
129 |
#endif |
130 |
} |
131 |
private void load_plugins() |
132 |
{ |
133 |
loader = new PluginLoader(); |
134 |
loader.LoadPlugins(); |
135 |
|
136 |
ConfigPlugin = loader.GetConfigPlugin(RomCheater.Properties.Settings.Default.LastConfigPlugin); |
137 |
if (ConfigPlugin != null) |
138 |
logger.Info.WriteLine("Loaded Config Plugin: {0}", ConfigPlugin.ToString()); |
139 |
InputPlugin = loader.GetInputPlugin(RomCheater.Properties.Settings.Default.LastInputPlugin); |
140 |
if (InputPlugin != null) |
141 |
logger.Info.WriteLine("Loaded Input Plugin: {0}", InputPlugin.ToString()); |
142 |
WindowPlugin = loader.GetWindowPlugin(RomCheater.Properties.Settings.Default.LastWindowPlugin); |
143 |
if (WindowPlugin != null) |
144 |
logger.Info.WriteLine("Loaded Window Plugin: {0}", WindowPlugin.ToString()); |
145 |
|
146 |
} |
147 |
|
148 |
private void mnuItemExit_Click(object sender, EventArgs e) |
149 |
{ |
150 |
this.Close(); |
151 |
} |
152 |
|
153 |
private void btnCopyLogToClipboard_Click(object sender, EventArgs e) |
154 |
{ |
155 |
|
156 |
} |
157 |
|
158 |
private void Main_Load(object sender, EventArgs e) |
159 |
{ |
160 |
|
161 |
} |
162 |
|
163 |
private void mnuItemConfig_Click(object sender, EventArgs e) |
164 |
{ |
165 |
RomCheaterConfigDialog dlg = new RomCheaterConfigDialog(loader); |
166 |
dlg.ShowDialog(); |
167 |
// reload plugins |
168 |
load_plugins(); |
169 |
} |
170 |
|
171 |
private void mnuItemOpenProcess_Click(object sender, EventArgs e) |
172 |
{ |
173 |
////List<Process> procs = ConfigPlugin.ValidProcessesForPlugin; |
174 |
//PIDSelector selector = new PIDSelector(ConfigPlugin); |
175 |
//selector.ShowDialog(); |
176 |
} |
177 |
|
178 |
private void Main_Shown(object sender, EventArgs e) |
179 |
{ |
180 |
ShowDocks(); |
181 |
} |
182 |
|
183 |
private void mnuItemShowLogWindow_Click(object sender, EventArgs e) |
184 |
{ |
185 |
ShowLogWindow(); |
186 |
} |
187 |
|
188 |
private void mnuItemHelpAbout_Click(object sender, EventArgs e) |
189 |
{ |
190 |
ShowAboutBox(); |
191 |
} |
192 |
|
193 |
private void mnuItemShowRamDumpDialog_Click(object sender, EventArgs e) |
194 |
{ |
195 |
ShowRamDump(); |
196 |
} |
197 |
|
198 |
private void mnuItemShowPIDSelector_Click(object sender, EventArgs e) |
199 |
{ |
200 |
ShowPidSelector(); |
201 |
} |
202 |
} |
203 |
} |