/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/tools/GSDumpGUI/Forms/frmMain.cs
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/tools/GSDumpGUI/Forms/frmMain.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (10 years, 9 months ago) by william
File size: 12559 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
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
14 namespace GSDumpGUI
15 {
16 public partial class GSDumpGUI : Form
17 {
18 public List<Process> Processes;
19
20 private Int32 _selected;
21 public Int32 SelectedRad
22 {
23 get { return _selected; }
24 set
25 {
26 if (value > 4)
27 value = 0;
28 _selected = value;
29 switch (_selected)
30 {
31 case 0:
32 rdaNone.Checked = true;
33 break;
34 case 1:
35 rdaDX9HW.Checked = true;
36 break;
37 case 2:
38 rdaDX10HW.Checked = true;
39 break;
40 case 3:
41 rdaDX9SW.Checked = true;
42 break;
43 case 4:
44 rdaDX10SW.Checked = true;
45 break;
46 }
47 }
48 }
49
50 private Bitmap NoImage;
51
52 public GSDumpGUI()
53 {
54 InitializeComponent();
55 Processes = new List<Process>();
56
57 NoImage = new Bitmap(320, 240, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
58 Graphics g = Graphics.FromImage(NoImage);
59 g.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, 320, 240));
60 g.DrawString("No Image", new Font(FontFamily.GenericSansSerif, 48, FontStyle.Regular), new SolidBrush(Color.White), new PointF(0, 70));
61 g.Dispose();
62 }
63
64 public void ReloadGSDXs()
65 {
66 txtGSDXDirectory.Text = Properties.Settings.Default.GSDXDir;
67 txtDumpsDirectory.Text = Properties.Settings.Default.DumpDir;
68
69 lstGSDX.Items.Clear();
70 lstDumps.Items.Clear();
71
72 if (Directory.Exists(txtGSDXDirectory.Text))
73 {
74 String[] File = Directory.GetFiles(txtGSDXDirectory.Text, "*.dll", SearchOption.TopDirectoryOnly);
75
76 GSDXWrapper wrap = new GSDXWrapper();
77 foreach (var itm in File)
78 {
79 if (GSDXWrapper.IsValidGSDX(itm))
80 {
81 wrap.Load(itm);
82 lstGSDX.Items.Add(Path.GetFileName(itm) + " | " + wrap.PSEGetLibName());
83 wrap.Unload();
84 }
85 }
86
87 String[] Dumps = Directory.GetFiles(txtDumpsDirectory.Text, "*.gs", SearchOption.TopDirectoryOnly);
88
89 foreach (var itm in Dumps)
90 {
91 BinaryReader br = new BinaryReader(System.IO.File.Open(itm, FileMode.Open));
92 Int32 CRC = br.ReadInt32();
93 br.Close();
94 lstDumps.Items.Add(Path.GetFileName(itm) + " | CRC : " + CRC.ToString("X"));
95 }
96 }
97 }
98
99 private void GSDumpGUI_Load(object sender, EventArgs e)
100 {
101 ReloadGSDXs();
102 lstDumps.Focus();
103 if (lstDumps.Items.Count > 0)
104 lstDumps.SelectedIndex = 0;
105 }
106
107 private void cmdBrowseGSDX_Click(object sender, EventArgs e)
108 {
109 FolderBrowserDialog fbd = new FolderBrowserDialog();
110 fbd.Description = "Select the GSDX DLL Directory";
111 fbd.SelectedPath = AppDomain.CurrentDomain.BaseDirectory;
112 if (fbd.ShowDialog() == DialogResult.OK)
113 txtGSDXDirectory.Text = fbd.SelectedPath;
114 }
115
116 private void cmdBrowseDumps_Click(object sender, EventArgs e)
117 {
118 FolderBrowserDialog fbd = new FolderBrowserDialog();
119 fbd.Description = "Select the GSDX Dumps Directory";
120 fbd.SelectedPath = AppDomain.CurrentDomain.BaseDirectory;
121 if (fbd.ShowDialog() == DialogResult.OK)
122 txtDumpsDirectory.Text = fbd.SelectedPath;
123 }
124
125 private void cmdSave_Click(object sender, EventArgs e)
126 {
127 if (System.IO.Directory.Exists(txtDumpsDirectory.Text))
128 Properties.Settings.Default.DumpDir = txtDumpsDirectory.Text;
129 else
130 MessageBox.Show("Select a correct directory for dumps", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
131
132 if (System.IO.Directory.Exists(txtGSDXDirectory.Text))
133 Properties.Settings.Default.GSDXDir = txtGSDXDirectory.Text;
134 else
135 MessageBox.Show("Select a correct directory for GSDX", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
136
137 Properties.Settings.Default.Save();
138 ReloadGSDXs();
139 }
140
141 private void cmdStart_Click(object sender, EventArgs e)
142 {
143 // Execute the GSReplay function
144 if (lstDumps.SelectedIndex != -1)
145 {
146 if (lstGSDX.SelectedIndex != -1)
147 ExecuteFunction("GSReplay");
148 else
149 MessageBox.Show("Select your GSDX first", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
150 }
151 else
152 MessageBox.Show("Select your Dump first", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
153 }
154
155 private void ExecuteFunction(String Function)
156 {
157 txtLog.Text = "";
158 String GSDXName = lstGSDX.SelectedItem.ToString().Split(new char[] { '|' })[0];
159
160 CreateDirs(GSDXName);
161
162 // Set the Arguments to pass to the child
163 String DLLPath = Properties.Settings.Default.GSDXDir + "\\" + GSDXName;
164 String DumpPath = "";
165 String SelectedRenderer = "";
166 switch (SelectedRad)
167 {
168 case 0:
169 SelectedRenderer = "-1";
170 break;
171 case 1:
172 SelectedRenderer = "0";
173 break;
174 case 2:
175 SelectedRenderer = "3";
176 break;
177 case 3:
178 SelectedRenderer = "1";
179 break;
180 case 4:
181 SelectedRenderer = "4";
182 break;
183 }
184 if (lstDumps.SelectedItem != null)
185 DumpPath = Properties.Settings.Default.DumpDir + "\\" +
186 lstDumps.SelectedItem.ToString().Split(new char[] { '|' })[0];
187
188 // Start the child and link the events.
189 ProcessStartInfo psi = new ProcessStartInfo();
190 psi.UseShellExecute = false;
191 psi.RedirectStandardOutput = true;
192 psi.RedirectStandardError = false;
193 psi.CreateNoWindow = true;
194 psi.FileName = AppDomain.CurrentDomain.BaseDirectory + "GsDumpGUI.exe";
195 psi.Arguments = "\"" + DLLPath + "\"" + " \"" + DumpPath + "\"" + " \"" + Function + "\"" + " " + SelectedRenderer;
196 Process p = Process.Start(psi);
197 p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
198 p.BeginOutputReadLine();
199 p.Exited += new EventHandler(p_Exited);
200 Processes.Add(p);
201 }
202
203 private static void CreateDirs(String GSDXName)
204 {
205 // Create and set the config directory.
206 String Dir = AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\";
207 if (!Directory.Exists(Dir))
208 {
209 Directory.CreateDirectory(Dir);
210 }
211 Dir += GSDXName;
212 if (!Directory.Exists(Dir))
213 {
214 Directory.CreateDirectory(Dir);
215 }
216 Dir += "\\Inis\\";
217 if (!Directory.Exists(Dir))
218 {
219 Directory.CreateDirectory(Dir);
220 File.Create(Dir + "\\gsdx.ini").Close();
221 }
222 Dir = AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\" + GSDXName;
223 Directory.SetCurrentDirectory(Dir);
224 }
225
226 void p_Exited(object sender, EventArgs e)
227 {
228 // Remove the child if is closed
229 Processes.Remove((Process)sender);
230 }
231
232 void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
233 {
234 // Write the log.
235 txtLog.Invoke(new Action<object>(delegate(object o)
236 {
237 txtLog.Text += e.Data + Environment.NewLine;
238 txtLog.SelectionStart = txtLog.Text.Length - 1;
239 txtLog.ScrollToCaret();
240 }), new object[] { null });
241 }
242
243 private void cmdConfigGSDX_Click(object sender, EventArgs e)
244 {
245 // Execute the GSconfigure function
246 if (lstGSDX.SelectedIndex != -1)
247 ExecuteFunction("GSconfigure");
248 else
249 MessageBox.Show("Select your GSDX first", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
250 }
251
252 private void cmdOpenIni_Click(object sender, EventArgs e)
253 {
254 // Execute the GSconfigure function
255 if (lstGSDX.SelectedIndex != -1)
256 {
257 String GSDXName = lstGSDX.SelectedItem.ToString().Split(new char[] { '|' })[0];
258 CreateDirs(GSDXName);
259 Process.Start(AppDomain.CurrentDomain.BaseDirectory + "GSDumpGSDXConfigs\\" + GSDXName + "\\inis\\gsdx.ini");
260 }
261 else
262 MessageBox.Show("Select your GSDX first", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
263 }
264
265 private void lstDumps_SelectedIndexChanged(object sender, EventArgs e)
266 {
267 if (lstDumps.SelectedIndex != -1)
268 {
269 String DumpFileName = lstDumps.SelectedItem.ToString().Split(new char[] { '|' })[0];
270 String Filename = Path.GetDirectoryName(Properties.Settings.Default.DumpDir + "\\") +
271 "\\" + Path.GetFileNameWithoutExtension(DumpFileName) + ".bmp";
272 if (File.Exists(Filename))
273 {
274 pctBox.Image = Image.FromFile(Filename);
275 pctBox.Cursor = Cursors.Hand;
276 }
277 else
278 {
279 pctBox.Image = NoImage;
280 pctBox.Cursor = Cursors.Default;
281 }
282 }
283 }
284
285 private void pctBox_Click(object sender, EventArgs e)
286 {
287 if (pctBox.Cursor == Cursors.Hand)
288 {
289 String DumpFileName = lstDumps.SelectedItem.ToString().Split(new char[] { '|' })[0];
290 String Filename = Path.GetDirectoryName(Properties.Settings.Default.DumpDir + "\\") +
291 "\\" + Path.GetFileNameWithoutExtension(DumpFileName) + ".bmp";
292 Process.Start(Filename);
293 }
294 }
295
296 private void GSDumpGUI_KeyDown(object sender, KeyEventArgs e)
297 {
298 if (e.KeyCode == Keys.Return)
299 cmdStart_Click(sender, e);
300
301 if (e.KeyCode == Keys.F1)
302 cmdConfigGSDX_Click(sender, e);
303
304 if ((e.KeyCode == Keys.Down))
305 {
306 e.Handled = true;
307 if (lstDumps.Items.Count > lstDumps.SelectedIndex + 1)
308 lstDumps.SelectedIndex++;
309 }
310
311 if ((e.KeyCode == Keys.Up))
312 {
313 e.Handled = true;
314 if (lstDumps.SelectedIndex > 0)
315 lstDumps.SelectedIndex--;
316 }
317
318 if ((e.KeyCode == Keys.F2))
319 SelectedRad++;
320 }
321
322 private void rda_CheckedChanged(object sender, EventArgs e)
323 {
324 RadioButton itm = ((RadioButton)(sender));
325 if (itm.Checked == true)
326 SelectedRad = Convert.ToInt32(itm.Tag);
327 }
328 }
329 }

  ViewVC Help
Powered by ViewVC 1.1.22