private void CreateTableFromPokerWindow(string windowTitle, IntPtr windowHandle)
{
/* We ignore any event that is caused by a window titled "HudWindow"
* because the user might be simply interacting with our hud.
* Same for "TableDisplayWindow" */
if (windowTitle == "HudWindow" || windowTitle == "TableDisplayWindow")
{
return;
}
// Make sure the hand history directory is set (otherwise we cannot create a table)
//TODO: Part of making a manual training game will be to make this optional
if (!System.IO.Directory.Exists(Globals.UserSettings.StoredHandHistoryDirectory))
{
WriteDebug(WRITE_DEBUG, "A valid game is available on window " + windowTitle + ", but the hand history path is invalid. Fix the hand history path in your settings");
return;
}
WriteDebug(WRITE_DEBUG, String.Format("Window title: {0}", windowTitle));
String pattern = pokerClient.GetHandHistoryFilenameRegexPatternFromWindowTitle(windowTitle);
if (pattern != String.Empty)
{
// If multiple events call this function while a table is added, multiple (non-expected) copies of a table will appear
lock (createTableLock)
{
// Valid poker window
pokerClient.DoPregameProcessing(Globals.UserSettings.StoredHandHistoryDirectory);
// We need to monitor this window for when it closes...
windowsListener.AddToMonitorList(windowTitle);
// Do we have a filename matching this window?
String filename = HHDirectoryParser.GetHandHistoryFilenameFromRegexPattern(Globals.UserSettings.HandHistoryDirectory, pattern);
if (filename != String.Empty)
{
String filePath = Globals.UserSettings.HandHistoryDirectory + @"\" + filename;
// A valid filename was found to be associated with a window title, see if we have a table already
Table table = FindTableByHHFilePath(filePath);
// Is there a game associated with this filename?
if (table == null)
{
// First time we see it, we need to create a table for this request
WriteDebug(WRITE_DEBUG, "--- we have a window, do we have a windowHandle? " + windowHandle.ToString());
Window window = null;
if (IntPtr.Zero == windowHandle)
{
WriteDebug(WRITE_DEBUG, "--- creating Window From Title: " + windowTitle);
window = new Window(windowTitle);
}
else
{
WriteDebug(WRITE_DEBUG, "--- creating Window From Handle: " + windowHandle.ToString());
window = new Window(windowHandle);
window.latestValidWindowTitle = windowTitle;
}
Table newTable = new Table(filePath, window, pokerClient, playerDatabase);
// and add it to our list
tables.Add(newTable);
WriteDebug(WRITE_DEBUG, "Created new table: " + newTable.WindowTitle + "(" + windowHandle.ToString() + ")" + " on " + newTable.HandHistoryFilePath);
OnDisplayStatus("Parsing for the first time... please wait.");
// Check for changes, now!
newTable.ParseHandHistoryNow();
}
else
{
// Inform the UI that we might need to shift the hud
ShiftHud(table);
}
OnDisplayStatus("Focus is on the table associated with " + filename);
WriteDebug(WRITE_DEBUG, String.Format("Valid window title match with {0}", filename));
}
else
{
OnDisplayStatus("New game started on window: " + windowTitle);
WriteDebug(WRITE_DEBUG, String.Format("A valid window title was found ({0}) but no filename associated with the window could be found using pattern {1}. Is this our first hand at the table and no hand history is available?", windowTitle, pattern));
}
}
}
else
{
// The window is not a poker window... do what?
}
}