GSDumpGUI: Watch for directory changes.

Also try to avoid unclosed file handles.
This commit is contained in:
KrossX 2019-07-29 13:53:43 -03:00 committed by lightningterror
parent b749c8ef7d
commit bd6261e3de
4 changed files with 148 additions and 50 deletions

View File

@ -48,6 +48,7 @@ namespace GSDumpGUI
static private TreeNode CurrentNode;
static public IntPtr hMainIcon;
static public bool prog_running;
[STAThread]
static void Main(String[] args)
@ -117,12 +118,14 @@ namespace GSDumpGUI
Server.OnClientAfterConnect += new TCPLibrary.Core.Server.ConnectedHandler(Server_OnClientAfterConnect);
Server.OnClientAfterDisconnected += new TCPLibrary.Core.Server.DisconnectedHandler(Server_OnClientAfterDisconnected);
Server.Enabled = true;
prog_running = true;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
frmMain = new GSDumpGUI();
Application.Run(frmMain);
prog_running = false;
Server.Enabled = false;
}
}

View File

@ -53,7 +53,7 @@ namespace GSDumpGUI.Forms.Helper
foreach (var dump in dumps)
{
int crc;
using (var fileStream = File.Open(dump.FullName, FileMode.Open))
using (var fileStream = File.OpenRead(dump.FullName))
{
using (var br = new BinaryReader(fileStream))
{

View File

@ -24,9 +24,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Diagnostics;
using System.Linq;
@ -92,6 +94,11 @@ namespace GSDumpGUI
private readonly GsDumps _availableGsDumps;
private readonly GsDlls _availableGsDlls;
private List<FileSystemWatcher> dll_watcher;
private List<FileSystemWatcher> dump_watcher;
private ConcurrentQueue<int> watcher_events;
public GSDumpGUI()
{
PortableXmlSettingsProvider.ApplyProvider(Settings);
@ -116,6 +123,47 @@ namespace GSDumpGUI
Processes = new List<Process>();
NoImage = CreateDefaultImage();
dll_watcher = new List<FileSystemWatcher>();
dump_watcher = new List<FileSystemWatcher>();
watcher_events = new ConcurrentQueue<int>();
Thread wt = new Thread(changes_watchdog_thread);
wt.Start();
}
private void changes_watchdog_thread()
{
while (Program.prog_running)
{
bool dll_reload = false;
bool dump_reload = false;
int evt;
while (watcher_events.TryDequeue(out evt))
{
if (evt == 1) dll_reload = true;
else if (evt == 2) dump_reload = true;
}
if (dll_reload) this.Invoke((MethodInvoker)delegate { ReloadGsdxDlls(); });
if (dump_reload) this.Invoke((MethodInvoker)delegate { ReloadGsdxDumps(); });
Thread.Sleep(1000);
}
}
private void OnDllDirChange(object source, FileSystemEventArgs e)
{
watcher_events.Enqueue(1);
//ReloadGsdxDlls();
}
private void OnDumpDirChange(object source, FileSystemEventArgs e)
{
watcher_events.Enqueue(2);
//ReloadGsdxDumps();
}
private static void BindListControl<TModel, TElement>(ListControl lb, TModel model, Func<TModel, BindingList<TElement>> collectionAccessor, Expression<Func<TElement, string>> displayTextAccessor, Expression<Func<TModel, int>> selectedIndexAccessor)
@ -151,6 +199,31 @@ namespace GSDumpGUI
Settings.GSDXDir = gsdxFolder.FullName;
_internalLogger.Information("Completed GSdx Loading Procedures");
string[] paths = { "", "\\plugins", "\\dll", "\\dlls" };
foreach (FileSystemWatcher w in dll_watcher)
{
w.EnableRaisingEvents = false;
w.Dispose();
}
dll_watcher.Clear();
for (int i = 0; i < 4; i++)
{
try
{
FileSystemWatcher w = new FileSystemWatcher(Settings.GSDXDir + paths[i], "*.dll");
//w.Changed += OnDllDirChange;
w.Created += OnDllDirChange;
w.Deleted += OnDllDirChange;
w.Renamed += OnDllDirChange;
w.EnableRaisingEvents = true;
dll_watcher.Add(w);
}
catch { }
}
}
private void ReloadGsdxDumps()
@ -165,6 +238,31 @@ namespace GSDumpGUI
Settings.DumpDir = dumpFolder.FullName;
_internalLogger.Information("...Completed GSdx Dump Loading Procedures");
string[] paths = { "", "\\dumps", "\\gsdumps" };
foreach (FileSystemWatcher w in dump_watcher)
{
w.EnableRaisingEvents = false;
w.Dispose();
}
dump_watcher.Clear();
for (int i = 0; i < 3; i++)
{
try
{
FileSystemWatcher w = new FileSystemWatcher(Settings.DumpDir + paths[i], "*.gs");
//w.Changed += OnDumpDirChange;
w.Created += OnDumpDirChange;
w.Deleted += OnDumpDirChange;
w.Renamed += OnDumpDirChange;
w.EnableRaisingEvents = true;
dump_watcher.Add(w);
}
catch { }
}
}
private void GSDumpGUI_Load(object sender, EventArgs e)

View File

@ -101,62 +101,58 @@ namespace GSDumpGUI
Unload();
string dir = DLL;
while (true)
dir = Path.GetDirectoryName(dir);
if (dir == null) return;
Directory.SetCurrentDirectory(dir);
System.Diagnostics.Trace.WriteLine("LoadLibrary: " + DLL);
IntPtr hmod = NativeMethods.LoadLibrary(DLL);
if (hmod != IntPtr.Zero)
{
dir = Path.GetDirectoryName(dir);
if (dir == null)
break;
Directory.SetCurrentDirectory(dir);
IntPtr hmod = NativeMethods.LoadLibrary(DLL);
if (hmod.ToInt64() > 0)
{
DLLAddr = hmod;
DLLAddr = hmod;
IntPtr funcaddrLibName = NativeMethods.GetProcAddress(hmod, "PS2EgetLibName");
IntPtr funcaddrConfig = NativeMethods.GetProcAddress(hmod, "GSconfigure");
IntPtr funcaddrLibName = NativeMethods.GetProcAddress(hmod, "PS2EgetLibName");
IntPtr funcaddrConfig = NativeMethods.GetProcAddress(hmod, "GSconfigure");
IntPtr funcaddrGIF = NativeMethods.GetProcAddress(hmod, "GSgifTransfer");
IntPtr funcaddrGIF1 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer1");
IntPtr funcaddrGIF2 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer2");
IntPtr funcaddrGIF3 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer3");
IntPtr funcaddrVSync = NativeMethods.GetProcAddress(hmod, "GSvsync");
IntPtr funcaddrSetBaseMem = NativeMethods.GetProcAddress(hmod, "GSsetBaseMem");
IntPtr funcaddrGSReset = NativeMethods.GetProcAddress(hmod, "GSreset");
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");
IntPtr funcmakeSnapshot = NativeMethods.GetProcAddress(hmod, "GSmakeSnapshot");
IntPtr funcaddrGIF = NativeMethods.GetProcAddress(hmod, "GSgifTransfer");
IntPtr funcaddrGIF1 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer1");
IntPtr funcaddrGIF2 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer2");
IntPtr funcaddrGIF3 = NativeMethods.GetProcAddress(hmod, "GSgifTransfer3");
IntPtr funcaddrVSync = NativeMethods.GetProcAddress(hmod, "GSvsync");
IntPtr funcaddrSetBaseMem = NativeMethods.GetProcAddress(hmod, "GSsetBaseMem");
IntPtr funcaddrGSReset = NativeMethods.GetProcAddress(hmod, "GSreset");
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");
IntPtr funcmakeSnapshot = NativeMethods.GetProcAddress(hmod, "GSmakeSnapshot");
if (!((funcaddrConfig.ToInt64() > 0) && (funcaddrLibName.ToInt64() > 0) && (funcaddrGIF.ToInt64() > 0)))
{
break;
}
if (!((funcaddrConfig.ToInt64() > 0) && (funcaddrLibName.ToInt64() > 0) && (funcaddrGIF.ToInt64() > 0)))
throw new InvalidGSPlugin("");
gsConfigure = (GSConfigure) Marshal.GetDelegateForFunctionPointer(funcaddrConfig, typeof(GSConfigure));
PsegetLibName = (PSEgetLibName) Marshal.GetDelegateForFunctionPointer(funcaddrLibName, typeof(PSEgetLibName));
gsConfigure = (GSConfigure) Marshal.GetDelegateForFunctionPointer(funcaddrConfig, typeof(GSConfigure));
PsegetLibName = (PSEgetLibName) Marshal.GetDelegateForFunctionPointer(funcaddrLibName, typeof(PSEgetLibName));
this.GSgifTransfer = (GSgifTransfer) Marshal.GetDelegateForFunctionPointer(funcaddrGIF, typeof(GSgifTransfer));
this.GSgifTransfer1 = (GSgifTransfer1) Marshal.GetDelegateForFunctionPointer(funcaddrGIF1, typeof(GSgifTransfer1));
this.GSgifTransfer2 = (GSgifTransfer2) Marshal.GetDelegateForFunctionPointer(funcaddrGIF2, typeof(GSgifTransfer2));
this.GSgifTransfer3 = (GSgifTransfer3) Marshal.GetDelegateForFunctionPointer(funcaddrGIF3, typeof(GSgifTransfer3));
this.GSVSync = (GSVSync) Marshal.GetDelegateForFunctionPointer(funcaddrVSync, typeof(GSVSync));
this.GSsetBaseMem = (GSsetBaseMem) Marshal.GetDelegateForFunctionPointer(funcaddrSetBaseMem, typeof(GSsetBaseMem));
this.GSopen = (GSopen) Marshal.GetDelegateForFunctionPointer(funcaddrOpen, typeof(GSopen));
this.GSsetGameCRC = (GSsetGameCRC) Marshal.GetDelegateForFunctionPointer(funcaddrSetCRC, typeof(GSsetGameCRC));
this.GSclose = (GSclose) Marshal.GetDelegateForFunctionPointer(funcaddrClose, typeof(GSclose));
this.GSshutdown = (GSshutdown) Marshal.GetDelegateForFunctionPointer(funcaddrShutdown, typeof(GSshutdown));
this.GSfreeze = (GSfreeze) Marshal.GetDelegateForFunctionPointer(funcaddrFreeze, typeof(GSfreeze));
this.GSreset = (GSreset) Marshal.GetDelegateForFunctionPointer(funcaddrGSReset, typeof(GSreset));
this.GSreadFIFO2 = (GSreadFIFO2) Marshal.GetDelegateForFunctionPointer(funcaddrGSreadFIFO2, typeof(GSreadFIFO2));
this.GSinit = (GSinit) Marshal.GetDelegateForFunctionPointer(funcaddrinit, typeof(GSinit));
this.GSmakeSnapshot = (GSmakeSnapshot)Marshal.GetDelegateForFunctionPointer(funcmakeSnapshot, typeof(GSmakeSnapshot));
this.GSgifTransfer = (GSgifTransfer) Marshal.GetDelegateForFunctionPointer(funcaddrGIF, typeof(GSgifTransfer));
this.GSgifTransfer1 = (GSgifTransfer1) Marshal.GetDelegateForFunctionPointer(funcaddrGIF1, typeof(GSgifTransfer1));
this.GSgifTransfer2 = (GSgifTransfer2) Marshal.GetDelegateForFunctionPointer(funcaddrGIF2, typeof(GSgifTransfer2));
this.GSgifTransfer3 = (GSgifTransfer3) Marshal.GetDelegateForFunctionPointer(funcaddrGIF3, typeof(GSgifTransfer3));
this.GSVSync = (GSVSync) Marshal.GetDelegateForFunctionPointer(funcaddrVSync, typeof(GSVSync));
this.GSsetBaseMem = (GSsetBaseMem) Marshal.GetDelegateForFunctionPointer(funcaddrSetBaseMem, typeof(GSsetBaseMem));
this.GSopen = (GSopen) Marshal.GetDelegateForFunctionPointer(funcaddrOpen, typeof(GSopen));
this.GSsetGameCRC = (GSsetGameCRC) Marshal.GetDelegateForFunctionPointer(funcaddrSetCRC, typeof(GSsetGameCRC));
this.GSclose = (GSclose) Marshal.GetDelegateForFunctionPointer(funcaddrClose, typeof(GSclose));
this.GSshutdown = (GSshutdown) Marshal.GetDelegateForFunctionPointer(funcaddrShutdown, typeof(GSshutdown));
this.GSfreeze = (GSfreeze) Marshal.GetDelegateForFunctionPointer(funcaddrFreeze, typeof(GSfreeze));
this.GSreset = (GSreset) Marshal.GetDelegateForFunctionPointer(funcaddrGSReset, typeof(GSreset));
this.GSreadFIFO2 = (GSreadFIFO2) Marshal.GetDelegateForFunctionPointer(funcaddrGSreadFIFO2, typeof(GSreadFIFO2));
this.GSinit = (GSinit) Marshal.GetDelegateForFunctionPointer(funcaddrinit, typeof(GSinit));
this.GSmakeSnapshot = (GSmakeSnapshot)Marshal.GetDelegateForFunctionPointer(funcmakeSnapshot, typeof(GSmakeSnapshot));
Loaded = true;
}
Loaded = true;
}
if (!Loaded)
@ -178,6 +174,7 @@ namespace GSDumpGUI
public void Unload()
{
System.Diagnostics.Trace.WriteLine("FreeLibrary: " + DLL);
NativeMethods.FreeLibrary(DLLAddr);
Loaded = false;
}