mirror of https://github.com/PCSX2/pcsx2.git
GSDumpGUI: Clean up GS plugin loading. Try all parent directories before giving up. Attempt at human readable plugin loading errors (fails badly).
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4210 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
parent
d707844613
commit
67caeae57e
|
@ -79,7 +79,7 @@ namespace GSDumpGUI
|
|||
GSDXWrapper wrap = new GSDXWrapper();
|
||||
foreach (var itm in File)
|
||||
{
|
||||
if (GSDXWrapper.IsValidGSDX(itm))
|
||||
try
|
||||
{
|
||||
wrap.Load(itm);
|
||||
|
||||
|
@ -88,7 +88,7 @@ namespace GSDumpGUI
|
|||
|
||||
wrap.Unload();
|
||||
}
|
||||
else
|
||||
catch (InvalidGSPlugin)
|
||||
{
|
||||
txtIntLog.Text += "Failed to load \"" + itm + "\". Is it really a GSDX DLL?" + Environment.NewLine;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,11 @@ namespace GSDumpGUI
|
|||
public delegate IntPtr PSEgetLibName();
|
||||
public delegate void GSinit();
|
||||
|
||||
public class InvalidGSPlugin : Exception
|
||||
{
|
||||
public InvalidGSPlugin(string reason) : base(reason) {}
|
||||
}
|
||||
|
||||
public class GSDXWrapper
|
||||
{
|
||||
static public bool DumpTooOld = false;
|
||||
|
@ -60,64 +65,26 @@ namespace GSDumpGUI
|
|||
public AutoResetEvent ExternalEvent;
|
||||
public int RunTo;
|
||||
|
||||
static public Boolean IsValidGSDX(String DLL)
|
||||
{
|
||||
NativeMethods.SetErrorMode(0x8007);
|
||||
Boolean Ris = true;
|
||||
|
||||
Directory.SetCurrentDirectory(Path.GetDirectoryName(DLL));
|
||||
IntPtr hmod = NativeMethods.LoadLibrary(DLL);
|
||||
if (hmod.ToInt64() > 0)
|
||||
{
|
||||
IntPtr funcaddrLibName = NativeMethods.GetProcAddress(hmod, "PS2EgetLibName");
|
||||
IntPtr funcaddrConfig = NativeMethods.GetProcAddress(hmod, "GSconfigure");
|
||||
|
||||
IntPtr funcaddrGIF = NativeMethods.GetProcAddress(hmod, "GSgifTransfer");
|
||||
IntPtr funcaddrVSync = NativeMethods.GetProcAddress(hmod, "GSvsync");
|
||||
IntPtr funcaddrSetBaseMem = NativeMethods.GetProcAddress(hmod, "GSsetBaseMem");
|
||||
IntPtr funcaddrOpen = NativeMethods.GetProcAddress(hmod, "GSopen");
|
||||
IntPtr funcaddrSetCRC = NativeMethods.GetProcAddress(hmod, "GSsetGameCRC");
|
||||
IntPtr funcaddrClose = NativeMethods.GetProcAddress(hmod, "GSclose");
|
||||
IntPtr funcaddrShutdown = NativeMethods.GetProcAddress(hmod, "GSshutdown");
|
||||
IntPtr funcaddrFreeze = NativeMethods.GetProcAddress(hmod, "GSfreeze");
|
||||
IntPtr funcaddrGSreadFIFO2 = NativeMethods.GetProcAddress(hmod, "GSreadFIFO2");
|
||||
IntPtr funcaddrinit = NativeMethods.GetProcAddress(hmod, "GSinit");
|
||||
|
||||
NativeMethods.FreeLibrary(hmod);
|
||||
if (!((funcaddrConfig.ToInt64() > 0) && (funcaddrLibName.ToInt64() > 0) && (funcaddrGIF.ToInt64() > 0)))
|
||||
{
|
||||
Int32 id = NativeMethods.GetLastError();
|
||||
System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "log.txt", DLL + " failed to load. Error " + id + Environment.NewLine);
|
||||
Ris = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Int32 id = NativeMethods.GetLastError();
|
||||
System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "log.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;
|
||||
Directory.SetCurrentDirectory(Path.GetDirectoryName(DLL));
|
||||
string dir = DLL;
|
||||
while (true)
|
||||
{
|
||||
dir = Path.GetDirectoryName(dir);
|
||||
if (dir == null)
|
||||
break;
|
||||
Directory.SetCurrentDirectory(dir);
|
||||
IntPtr hmod = NativeMethods.LoadLibrary(DLL);
|
||||
if (hmod.ToInt64() > 0)
|
||||
{
|
||||
DLLAddr = hmod;
|
||||
|
||||
IntPtr funcaddrLibName = NativeMethods.GetProcAddress(hmod, "PS2EgetLibName");
|
||||
IntPtr funcaddrConfig = NativeMethods.GetProcAddress(hmod, "GSconfigure");
|
||||
|
||||
|
@ -136,6 +103,11 @@ namespace GSDumpGUI
|
|||
IntPtr funcaddrGSreadFIFO2 = NativeMethods.GetProcAddress(hmod, "GSreadFIFO2");
|
||||
IntPtr funcaddrinit = NativeMethods.GetProcAddress(hmod, "GSinit");
|
||||
|
||||
if (!((funcaddrConfig.ToInt64() > 0) && (funcaddrLibName.ToInt64() > 0) && (funcaddrGIF.ToInt64() > 0)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
gsConfigure = (GSConfigure)Marshal.GetDelegateForFunctionPointer(funcaddrConfig, typeof(GSConfigure));
|
||||
PsegetLibName = (PSEgetLibName)Marshal.GetDelegateForFunctionPointer(funcaddrLibName, typeof(PSEgetLibName));
|
||||
|
||||
|
@ -154,7 +126,16 @@ namespace GSDumpGUI
|
|||
this.GSreadFIFO2 = (GSreadFIFO2)Marshal.GetDelegateForFunctionPointer(funcaddrGSreadFIFO2, typeof(GSreadFIFO2));
|
||||
this.GSinit = (GSinit)Marshal.GetDelegateForFunctionPointer(funcaddrinit, typeof(GSinit));
|
||||
|
||||
DLLAddr = hmod;
|
||||
Loaded = true;
|
||||
}
|
||||
}
|
||||
if (!Loaded)
|
||||
{
|
||||
Exception lasterror = Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
|
||||
System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "log.txt", DLL + " failed to load. Error " + lasterror.ToString() + Environment.NewLine);
|
||||
NativeMethods.SetErrorMode(0x0000);
|
||||
Unload();
|
||||
throw new InvalidGSPlugin(lasterror.ToString());
|
||||
}
|
||||
NativeMethods.SetErrorMode(0x0000);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue