GSDXGSDumpGUI :

Big optimization, reorganization of the code to be more coherent.
Now the Bitmap of "No Image" is created once.
Fixed crash on opening the bitmap.
Now the program change the GSDX window icon, with its own.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2666 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
feal87 2010-03-04 14:54:20 +00:00
parent 85c23ce0a0
commit b7f3b93ecd
7 changed files with 173 additions and 121 deletions

View File

@ -6,6 +6,7 @@ using Reflection = System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
using GSDumpGUI.Properties;
namespace GSDumpGUI
{
@ -13,6 +14,8 @@ namespace GSDumpGUI
{
static public GSDumpGUI frmMain;
static private Boolean ChangeIcon;
[STAThread]
static void Main(String[] args)
{
@ -22,6 +25,15 @@ namespace GSDumpGUI
{
while (true)
{
if (ChangeIcon)
{
IntPtr pt = Process.GetCurrentProcess().MainWindowHandle;
if (pt.ToInt64() != 0)
{
NativeMethods.SetClassLong(pt, -14, Resources.AppIcon.Handle.ToInt64());
ChangeIcon = false;
}
}
Int32 tmp = NativeMethods.GetAsyncKeyState(0x1b) & 0xf;
if (tmp != 0)
Process.GetCurrentProcess().Kill();
@ -37,32 +49,19 @@ namespace GSDumpGUI
String Operation = args[2];
Int32 Renderer = Convert.ToInt32(args[3]);
// Try to load the DLL in memory
IntPtr hmod = NativeMethods.LoadLibrary(DLLPath);
if (hmod.ToInt64() > 0)
GSDXWrapper wrap = new GSDXWrapper();
wrap.Load(DLLPath);
if (Operation == "GSReplay")
{
// Search if the DLL has the requested operation
IntPtr funcaddr = NativeMethods.GetProcAddress(hmod, Operation);
if (funcaddr.ToInt64() > 0)
{
// Execute the appropriate function pointer by casting it to a delegate.
if (Operation == "GSReplay")
{
GSDXImport.GSReplay dg = (GSDXImport.GSReplay)Marshal.GetDelegateForFunctionPointer(funcaddr, typeof(GSDXImport.GSReplay));
if (Renderer != -1)
dg.Invoke(new IntPtr(0), new IntPtr(0), Renderer + " " + DumpPath, false);
else
dg.Invoke(new IntPtr(0), new IntPtr(0), DumpPath, false);
}
else
{
GSDXImport.GSConfigure dg = (GSDXImport.GSConfigure)Marshal.GetDelegateForFunctionPointer(funcaddr, typeof(GSDXImport.GSConfigure));
dg.Invoke();
}
}
// Unload the library.
NativeMethods.FreeLibrary(hmod);
ChangeIcon = true;
if (Renderer != -1)
wrap.GSReplayDump(Renderer + " " + DumpPath);
else
wrap.GSReplayDump(DumpPath);
}
else
wrap.GSConfig();
wrap.Unload();
}
else
{

View File

@ -129,7 +129,6 @@
this.lstGSDX.Name = "lstGSDX";
this.lstGSDX.Size = new System.Drawing.Size(301, 225);
this.lstGSDX.TabIndex = 1;
this.lstGSDX.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lstGSDX_KeyDown);
//
// lstDumps
//
@ -139,7 +138,6 @@
this.lstDumps.Size = new System.Drawing.Size(301, 225);
this.lstDumps.TabIndex = 0;
this.lstDumps.SelectedIndexChanged += new System.EventHandler(this.lstDumps_SelectedIndexChanged);
this.lstDumps.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lstDumps_KeyDown);
//
// lblDumps
//
@ -229,9 +227,10 @@
this.rdaDX9HW.Name = "rdaDX9HW";
this.rdaDX9HW.Size = new System.Drawing.Size(68, 17);
this.rdaDX9HW.TabIndex = 18;
this.rdaDX9HW.Tag = "1";
this.rdaDX9HW.Text = "DX9 HW";
this.rdaDX9HW.UseVisualStyleBackColor = true;
this.rdaDX9HW.CheckedChanged += new System.EventHandler(this.rdaDX9HW_CheckedChanged);
this.rdaDX9HW.CheckedChanged += new System.EventHandler(this.rda_CheckedChanged);
//
// rdaDX10HW
//
@ -240,9 +239,10 @@
this.rdaDX10HW.Name = "rdaDX10HW";
this.rdaDX10HW.Size = new System.Drawing.Size(74, 17);
this.rdaDX10HW.TabIndex = 19;
this.rdaDX10HW.Tag = "2";
this.rdaDX10HW.Text = "DX10 HW";
this.rdaDX10HW.UseVisualStyleBackColor = true;
this.rdaDX10HW.CheckedChanged += new System.EventHandler(this.rdaDX10HW_CheckedChanged);
this.rdaDX10HW.CheckedChanged += new System.EventHandler(this.rda_CheckedChanged);
//
// rdaDX9SW
//
@ -251,9 +251,10 @@
this.rdaDX9SW.Name = "rdaDX9SW";
this.rdaDX9SW.Size = new System.Drawing.Size(67, 17);
this.rdaDX9SW.TabIndex = 20;
this.rdaDX9SW.Tag = "3";
this.rdaDX9SW.Text = "DX9 SW";
this.rdaDX9SW.UseVisualStyleBackColor = true;
this.rdaDX9SW.CheckedChanged += new System.EventHandler(this.rdaDX9SW_CheckedChanged);
this.rdaDX9SW.CheckedChanged += new System.EventHandler(this.rda_CheckedChanged);
//
// rdaDX10SW
//
@ -262,9 +263,10 @@
this.rdaDX10SW.Name = "rdaDX10SW";
this.rdaDX10SW.Size = new System.Drawing.Size(73, 17);
this.rdaDX10SW.TabIndex = 21;
this.rdaDX10SW.Tag = "4";
this.rdaDX10SW.Text = "DX10 SW";
this.rdaDX10SW.UseVisualStyleBackColor = true;
this.rdaDX10SW.CheckedChanged += new System.EventHandler(this.rdaDX10SW_CheckedChanged);
this.rdaDX10SW.CheckedChanged += new System.EventHandler(this.rda_CheckedChanged);
//
// lblOverride
//
@ -284,9 +286,10 @@
this.rdaNone.Size = new System.Drawing.Size(51, 17);
this.rdaNone.TabIndex = 23;
this.rdaNone.TabStop = true;
this.rdaNone.Tag = "0";
this.rdaNone.Text = "None";
this.rdaNone.UseVisualStyleBackColor = true;
this.rdaNone.CheckedChanged += new System.EventHandler(this.rdaNone_CheckedChanged);
this.rdaNone.CheckedChanged += new System.EventHandler(this.rda_CheckedChanged);
//
// GSDumpGUI
//

View File

@ -47,10 +47,18 @@ namespace GSDumpGUI
}
}
private Bitmap NoImage;
public GSDumpGUI()
{
InitializeComponent();
Processes = new List<Process>();
NoImage = new Bitmap(320, 240, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(NoImage);
g.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, 320, 240));
g.DrawString("No Image", new Font(FontFamily.GenericSansSerif, 48, FontStyle.Regular), new SolidBrush(Color.White), new PointF(0, 70));
g.Dispose();
}
public void ReloadGSDXs()
@ -65,36 +73,16 @@ namespace GSDumpGUI
{
String[] File = Directory.GetFiles(txtGSDXDirectory.Text, "*.dll", SearchOption.TopDirectoryOnly);
NativeMethods.SetErrorMode(0x8007);
GSDXWrapper wrap = new GSDXWrapper();
foreach (var itm in File)
{
IntPtr hmod = NativeMethods.LoadLibrary(itm);
if (hmod.ToInt64() > 0)
if (GSDXWrapper.IsValidGSDX(itm))
{
IntPtr funcaddr = NativeMethods.GetProcAddress(hmod, "GSReplay");
if (funcaddr.ToInt64() > 0)
{
IntPtr funcaddrN = NativeMethods.GetProcAddress(hmod, "PSEgetLibName");
if (funcaddrN.ToInt64() > 0)
{
GSDXImport.PSEgetLibName ps = (GSDXImport.PSEgetLibName)Marshal.GetDelegateForFunctionPointer(funcaddrN, typeof(GSDXImport.PSEgetLibName));
lstGSDX.Items.Add(Path.GetFileName(itm) + " | " + Marshal.PtrToStringAnsi(ps.Invoke()));
}
}
else
{
Int32 id = NativeMethods.GetLastError();
System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "test.txt", itm + " failed to load. Error " + id + Environment.NewLine);
}
NativeMethods.FreeLibrary(hmod);
}
else
{
Int32 id = NativeMethods.GetLastError();
System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "test.txt", itm + " failed to load. Error " + id);
wrap.Load(itm);
lstGSDX.Items.Add(Path.GetFileName(itm) + " | " + wrap.PSEGetLibName());
wrap.Unload();
}
}
NativeMethods.SetErrorMode(0x0000);
String[] Dumps = Directory.GetFiles(txtDumpsDirectory.Text, "*.gs", SearchOption.TopDirectoryOnly);
@ -103,7 +91,7 @@ namespace GSDumpGUI
BinaryReader br = new BinaryReader(System.IO.File.Open(itm, FileMode.Open));
Int32 CRC = br.ReadInt32();
br.Close();
lstDumps.Items.Add(Path.GetFileName(itm) + " | CRC : " + CRC.ToString("x"));
lstDumps.Items.Add(Path.GetFileName(itm) + " | CRC : " + CRC.ToString("X"));
}
}
}
@ -288,12 +276,7 @@ namespace GSDumpGUI
}
else
{
Bitmap bt = new Bitmap(320, 240, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bt);
g.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, 320, 240));
g.DrawString("No Image", new Font(FontFamily.GenericSansSerif, 48, FontStyle.Regular), new SolidBrush(Color.White), new PointF(0,70));
g.Dispose();
pctBox.Image = bt;
pctBox.Image = NoImage;
pctBox.Cursor = Cursors.Default;
}
}
@ -303,73 +286,44 @@ namespace GSDumpGUI
{
if (pctBox.Cursor == Cursors.Hand)
{
String Filename = Path.GetDirectoryName(Properties.Settings.Default.DumpDir + "\\") + "\\" + Path.GetFileNameWithoutExtension(lstDumps.SelectedItem.ToString()) + ".bmp";
String DumpFileName = lstDumps.SelectedItem.ToString().Split(new char[] { '|' })[0];
String Filename = Path.GetDirectoryName(Properties.Settings.Default.DumpDir + "\\") +
"\\" + Path.GetFileNameWithoutExtension(DumpFileName) + ".bmp";
Process.Start(Filename);
}
}
private void lstDumps_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
cmdStart_Click(sender, e);
if (e.KeyCode == Keys.F1)
cmdConfigGSDX_Click(sender, e);
}
private void lstGSDX_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
cmdStart_Click(sender, e);
if (e.KeyCode == Keys.F1)
cmdConfigGSDX_Click(sender, e);
}
private void GSDumpGUI_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
cmdStart_Click(sender, e);
if (e.KeyCode == Keys.F1)
cmdConfigGSDX_Click(sender, e);
if ((e.KeyCode == Keys.Down))
{
e.Handled = true;
if (lstDumps.Items.Count > lstDumps.SelectedIndex + 1)
lstDumps.SelectedIndex++;
}
if ((e.KeyCode == Keys.Up))
{
e.Handled = true;
if (lstDumps.SelectedIndex > 0)
lstDumps.SelectedIndex--;
}
if ((e.KeyCode == Keys.F2))
SelectedRad++;
}
private void rdaDX9HW_CheckedChanged(object sender, EventArgs e)
private void rda_CheckedChanged(object sender, EventArgs e)
{
if (rdaDX9HW.Checked == true)
SelectedRad = 1;
}
private void rdaNone_CheckedChanged(object sender, EventArgs e)
{
if (rdaNone.Checked == true)
SelectedRad = 0;
}
private void rdaDX10HW_CheckedChanged(object sender, EventArgs e)
{
if (rdaDX10HW.Checked == true)
SelectedRad = 2;
}
private void rdaDX9SW_CheckedChanged(object sender, EventArgs e)
{
if (rdaDX9SW.Checked == true)
SelectedRad = 3;
}
private void rdaDX10SW_CheckedChanged(object sender, EventArgs e)
{
if (rdaDX10SW.Checked == true)
SelectedRad = 4;
RadioButton itm = ((RadioButton)(sender));
if (itm.Checked == true)
SelectedRad = Convert.ToInt32(itm.Tag);
}
}
}

