/[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 313 - (show annotations) (download)
Sun Dec 26 16:21:07 2010 UTC (9 years, 9 months ago) by william
File size: 20925 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4151 local: v0.9.7.293-latest) in ./trunk
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 frmMain.treeGifPacketContent.Enabled = frmMain.chkDebugMode.Checked;
180 if (frmMain.chkDebugMode.Checked == false)
181 frmMain.treTreeView.Nodes.Clear();
182
183 }), new object[] { null });
184 break;
185 case MessageType.DebugState:
186 frmMain.Invoke(new Action<object>(delegate(object e)
187 {
188 frmMain.treTreeView.Nodes.Clear();
189 List<TreeNode> parents = new List<TreeNode>();
190 List<TreeNode> nodes = new List<TreeNode>();
191 foreach (var itm in Mess.Parameters)
192 {
193 String[] parts = itm.ToString().Split(new char[] { '|' });
194 switch (parts[1])
195 {
196 case "Transfer":
197 TreeNode tn2 = new TreeNode();
198 tn2.Name = parts[0];
199 tn2.Text = parts[0] + " - " + parts[1] + " - " + parts[2] + " - " + parts[3] + " byte";
200 nodes.Add(tn2);
201 break;
202 case "ReadFIFO2":
203 TreeNode tn3 = new TreeNode();
204 tn3.Name = parts[0];
205 tn3.Text = parts[0] + " - " + parts[1] + " - " + parts[2] + " byte";
206 nodes.Add(tn3);
207 break;
208 case "VSync":
209 TreeNode tn = new TreeNode();
210 tn.Name = parts[0];
211 tn.Text = parts[0] + " - " + parts[1] + " - " + parts[2] + " byte";
212 tn.Nodes.AddRange(nodes.ToArray());
213 parents.Add(tn);
214
215 nodes.Clear();
216 break;
217 case "Registers":
218 TreeNode tn4 = new TreeNode();
219 tn4.Name = parts[0];
220 tn4.Text = parts[0] + " - " + parts[1] + " - " + parts[2] + " byte";
221 nodes.Add(tn4);
222 break;
223 }
224 }
225 frmMain.treTreeView.Nodes.AddRange(parents.ToArray());
226 }), new object[] { null });
227 break;
228 case MessageType.Step:
229 case MessageType.RunToCursor:
230 frmMain.Invoke(new Action<object>(delegate(object e)
231 {
232 int idtoselect = (int)Mess.Parameters[0];
233 TreeNode[] noes = frmMain.treTreeView.Nodes.Find(idtoselect.ToString(), true);
234 if (noes.Length > 0)
235 {
236 if (CurrentNode != null)
237 CurrentNode.BackColor = Color.White;
238 noes[0].BackColor = Color.LightBlue;
239 CurrentNode = noes[0];
240 frmMain.treTreeView.SelectedNode = noes[0];
241 }
242 }), new object[] { null });
243 break;
244 case MessageType.PacketInfo:
245 frmMain.Invoke(new Action<object>(delegate(object e)
246 {
247 if (Mess.Parameters[0].ToString() != "No Data Available")
248 {
249 string[] vals = Mess.Parameters[0].ToString().Split('|');
250 frmMain.txtGifPacketSize.Text = vals[0] + " bytes";
251
252 frmMain.treeGifPacketContent.Nodes.Clear();
253
254 frmMain.treeGifPacketContent.Nodes.Add(vals[1]);
255
256 if (vals.Length > 2)
257 {
258 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(vals[2]);
259 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(vals[3]);
260 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(vals[4]);
261 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(vals[5]);
262
263 TreeNode nodePrim = new TreeNode("Prim");
264 string[] prim = vals[6].Split('~');
265 for (int j = 1; j < prim.Length; j++)
266 {
267 nodePrim.Nodes.Add(prim[j]);
268 }
269 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(nodePrim);
270
271 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(vals[7]);
272
273 TreeNode nodeReg = new TreeNode("reg");
274 string[] reg = vals[8].Split(new char[]{'~'}, StringSplitOptions.RemoveEmptyEntries);
275 for (int j = 1; j < reg.Length; j++)
276 {
277 string[] fvals = reg[j].Split(new char[] { '@' }, StringSplitOptions.RemoveEmptyEntries);
278 TreeNode nodeObj = new TreeNode(fvals[0]);
279 for (int z = 1; z < fvals.Length; z++)
280 {
281 TreeNode item = new TreeNode(fvals[z]);
282 nodeObj.Nodes.Add(item);
283 }
284 nodeReg.Nodes.Add(nodeObj);
285 }
286 frmMain.treeGifPacketContent.Nodes[0].Nodes.Add(nodeReg);
287 }
288 frmMain.treeGifPacketContent.Nodes[0].ExpandAll();
289 }
290 else
291 {
292 frmMain.treeGifPacketContent.Nodes.Clear();
293
294 frmMain.treeGifPacketContent.Nodes.Add(Mess.Parameters[0].ToString());
295 }
296 }), new object[] { null });
297 break;
298 default:
299 break;
300 }
301 }
302
303 static void Client_OnMessageReceived(TCPLibrary.Core.Client sender, TCPLibrary.MessageBased.Core.TCPMessage Mess)
304 {
305 TCPMessage msg;
306 switch (Mess.MessageType)
307 {
308 case TCPLibrary.MessageBased.Core.MessageType.Connect:
309 break;
310 case TCPLibrary.MessageBased.Core.MessageType.MaxUsers:
311 break;
312 case TCPLibrary.MessageBased.Core.MessageType.SizeDump:
313 SendDumpSize();
314 break;
315 case MessageType.Statistics:
316 SendStatistics();
317 break;
318 case MessageType.SetDebugMode:
319 wrap.DebugMode = (Boolean)Mess.Parameters[0];
320
321 msg = new TCPMessage();
322 msg.MessageType = MessageType.GetDebugMode;
323 msg.Parameters.Add(wrap.DebugMode);
324 Client.Send(msg);
325
326 if (wrap.DebugMode)
327 {
328 msg = new TCPMessage();
329 msg.MessageType = MessageType.DebugState;
330 msg.Parameters.AddRange(wrap.GetGifPackets(dump));
331 Client.Send(msg);
332
333 msg = new TCPMessage();
334 msg.MessageType = MessageType.Step;
335 msg.Parameters.Add(dump.Data.FindIndex(a => a == wrap.CurrentGIFPacket));
336 Client.Send(msg);
337 }
338 break;
339 case MessageType.GetDebugMode:
340 msg = new TCPMessage();
341 msg.MessageType = MessageType.GetDebugMode;
342 msg.Parameters.Add(wrap.DebugMode);
343 Client.Send(msg);
344
345 if (wrap.DebugMode)
346 {
347 msg = new TCPMessage();
348 msg.MessageType = MessageType.DebugState;
349 msg.Parameters.AddRange(wrap.GetGifPackets(dump));
350 Client.Send(msg);
351
352 msg = new TCPMessage();
353 msg.MessageType = MessageType.Step;
354 msg.Parameters.Add(dump.Data.FindIndex(a => a == wrap.CurrentGIFPacket));
355 Client.Send(msg);
356 }
357 break;
358
359 case MessageType.PacketInfo:
360 int id = (int)Mess.Parameters[0];
361 msg = new TCPMessage();
362 msg.MessageType = MessageType.PacketInfo;
363 msg.Parameters.Add(wrap.GetGifPacketInfo(dump, id));
364 Client.Send(msg);
365 break;
366 case MessageType.Step:
367 case MessageType.RunToCursor:
368 case MessageType.RunToNextVSync:
369 wrap.ExternalEvent.WaitOne();
370 wrap.ExternalEvent.Reset();
371 wrap.QueueMessage.Enqueue(Mess);
372 wrap.ThereIsWork = true;
373 break;
374 default:
375 break;
376 }
377 }
378
379 private static void SendDumpSize()
380 {
381 TCPMessage msg;
382 msg = new TCPMessage();
383 msg.MessageType = MessageType.SizeDump;
384 if (dump != null)
385 msg.Parameters.Add(dump.Size);
386 else
387 msg.Parameters.Add(0);
388 Client.Send(msg);
389 }
390
391 private static void SendStatistics()
392 {
393 TCPMessage msg;
394 msg = new TCPMessage();
395 msg.MessageType = MessageType.Statistics;
396 if (dump != null)
397 {
398 msg.Parameters.Add(dump.Data.Count);
399 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 0 && (a.data[0] == 3 || a.data[0] == 0)).Count);
400 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 0 && a.data[0] == 1).Count);
401 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 0 && a.data[0] == 2).Count);
402 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 1).Count);
403 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 2).Count);
404 msg.Parameters.Add(dump.Data.FindAll(a => (int)a.id == 3).Count);
405 }
406 else
407 {
408 msg.Parameters.Add(0);
409 msg.Parameters.Add(0);
410 msg.Parameters.Add(0);
411 msg.Parameters.Add(0);
412 msg.Parameters.Add(0);
413 msg.Parameters.Add(0);
414 msg.Parameters.Add(0);
415 }
416 Client.Send(msg);
417 }
418
419 static void Server_OnClientAfterConnect(TCPLibrary.Core.Server server, TCPLibrary.Core.ClientS sender)
420 {
421 Clients.Add((TCPLibrary.MessageBased.Core.BaseMessageClientS)sender);
422 RefreshList(true);
423 }
424
425 private static void RefreshList(bool SelectLast)
426 {
427 frmMain.Invoke(new Action<object>( delegate(object e)
428 {
429 frmMain.lstProcesses.Items.Clear();
430
431 foreach (var itm in Clients)
432 {
433 frmMain.lstProcesses.Items.Add(itm.IPAddress);
434 }
435 if (SelectLast)
436 frmMain.lstProcesses.SelectedIndex = frmMain.lstProcesses.Items.Count - 1;
437 if (frmMain.lstProcesses.SelectedIndex == -1)
438 {
439 frmMain.chkDebugMode.Checked = false;
440 frmMain.lblGif.Enabled = frmMain.chkDebugMode.Checked;
441 frmMain.btnRunToSelection.Enabled = frmMain.chkDebugMode.Checked;
442 frmMain.treTreeView.Enabled = frmMain.chkDebugMode.Checked;
443 frmMain.btnStep.Enabled = frmMain.chkDebugMode.Checked;
444 frmMain.cmdGoToStart.Enabled = frmMain.chkDebugMode.Checked;
445 frmMain.cmdGoToNextVSync.Enabled = frmMain.chkDebugMode.Checked;
446 frmMain.treTreeView.Nodes.Clear();
447 frmMain.treeGifPacketContent.Nodes.Clear();
448 }
449 }), new object[] { null});
450 }
451 }
452 }

  ViewVC Help
Powered by ViewVC 1.1.22