/[pcsx2_0.9.7]/trunk/tools/GSDumpGUI/Forms/frmMain.cs
ViewVC logotype

Contents of /trunk/tools/GSDumpGUI/Forms/frmMain.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 290 - (show annotations) (download)
Sat Dec 25 02:51:30 2010 UTC (9 years ago) by william
File size: 18102 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4139 local: v0.9.7.283-latest) in ./trunk
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.IO;
9 using System.Runtime.InteropServices;
10 using System.Threading;
11 using System.Diagnostics;
12 using System.Security;
13 using TCPLibrary.MessageBased.Core;
14
15 namespace GSDumpGUI
16 {
17 public partial class GSDumpGUI : Form
18 {
19 public List<Process> Processes;
20
21 private Int32 _selected;
22 public Int32 SelectedRad
23 {
24 get { return _selected; }
25 set
26 {
27 if (value > 4)
28 value = 0;
29 _selected = value;
30 switch (_selected)
31 {
32 case 0:
33 rdaNone.Checked = true;
34 break;
35 case 1:
36 rdaDX9HW.Checked = true;
37 break;
38 case 2:
39 rdaDX10HW.Checked = true;
40 break;
41 case 3:
42 rdaDX9SW.Checked = true;
43 break;
44 case 4:
45 rdaDX10SW.Checked = true;
46 break;
47 }
48 }
49 }
50
51 private Bitmap NoImage;
52
53 public GSDumpGUI()
54 {
55 InitializeComponent();
56 Processes = new List<Process>();
57
58 NoImage = new Bitmap(320, 240, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
59 Graphics g = Graphics.FromImage(NoImage);
60 g.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, 320, 240));
61 g.DrawString("No Image", new Font(FontFamily.GenericSansSerif, 48, FontStyle.Regular), new SolidBrush(Color.White), new PointF(0, 70));
62 g.Dispose();
63 }
64
65 public void ReloadGSDXs()
66 {
67 txtIntLog.Text += "Starting GSDX Loading Procedures" + Environment.NewLine + Environment.NewLine;
68
69 txtGSDXDirectory.Text = Properties.Settings.Default.GSDXDir;
70 txtDumpsDirectory.Text = Properties.Settings.Default.DumpDir;
71
72 lstGSDX.Items.Clear();
73 lstDumps.Items.Clear();
74
75 if (Directory.Exists(txtGSDXDirectory.Text))
76 {
77 String[] File = Directory.GetFiles(txtGSDXDirectory.Text, "*.dll", SearchOption.TopDirectoryOnly);
78
79 GSDXWrapper wrap = new GSDXWrapper();
80 foreach (var itm in File)
81 {
82 if (GSDXWrapper.IsValidGSDX(itm))
83 {
84 wrap.Load(itm);
85
86 lstGSDX.Items.Add(Path.GetFileName(itm) + " | " + wrap.PSEGetLibName());
87 txtIntLog.Text += "\"" + itm + "\" correctly identified as " + wrap.PSEGetLibName() + Environment.NewLine;
88
89 wrap.Unload();
90 }
91 else
92 {
93 txtIntLog.Text += "Failed to load \"" + itm + "\". Is it really a GSDX DLL?" + Environment.NewLine;
94 }
95 }
96 }
97
98 txtIntLog.Text += Environment.NewLine + "Completed GSDX Loading Procedures" + Environment.NewLine + Environment.NewLine;
99
100 txtIntLog.Text += "Starting GSDX Dumps Loading Procedures : " + Environment.NewLine + Environment.NewLine;
101 if (Directory.Exists(txtDumpsDirectory.Text))
102 {
103 String[] Dumps = Directory.GetFiles(txtDumpsDirectory.Text, "*.gs", SearchOption.TopDirectoryOnly);
104
105 foreach (var itm in Dumps)
106 {
107 BinaryReader br = new BinaryReader(System.IO.File.Open(itm, FileMode.Open));
108 Int32 CRC = br.ReadInt32();
109 br.Close();
110 lstDumps.Items.Add(Path.GetFileName(itm) + " | CRC : " + CRC.ToString("X"));
111 txtIntLog.Text += "Identified Dump for game (" + CRC.ToString("X") + ") with filename \"" + itm + "\"" + Environment.NewLine;
112 }
113 }
114 txtIntLog.Text += Environment.NewLine + "Completed GSDX Dumps Loading Procedures : " + Environment.NewLine + Environment.NewLine;
115 txtIntLog.SelectionStart = txtIntLog.TextLength;
116 txtIntLog.ScrollToCaret();
117 }
118
119 private void GSDumpGUI_Load(object sender, EventArgs e)
120 {
121 ReloadGSDXs();
122 lstDumps.Focus();
123 if (lstDumps.Items.Count > 0)
124 lstDumps.SelectedIndex = 0;
125 }
126
127 private void cmdBrowseGSDX_Click(object sender, EventArgs e)
128 {
129 FolderBrowserDialog fbd = new FolderBrowserDialog();
130 fbd.Description = "Select the GSDX DLL Directory";
131 fbd.SelectedPath = AppDomain.CurrentDomain.BaseDirectory;
132 if (fbd.ShowDialog() == DialogResult.OK)
133 txtGSDXDirectory.Text = fbd.SelectedPath;
134 SaveConfig();
135 ReloadGSDXs();
136 }
137
138 private void cmdBrowseDumps_Click(object sender, EventArgs e)
139 {
140 FolderBrowserDialog fbd = new FolderBrowserDialog();
141 fbd.Description = "Select the GSDX Dumps Directory";
142 fbd.SelectedPath = AppDomain.CurrentDomain.BaseDirectory;
143 if (fbd.ShowDialog() == DialogResult.OK)
144 txtDumpsDirectory.Text = fbd.SelectedPath;
145 SaveConfig();
146 ReloadGSDXs();
147 }
148
149 private void cmdStart_Click(object sender, EventArgs e)
150 {
151 // Execute the GSReplay function
152 if (lstDumps.SelectedIndex != -1)
153 {
154 if (lstGSDX.SelectedIndex != -1)
155 ExecuteFunction("GSReplay");
156 else
157 MessageBox.Show("Select your GSDX first", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
158 }
159 else
160 MessageBox.Show("Select your Dump first", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
161 }
162
163 private void ExecuteFunction(String Function)
164 {
165 txtLog.Text = "";
166 String GSDXName = lstGSDX.SelectedItem.ToString().Split(new char[] { '|' })[0];
167
168 CreateDirs(GSDXName);
169
170 // Set the Arguments to pass to the child
171 String DLLPath = Properties.Settings.Default.GSDXDir + "\\" + GSDXName;
172 String DumpPath = "";
173 String SelectedRenderer = "";
174 switch (SelectedRad)
175 {
176 case 0:
177 SelectedRenderer = "-1";
178 break;
179 case 1:
180 SelectedRenderer = "0";
181 break;
182 case 2:
183 SelectedRenderer = "3";
184 break;
185 case 3:
186 SelectedRenderer = "1";
187 break;
188 case 4:
189 SelectedRenderer = "4";
190 break;
191 }
192 if (SelectedRenderer != "-1")
193 {
194 if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\" + GSDXName + "\\inis\\gsdx.ini"))
195 {
196 String ini = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\" + GSDXName + "\\inis\\gsdx.ini");
197 int pos = ini.IndexOf("Renderer=", 0);
198 if (pos != -1)
199 {
200 String newini = ini.Substring(0, pos + 9);
201 newini += SelectedRenderer;
202 newini += ini.Substring(pos + 10, ini.Length - pos - 10);
203 File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\" + GSDXName + "\\inis\\gsdx.ini", newini);
204 }
205 else
206 {
207 File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\" + GSDXName + "\\inis\\gsdx.ini", ini + Environment.NewLine + "Renderer=" + SelectedRenderer);
208 }
209 }
210 }
211 if (lstDumps.SelectedItem != null)
212 DumpPath = Properties.Settings.Default.DumpDir + "\\" +
213 lstDumps.SelectedItem.ToString().Split(new char[] { '|' })[0];
214
215 // Start the child and link the events.
216 ProcessStartInfo psi = new ProcessStartInfo();
217 psi.UseShellExecute = false;
218 psi.RedirectStandardOutput = true;
219 psi.RedirectStandardError = false;
220 psi.CreateNoWindow = true;
221 psi.FileName = AppDomain.CurrentDomain.BaseDirectory + "GsDumpGUI.exe";
222 psi.Arguments = "\"" + DLLPath + "\"" + " \"" + DumpPath + "\"" + " \"" + Function + "\"" + " " + SelectedRenderer;
223 Process p = Process.Start(psi);
224 p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
225 p.BeginOutputReadLine();
226 p.Exited += new EventHandler(p_Exited);
227 Processes.Add(p);
228 }
229
230 private static void CreateDirs(String GSDXName)
231 {
232 // Create and set the config directory.
233 String Dir = AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\";
234 if (!Directory.Exists(Dir))
235 {
236 Directory.CreateDirectory(Dir);
237 }
238 Dir += GSDXName;
239 if (!Directory.Exists(Dir))
240 {
241 Directory.CreateDirectory(Dir);
242 }
243 Dir += "\\Inis\\";
244 if (!Directory.Exists(Dir))
245 {
246 Directory.CreateDirectory(Dir);
247 File.Create(Dir + "\\gsdx.ini").Close();
248 }
249 Dir = AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\" + GSDXName;
250 Directory.SetCurrentDirectory(Dir);
251 }
252
253 void p_Exited(object sender, EventArgs e)
254 {
255 // Remove the child if is closed
256 Processes.Remove((Process)sender);
257 }
258
259 void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
260 {
261 // Write the log.
262 txtLog.Invoke(new Action<object>(delegate(object o)
263 {
264 txtLog.Text += e.Data + Environment.NewLine;
265 txtLog.SelectionStart = txtLog.Text.Length - 1;
266 txtLog.ScrollToCaret();
267 }), new object[] { null });
268 }
269
270 private void cmdConfigGSDX_Click(object sender, EventArgs e)
271 {
272 // Execute the GSconfigure function
273 if (lstGSDX.SelectedIndex != -1)
274 ExecuteFunction("GSconfigure");
275 else
276 MessageBox.Show("Select your GSDX first", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
277 }
278
279 private void cmdOpenIni_Click(object sender, EventArgs e)
280 {
281 // Execute the GSconfigure function
282 if (lstGSDX.SelectedIndex != -1)
283 {
284 String GSDXName = lstGSDX.SelectedItem.ToString().Split(new char[] { '|' })[0];
285 CreateDirs(GSDXName);
286 Process.Start(AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\" + GSDXName + "\\inis\\gsdx.ini");
287 }
288 else
289 MessageBox.Show("Select your GSDX first", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
290 }
291
292 private void lstDumps_SelectedIndexChanged(object sender, EventArgs e)
293 {
294 if (lstDumps.SelectedIndex != -1)
295 {
296 String DumpFileName = lstDumps.SelectedItem.ToString().Split(new char[] { '|' })[0];
297 String Filename = Path.GetDirectoryName(Properties.Settings.Default.DumpDir + "\\") +
298 "\\" + Path.GetFileNameWithoutExtension(DumpFileName) + ".bmp";
299 if (File.Exists(Filename))
300 {
301 pctBox.Image = Image.FromFile(Filename);
302 pctBox.Cursor = Cursors.Hand;
303 }
304 else
305 {
306 pctBox.Image = NoImage;
307 pctBox.Cursor = Cursors.Default;
308 }
309 }
310 }
311
312 private void pctBox_Click(object sender, EventArgs e)
313 {
314 if (pctBox.Cursor == Cursors.Hand)
315 {
316 String DumpFileName = lstDumps.SelectedItem.ToString().Split(new char[] { '|' })[0];
317 String Filename = Path.GetDirectoryName(Properties.Settings.Default.DumpDir + "\\") +
318 "\\" + Path.GetFileNameWithoutExtension(DumpFileName) + ".bmp";
319 Process.Start(Filename);
320 }
321 }
322
323 private void GSDumpGUI_KeyDown(object sender, KeyEventArgs e)
324 {
325 if (e.KeyCode == Keys.Return)
326 cmdStart_Click(sender, e);
327
328 if (e.KeyCode == Keys.F1)
329 cmdConfigGSDX_Click(sender, e);
330
331 if ((e.KeyCode == Keys.F2))
332 SelectedRad++;
333 }
334
335 private void rda_CheckedChanged(object sender, EventArgs e)
336 {
337 RadioButton itm = ((RadioButton)(sender));
338 if (itm.Checked == true)
339 SelectedRad = Convert.ToInt32(itm.Tag);
340 }
341
342 private void txtGSDXDirectory_Leave(object sender, EventArgs e)
343 {
344 SaveConfig();
345 ReloadGSDXs();
346 }
347
348 private void txtDumpsDirectory_Leave(object sender, EventArgs e)
349 {
350 SaveConfig();
351 ReloadGSDXs();
352 }
353
354 private void SaveConfig()
355 {
356 Properties.Settings.Default.GSDXDir = txtGSDXDirectory.Text;
357 Properties.Settings.Default.DumpDir = txtDumpsDirectory.Text;
358 Properties.Settings.Default.Save();
359 }
360
361 private void lstProcesses_SelectedIndexChanged(object sender, EventArgs e)
362 {
363 if (lstProcesses.SelectedIndex != -1)
364 {
365 chkDebugMode.Enabled = true;
366
367 TCPMessage msg = new TCPMessage();
368 msg.MessageType = MessageType.GetDebugMode;
369 msg.Parameters.Add(chkDebugMode.Checked);
370 Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg);
371
372 msg = new TCPMessage();
373 msg.MessageType = MessageType.SizeDump;
374 Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg);
375
376 msg = new TCPMessage();
377 msg.MessageType = MessageType.Statistics;
378 Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg);
379 }
380 else
381 {
382 chkDebugMode.Enabled = false;
383 }
384 }
385
386 private void chkDebugMode_CheckedChanged(object sender, EventArgs e)
387 {
388 if (lstProcesses.SelectedIndex != -1)
389 {
390 TCPMessage msg = new TCPMessage();
391 msg.MessageType = MessageType.SetDebugMode;
392 msg.Parameters.Add(chkDebugMode.Checked);
393 Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg);
394 }
395 }
396
397 private void btnStep_Click(object sender, EventArgs e)
398 {
399 TCPMessage msg = new TCPMessage();
400 msg.MessageType = MessageType.Step;
401 Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg);
402 }
403
404 private void btnRunToSelection_Click(object sender, EventArgs e)
405 {
406 if (treTreeView.SelectedNode != null)
407 {
408 TCPMessage msg = new TCPMessage();
409 msg.MessageType = MessageType.RunToCursor;
410 msg.Parameters.Add(Convert.ToInt32(treTreeView.SelectedNode.Text.Split(new string[]{" - "}, StringSplitOptions.None)[0]));
411 Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg);
412 }
413 else
414 MessageBox.Show("You have not selected a node to jump to");
415 }
416
417 private void cmdGoToStart_Click(object sender, EventArgs e)
418 {
419 TCPMessage msg = new TCPMessage();
420 msg.MessageType = MessageType.RunToCursor;
421 msg.Parameters.Add(0);
422 Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg);
423 }
424
425 private void cmdGoToNextVSync_Click(object sender, EventArgs e)
426 {
427 TCPMessage msg = new TCPMessage();
428 msg.MessageType = MessageType.RunToNextVSync;
429 Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg);
430 }
431
432 private void treTreeView_AfterSelect(object sender, TreeViewEventArgs e)
433 {
434 if (treTreeView.SelectedNode != null)
435 {
436 TCPMessage msg = new TCPMessage();
437 msg.MessageType = MessageType.PacketInfo;
438 msg.Parameters.Add(Convert.ToInt32(treTreeView.SelectedNode.Text.Split(new string[] { " - " }, StringSplitOptions.None)[0]));
439 Program.Clients.Find(a => a.IPAddress == lstProcesses.SelectedItem.ToString()).Send(msg);
440 }
441 treTreeView.SelectedNode = e.Node;
442 }
443 }
444 }

  ViewVC Help
Powered by ViewVC 1.1.22