/[pcsx2_0.9.7]/trunk/tools/GSDumpGUI/Core/Program.cs
ViewVC logotype

Contents of /trunk/tools/GSDumpGUI/Core/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 1 month ago) by william
File size: 17265 byte(s)
re-commit (had local access denied errors when committing)
1 using System;
2 using System.Collections.Generic;
3 using System.Windows.Forms;
4 using Specialized = System.Collections.Specialized;
5 using Reflection = System.Reflection;
6 using System.Runtime.InteropServices;
7 using System.Threading;
8 using System.Diagnostics;
9 using GSDumpGUI.Properties;
10 using System.IO;
11 using TCPLibrary.MessageBased.Core;
12 using System.Drawing;
13
14 namespace GSDumpGUI
15 {
16 static class Program
17 {
18 static public GSDumpGUI frmMain;
19 static public TCPLibrary.MessageBased.Core.BaseMessageServer Server;
20 static public List<TCPLibrary.MessageBased.Core.BaseMessageClientS> Clients;
21
22 static public TCPLibrary.MessageBased.Core.BaseMessageClient Client;
23 static private Boolean ChangeIcon;
24 static private GSDump dump;
25 static private GSDXWrapper wrap;
26
27 static private TreeNode CurrentNode;
28
29 [STAThread]
30 static void Main(String[] args)
31 {
32 if (args.Length == 4)
33 {
34 // do this first, else racy mess ;)
35 wrap = new GSDXWrapper();
36
37 try
38 {
39 Client = new TCPLibrary.MessageBased.Core.BaseMessageClient();
40 Client.OnMessageReceived += new TCPLibrary.MessageBased.Core.BaseMessageClient.MessageReceivedHandler(Client_OnMessageReceived);
41 Client.Connect("localhost", 9999);
42 }
43 catch (Exception)
44 {
45 Client = null;
46 }
47
48 Thread thd = new Thread(new ThreadStart(delegate
49 {
50 while (true)
51 {
52 IntPtr pt = Process.GetCurrentProcess().MainWindowHandle;
53 if (ChangeIcon)
54 {
55 if (pt.ToInt64() != 0)
56 {
57 NativeMethods.SetClassLong(pt, -14, Resources.AppIcon.Handle.ToInt64());
58 ChangeIcon = false;
59 }
60 }
61
62 Int32 tmp = NativeMethods.GetAsyncKeyState(0x1b) & 0xf;
63 if (tmp != 0)
64 Process.GetCurrentProcess().Kill();
65 Thread.Sleep(16);
66 }
67 }));
68 thd.IsBackground = true;
69 thd.Start();
70
71 // Retrieve parameters
72 String DLLPath = args[0];
73 String DumpPath = args[1];
74 String Operation = args[2];
75 Int32 Renderer = Convert.ToInt32(args[3]);
76
77 wrap.Load(DLLPath);
78 Directory.SetCurrentDirectory(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\" + Path.GetFileName(DLLPath) + "\\"));
79 if (Operation == "GSReplay")
80 {
81 dump = GSDump.LoadDump(DumpPath);
82
83 if (Client != null)
84 {
85 SendStatistics();
86 SendDumpSize();
87 }
88
89 wrap.Run(dump, Renderer);
90 ChangeIcon = true;
91 }
92 else
93 wrap.GSConfig();
94 wrap.Unload();
95
96 if (GSDXWrapper.DumpTooOld)
97 {
98 if (Client != null)
99 {
100 TCPMessage msg = new TCPMessage();
101 msg.MessageType = MessageType.StateOld;
102 Client.Send(msg);
103 }
104 }
105
106 if (Client != null)
107 Client.Disconnect();
108 }
109 else
110 {
111 Clients = new List<TCPLibrary.MessageBased.Core.BaseMessageClientS>();
112
113 Server = new TCPLibrary.MessageBased.Core.BaseMessageServer();
114 Server.OnClientMessageReceived += new BaseMessageServer.MessageReceivedHandler(Server_OnClientMessageReceived);
115 Server.OnClientAfterConnect += new TCPLibrary.Core.Server.ConnectedHandler(Server_OnClientAfterConnect);
116 Server.OnClientAfterDisconnected += new TCPLibrary.Core.Server.DisconnectedHandler(Server_OnClientAfterDisconnected);
117 Server.Port = 9999;
118 Server.Enabled = true;
119
120 Application.EnableVisualStyles();
121 Application.SetCompatibleTextRenderingDefault(false);
122 frmMain = new GSDumpGUI();
123 Application.Run(frmMain);
124
125 Server.Enabled = false;
126 }
127 }
128
129 static void Server_OnClientAfterDisconnected(TCPLibrary.Core.Server server, TCPLibrary.Core.ClientS sender)
130 {
131 Clients.Remove((TCPLibrary.MessageBased.Core.BaseMessageClientS)sender);
132 RefreshList(false);
133 }
134
135 static void Server_OnClientMessageReceived(BaseMessageServer server, BaseMessageClientS sender, TCPMessage Mess)
136 {
137 switch (Mess.MessageType)
138 {
139 case MessageType.Connect:
140 break;
141 case MessageType.MaxUsers:
142 break;
143 case MessageType.SizeDump:
144 frmMain.Invoke(new Action<object>(delegate(object e)
145 {
146 frmMain.txtDumpSize.Text = (((int)Mess.Parameters[0]) / 1024f / 1024f).ToString("F2") + " MB";
147 }), new object[] { null });
148 break;
149 case MessageType.Statistics:
150 frmMain.Invoke(new Action<object>(delegate(object e)
151 {
152 frmMain.txtGIFPackets.Text = ((int)Mess.Parameters[0]).ToString();
153 frmMain.txtPath1.Text = ((int)Mess.Parameters[1]).ToString();
154 frmMain.txtPath2.Text = ((int)Mess.Parameters[2]).ToString();
155 frmMain.txtPath3.Text = ((int)Mess.Parameters[3]).ToString();
156 frmMain.txtReadFifo.Text = ((int)Mess.Parameters[5]).ToString();
157 frmMain.txtVSync.Text = ((int)Mess.Parameters[4]).ToString();
158 frmMain.txtRegisters.Text = ((int)Mess.Parameters[6]).ToString();
159 }), new object[] { null });
160 break;
161 case MessageType.StateOld:
162 frmMain.Invoke(new Action<object>(delegate(object e)
163 {
164 MessageBox.Show("Savestate too old to be read. :(", "Warning");
165 frmMain.Focus();
166 }), new object[] { null });
167 break;
168 case MessageType.GetDebugMode:
169 frmMain.Invoke(new Action<object>(delegate(object e)
170 {
171 frmMain.chkDebugMode.Checked = (Boolean)Mess.Parameters[0];
172
173 frmMain.lblGif.Enabled = frmMain.chkDebugMode.Checked;
174 frmMain.btnRunToSelection.Enabled = frmMain.chkDebugMode.Checked;
175 frmMain.treTreeView.Enabled = frmMain.chkDebugMode.Checked;
176 frmMain.btnStep.Enabled = frmMain.chkDebugMode.Checked;
177 frmMain.cmdGoToStart.Enabled = frmMain.chkDebugMode.Checked;
178 frmMain.cmdGoToNextVSync.Enabled = frmMain.chkDebugMode.Checked;
179 if (frmMain.chkDebugMode.Checked == false)
180 frmMain.treTreeView.Nodes.Clear();
181
182 }), new object[] { null });
183 break;
184 case MessageType.DebugState:
185 frmMain.Invoke(new Action<object>(delegate(object e)
186 {
187 frmMain.treTreeView.Nodes.Clear();
188 List<TreeNode> parents = new List<TreeNode>();
189 List<TreeNode> nodes = new List<TreeNode>();
190 foreach (var itm in Mess.Parameters)
191 {
192 String[] parts = itm.ToString().Split(new char[] { '|' });
193 switch (parts[1])
194 {
195 case "Transfer":
196 TreeNode tn2 = new TreeNode();
197 tn2.Name = parts[0];
198 tn2.Text = parts[0] + " - " + parts[1] + " - " + parts[2];
199 nodes.Add(tn2);
200 break;
201 case "ReadFIFO2":
202 TreeNode tn3 = new TreeNode();
203 tn3.Name = parts[0];
204 tn3.Text = parts[0] + " - " + parts[1];
205 nodes.Add(tn3);
206 break;
207 case "VSync":
208 TreeNode tn = new TreeNode();
209 tn.Name = parts[0];
210 tn.Text = parts[0] + " - " + parts[1];
211 tn.Nodes.AddRange(nodes.ToArray());
212 parents.Add(tn);
213
214 nodes.Clear();
215 break;
216 case "Registers":
217 TreeNode tn4 = new TreeNode();
218 tn4.Name = parts[0];
219 tn4.Text = parts[0] + " - " + parts[1];
220 nodes.Add(tn4);
221 break;
222 }
223 }
224 frmMain.treTreeView.Nodes.AddRange(parents.ToArray());
225 }), new object[] { null });
226 break;
227 case MessageType.Step:
228 case MessageType.RunToCursor:
229 frmMain.Invoke(new Action<object>(delegate(object e)
230 {
231 int idtoselect = (int)Mess.Parameters[0];
232 TreeNode[] noes = frmMain.treTreeView.Nodes.Find(idtoselect.ToString(), true);
233 if (noes.Length > 0)
234 {
235 if (CurrentNode != null)
236 CurrentNode.BackColor = Color.White;
237 noes[0].BackColor = Color.LightBlue;
238 CurrentNode = noes[0];
239 frmMain.treTreeView.SelectedNode = noes[0];
240 }
241 }), new object[] { null });
242 break;
243 default:
244 break;
245 }
246 }
247
248 static void Client_OnMessageReceived(TCPLibrary.Core.Client sender, TCPLibrary.MessageBased.Core.TCPMessage Mess)
249 {
250 TCPMessage msg;
251 switch (Mess.MessageType)
252 {
253 case TCPLibrary.MessageBased.Core.MessageType.Connect:
254 break;
255 case TCPLibrary.MessageBased.Core.MessageType.MaxUsers:
256 break;
257 case TCPLibrary.MessageBased.Core.MessageType.SizeDump:
258 SendDumpSize();
259 break;
260 case MessageType.Statistics:
261 SendStatistics();
262 break;
263 case MessageType.SetDebugMode:
264 wrap.DebugMode = (Boolean)Mess.Parameters[0];
265
266 msg = new TCPMessage();
267 msg.MessageType = MessageType.GetDebugMode;
268 msg.Parameters.Add(wrap.DebugMode);
269 Client.Send(msg);
270
271 if (wrap.DebugMode)
272 {
273 msg = new TCPMessage();
274 msg.MessageType = MessageType.DebugState;
275 msg.Parameters.AddRange(wrap.GetGifPackets(dump));
276 Client.Send(msg);
277
278 msg = new TCPMessage();
279 msg.MessageType = MessageType.Step;
280 msg.Parameters.Add(dump.Data.FindIndex(a => a == wrap.CurrentGIFPacket));
281 Client.Send(msg);
282 }
283 break;
284 case MessageType.GetDebugMode:
285 msg = new TCPMessage();
286 msg.MessageType = MessageType.GetDebugMode;
287 msg.Parameters.Add(wrap.DebugMode);
288 Client.Send(msg);
289
290 if (wrap.DebugMode)
291 {
292 msg = new TCPMessage();
293 msg.MessageType = MessageType.DebugState;
294 msg.Parameters.AddRange(wrap.GetGifPackets(dump));
295 Client.Send(msg);
296
297 msg = new TCPMessage();
298 msg.MessageType = MessageType.Step;
299 msg.Parameters.Add(dump.Data.FindIndex(a => a == wrap.CurrentGIFPacket));
300 Client.Send(msg);
301 }
302 break;
303 case MessageType.Step:
304 case MessageType.RunToCursor:
305 case MessageType.RunToNextVSync:
306 wrap.ExternalEvent.WaitOne();
307 wrap.ExternalEvent.Reset();
308 wrap.QueueMessage.Enqueue(Mess);
309 wrap.ThereIsWork = true;
310 break;
311 default:
312 break;
313 }
314 }
315
316 private static void SendDumpSize()
317 {
318 TCPMessage msg;
319 msg = new TCPMessage();
320 msg.MessageType = MessageType.SizeDump;
321 if (dump != null)
322 msg.Parameters.Add(dump.Size);
323 else
324 msg.Parameters.Add(0);
325 Client.Send(msg);
326 }
327
328 private static void SendStatistics()
329 {
330 TCPMessage msg;
331 msg = new TCPMessage();
332 msg.MessageType = MessageType.Statistics;
333 if (dump != null)
334 {
335 msg.Parameters.Add(dump.Data.Count);
336 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 0 && (a.data[0] == 3 || a.data[0] == 0)).Count);
337 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 0 && a.data[0] == 1).Count);
338 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 0 && a.data[0] == 2).Count);
339 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 1).Count);
340 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 2).Count);
341 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 3).Count);
342 }
343 else
344 {
345 msg.Parameters.Add(0);
346 msg.Parameters.Add(0);
347 msg.Parameters.Add(0);
348 msg.Parameters.Add(0);
349 msg.Parameters.Add(0);
350 msg.Parameters.Add(0);
351 msg.Parameters.Add(0);
352 }
353 Client.Send(msg);
354 }
355
356 static void Server_OnClientAfterConnect(TCPLibrary.Core.Server server, TCPLibrary.Core.ClientS sender)
357 {
358 Clients.Add((TCPLibrary.MessageBased.Core.BaseMessageClientS)sender);
359 RefreshList(true);
360 }
361
362 private static void RefreshList(bool SelectLast)
363 {
364 frmMain.Invoke(new Action<object>( delegate(object e)
365 {
366 frmMain.lstProcesses.Items.Clear();
367
368 foreach (var itm in Clients)
369 {
370 frmMain.lstProcesses.Items.Add(itm.IPAddress);
371 }
372 if (SelectLast)
373 frmMain.lstProcesses.SelectedIndex = frmMain.lstProcesses.Items.Count - 1;
374 if (frmMain.lstProcesses.SelectedIndex == -1)
375 {
376 frmMain.chkDebugMode.Checked = false;
377 frmMain.lblGif.Enabled = frmMain.chkDebugMode.Checked;
378 frmMain.btnRunToSelection.Enabled = frmMain.chkDebugMode.Checked;
379 frmMain.treTreeView.Enabled = frmMain.chkDebugMode.Checked;
380 frmMain.btnStep.Enabled = frmMain.chkDebugMode.Checked;
381 frmMain.cmdGoToStart.Enabled = frmMain.chkDebugMode.Checked;
382 frmMain.cmdGoToNextVSync.Enabled = frmMain.chkDebugMode.Checked;
383 frmMain.treTreeView.Nodes.Clear();
384 }
385 }), new object[] { null});
386 }
387 }
388 }

  ViewVC Help
Powered by ViewVC 1.1.22