View File

@ -50,7 +50,7 @@
<Compile Include="Forms\frmMain.Designer.cs">
<DependentUpon>frmMain.cs</DependentUpon>
</Compile>
<Compile Include="Library\GSDXImport.cs" />
<Compile Include="Library\GSDXWrapper.cs" />
<Compile Include="Library\NativeMethods.cs" />
<Compile Include="Core\Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace GSDumpGUI
{
static public class GSDXImport
{
public delegate void GSReplay(IntPtr HWND, IntPtr HInstance, String File, Boolean Show);
public delegate void GSConfigure();
public delegate IntPtr PSEgetLibName();
}
}

View File

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace GSDumpGUI
{
public class GSDXWrapper
{
private delegate void GSReplay(IntPtr HWND, IntPtr HInstance, String File, Boolean Show);
private delegate void GSConfigure();
private delegate IntPtr PSEgetLibName();
private GSReplay gsReplay;
private GSConfigure gsConfigure;
private PSEgetLibName PsegetLibName;
private Boolean Loaded;
private String DLL;
private IntPtr DLLAddr;
static public Boolean IsValidGSDX(String DLL)
{
NativeMethods.SetErrorMode(0x8007);
Boolean Ris = true;
IntPtr hmod = NativeMethods.LoadLibrary(DLL);
if (hmod.ToInt64() > 0)
{
IntPtr funcaddrReplay = NativeMethods.GetProcAddress(hmod, "GSReplay");
IntPtr funcaddrLibName = NativeMethods.GetProcAddress(hmod, "PSEgetLibName");
IntPtr funcaddrConfig = NativeMethods.GetProcAddress(hmod, "GSconfigure");
NativeMethods.FreeLibrary(hmod);
if (!((funcaddrConfig.ToInt64() > 0) && (funcaddrLibName.ToInt64() > 0) && (funcaddrReplay.ToInt64() > 0)))
{
Int32 id = NativeMethods.GetLastError();
System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "test.txt", DLL + " failed to load. Error " + id);
Ris = false;
}
}
else
{
Int32 id = NativeMethods.GetLastError();
System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "test.txt", DLL + " failed to load. Error " + id + Environment.NewLine);
Ris = false;
}
NativeMethods.SetErrorMode(0x0000);
return Ris;
}
public void Load(String DLL)
{
this.DLL = DLL;
NativeMethods.SetErrorMode(0x8007);
if (!IsValidGSDX(DLL))
throw new Exception("Invalid GSDX DLL");
if (Loaded)
Unload();
Loaded = true;
IntPtr hmod = NativeMethods.LoadLibrary(DLL);
if (hmod.ToInt64() > 0)
{
IntPtr funcaddrReplay = NativeMethods.GetProcAddress(hmod, "GSReplay");
IntPtr funcaddrLibName = NativeMethods.GetProcAddress(hmod, "PSEgetLibName");
IntPtr funcaddrConfig = NativeMethods.GetProcAddress(hmod, "GSconfigure");
gsReplay = (GSReplay)Marshal.GetDelegateForFunctionPointer(funcaddrReplay, typeof(GSReplay));
gsConfigure = (GSConfigure)Marshal.GetDelegateForFunctionPointer(funcaddrConfig, typeof(GSConfigure));
PsegetLibName = (PSEgetLibName)Marshal.GetDelegateForFunctionPointer(funcaddrLibName, typeof(PSEgetLibName));
DLLAddr = hmod;
}
NativeMethods.SetErrorMode(0x0000);
}
public void Unload()
{
NativeMethods.FreeLibrary(DLLAddr);
Loaded = false;
}
public void GSConfig()
{
if (!Loaded)
throw new Exception("GSDX is not loaded");
gsConfigure.Invoke();
}
public void GSReplayDump(String DumpFilename)
{
if (!Loaded)
throw new Exception("GSDX is not loaded");
gsReplay.Invoke(new IntPtr(0), new IntPtr(0), DumpFilename, false);
}
public String PSEGetLibName()
{
if (!Loaded)
throw new Exception("GSDX is not loaded");
return Marshal.PtrToStringAnsi(PsegetLibName.Invoke());
}
}
}

View File

@ -31,5 +31,9 @@ namespace GSDumpGUI
[SuppressUnmanagedCodeSecurityAttribute]
[DllImport("user32", CharSet = CharSet.Ansi)]
public extern static short GetAsyncKeyState(int key);
[SuppressUnmanagedCodeSecurityAttribute]
[DllImport("user32", CharSet = CharSet.Ansi)]
public extern static int SetClassLong(IntPtr HWND, int index, long newlong);
}
}