Esempio n. 1
0
void CDlgSAPrefs6::OnBnClickedPtTest()
{
	CString			conn_str = "", ip_addr = "", port = "", user = "", pass = "", dbname = "", e = "";

	m_pt_ip.GetWindowText(ip_addr);
	m_pt_port.GetWindowText(port);
	m_pt_user.GetWindowText(user);
	m_pt_pass.GetWindowText(pass);
	m_pt_dbname.GetWindowText(dbname);

	conn_str = "host=" + ip_addr;
	conn_str += " port=" + port;
	conn_str += " user="******" password="******" dbname='" + dbname;
	conn_str += "'";

	// Set busy cursor
	PMainframe()->set_wait_cursor(true);
	PMainframe()->BeginWaitCursor();

	// Test the connection parameters
	PGconn	*pgconn = PQconnectdb(conn_str.GetString());

	// Unset busy cursor
	PMainframe()->EndWaitCursor();
	PMainframe()->set_wait_cursor(false);

	if (PQstatus(pgconn) == CONNECTION_OK) 
	{
		write_log_pokertracker(prefs.debug_pokertracker(), "Test: PostgreSQL DB opened successfully <%s/%s/%s>\n", ip_addr, port, dbname);
		if (PQisthreadsafe()) 
		{
			write_log_pokertracker(prefs.debug_pokertracker(), "Test: PostgreSQL library is thread safe.\n\n");
			OH_MessageBox_Interactive("PostgreSQL DB opened successfully", "Success", MB_OK);
		}
		else 
		{
			write_log_pokertracker(prefs.debug_pokertracker(), "Test: PostgreSQL library is *NOT* thread safe!  This is a problem!\n\n");
			OH_MessageBox_Interactive("PostgreSQL DB opened successfully, but\nPostgreSQL library is *NOT* thread safe!\nThis is a problem!",
					   "Success (partial)", MB_OK);
		}
		PQfinish(pgconn);
	}
	else 
	{
		write_log_pokertracker(prefs.debug_pokertracker(), "Test: ERROR opening PostgreSQL DB: %s\n\n", PQerrorMessage(pgconn));
		e = "ERROR opening PostgreSQL DB:\n";
		e += PQerrorMessage(pgconn);
		e += "\nConn string:";
		e += conn_str;

		OH_MessageBox_Interactive(e.GetString(), "ERROR", MB_OK);

		PQfinish(pgconn);
	}
}
void COpenHoldemTitle::UpdateTitle()
{
	if (PMainframe() == NULL)
	{
		// Missing main window can happen very early during execution
		// if OpenHoldem creates a default document with default title
		// but the window does not yet exist.
		return;
	}

	// PostMessage(WMA_SETWINDOWTEXT, 0, (LPARAM)(GetTitle().GetString()));
	// can't be used, because that would call COpenHoldemHopperCommunication::OnSetWindowText
	// which would then call SetUserDefinedOpenHoldemTitle()
	// which would call UpdateTitle()
	// -> endless recursion
	static CString current_title;
	current_title = GetTitle();
	HWND main_window = PMainframe()->GetSafeHwnd();
	SetWindowText(main_window, current_title);

}
Esempio n. 3
0
BOOL CMainFrame::DestroyWindow() {
	StopThreads();
  PMainframe()->KillTimers();
	// Save window position
  WINDOWPLACEMENT wp;
	GetWindowPlacement(&wp); 		
	Preferences()->SetValue(k_prefs_main_x, wp.rcNormalPosition.left); 		
 	Preferences()->SetValue(k_prefs_main_y, wp.rcNormalPosition.top);
  write_log(Preferences()->debug_gui(), "[GUI] Going to delete the GUI\n");
  write_log(Preferences()->debug_gui(), "[GUI] this = [%i]\n", this);
  // All OK here
  assert(AfxCheckMemory());
  // http://www.maxinmontreal.com/forums/viewtopic.php?f=111&t=20459
  // probably caused by incorrect order of deletion,
  // caused by incorrect position of StopThreads and KillTimers.
  bool success = CFrameWnd::DestroyWindow(); 
  write_log(Preferences()->debug_gui(), "[GUI] Window deleted\n");
  return success;
}
Esempio n. 4
0
void CMainFrame::OnAutoplayer()
{
    if (p_flags_toolbar->IsButtonChecked(ID_MAIN_TOOLBAR_AUTOPLAYER))
    {
        // calc hand lists
        p_formula->CreateHandListMatrices();

        // one last parse - do not engage if parse fails
        if (p_formula->ParseAllFormula(PMainframe()->GetSafeHwnd()))
        {
            p_autoplayer->set_autoplayer_engaged(true);
        }
        else
        {
            p_autoplayer->set_autoplayer_engaged(false);
            p_flags_toolbar->CheckButton(ID_MAIN_TOOLBAR_AUTOPLAYER, false);
        }
    }
    else
    {
        p_autoplayer->set_autoplayer_engaged(false);
    }
}
void CAutoConnector::Disconnect() {
	write_log(preferences.debug_autoconnector(), "[CAutoConnector] Disconnect()\n");

  // First close scraper-output-dialog,
  // as an updating dialog without a connected table can crash.
  CDlgScraperOutput::DestroyWindowSafely();

	// Wait for mutex - "forever" if necessary, as we have to clean up.
	ASSERT(_autoconnector_mutex->m_hObject != NULL); 
	write_log(preferences.debug_autoconnector(), "[CAutoConnector] Locking autoconnector-mutex\n");
	_autoconnector_mutex->Lock(INFINITE);

	// Make sure autoplayer is off
	write_log(preferences.debug_autoconnector(), "[CAutoConnector] Stopping autoplayer\n");
	p_autoplayer->EngageAutoplayer(false);

	p_engine_container->ResetOnDisconnection();

	// Send "disconnect" to scraper DLL, if loaded
	if (theApp._dll_scraper_process_message)
		(theApp._dll_scraper_process_message) ("disconnect", NULL);

	theApp.UnloadScraperDLL();

	// Clear "attached" info
	set_attached_hwnd(NULL);

	// Unattach OH.
	p_flags_toolbar->UnattachOHFromPokerWindow();
	p_flags_toolbar->ResetButtonsOnDisconnect();

	// Mark table as not attached
	write_log(preferences.debug_autoconnector(), "[CAutoConnector] Marking table as not attached\n");
	p_sharedmem->MarkPokerWindowAsUnAttached();

	// Release mutex as soon as possible, after critical work is done
	write_log(preferences.debug_autoconnector(), "[CAutoConnector] Unlocking autoconnector-mutex\n");
	_autoconnector_mutex->Unlock();	

	// Delete bitmaps
	p_scraper->DeleteBitmaps();

	// Clear scraper fields
	p_table_state->Reset();

	// Reset symbols
	p_engine_container->ResetOnConnection();

	write_log(preferences.debug_autoconnector(), "[CAutoConnector] ResetOnConnection executed (disconnection)\n");
	write_log(preferences.debug_autoconnector(), "[CAutoConnector] Going to continue with window title\n");

	// Change window title
	p_openholdem_title->UpdateTitle();

	// Reset Display 
	PMainframe()->ResetDisplay();

	// Reset "ScraperOutput" dialog, if it is live
	if (m_ScraperOutputDlg)	{
		m_ScraperOutputDlg->Reset();
	}
	WriteLogTableReset();

	// Close OH, when table disappears and leaving enabled in preferences.
	if (preferences.autoconnector_close_when_table_disappears()) {
		PostQuitMessage(0);
	}
	write_log(preferences.debug_autoconnector(), "[CAutoConnector] Disconnect done\n");
}
bool CAutoConnector::Connect(HWND targetHWnd) {
	int					N = 0, line = 0, ret = 0;
	char				title[MAX_WINDOW_TITLE] = {0};
	int					SelectedItem = -1;
	CString			current_path = "";
	BOOL				bFound = false;
	CFileFind   hFile;

	write_log(preferences.debug_autoconnector(), "[CAutoConnector] Connect(..)\n");

	ASSERT(_autoconnector_mutex->m_hObject != NULL); 
	write_log(preferences.debug_autoconnector(), "[CAutoConnector] Locking autoconnector-mutex\n");
	if (!_autoconnector_mutex->Lock(500))	{
		write_log(preferences.debug_autoconnector(), "[CAutoConnector] Could not grab mutex; early exit\n");
		return false; 
	}
  // Clear global list for holding table candidates
	g_tlist.RemoveAll();
	write_log(preferences.debug_autoconnector(), "[CAutoConnector] Number of tablemaps loaded: %i\n",
    p_tablemap_loader->NumberOfTableMapsLoaded());
	for (int tablemap_index=0; tablemap_index<p_tablemap_loader->NumberOfTableMapsLoaded(); tablemap_index++) {
		write_log(preferences.debug_autoconnector(), "[CAutoConnector] Going to check TM nr. %d out of %d\n", 
			tablemap_index, p_tablemap_loader->NumberOfTableMapsLoaded());
		Check_TM_Against_All_Windows_Or_TargetHWND(tablemap_index, targetHWnd);
	}
	
	// Put global candidate table list in table select dialog variables
	N = (int) g_tlist.GetSize();
  write_log(preferences.debug_autoconnector(), "[CAutoConnector] Number of table candidates> %i\n", N);
	if (N == 0) {
		FailedToConnectBecauseNoWindowInList();
	}	else 	{
		SelectedItem = SelectTableMapAndWindow(N);
		if (SelectedItem == k_undefined) {
			FailedToConnectProbablyBecauseAllTablesAlreadyServed();
		}	else {
			write_log(preferences.debug_autoconnector(), "[CAutoConnector] Window [%d] selected\n", g_tlist[SelectedItem].hwnd);
			p_sharedmem->MarkPokerWindowAsAttached(g_tlist[SelectedItem].hwnd);
			write_log(preferences.debug_autoconnector(), "[CAutoConnector] Window marked at shared memory\n");

			// Load correct tablemap, and save hwnd/rect/numchairs of table that we are "attached" to
			set_attached_hwnd(g_tlist[SelectedItem].hwnd);
			assert(p_tablemap != NULL);
			CString tablemap_to_load = g_tlist[SelectedItem].path.GetString();
			write_log(preferences.debug_autoconnector(), "[CAutoConnector] Selected tablemap: %s\n", tablemap_to_load);
			p_tablemap->LoadTablemap(tablemap_to_load);
			write_log(preferences.debug_autoconnector(), "[CAutoConnector] Tablemap loaded\n");

			// Create bitmaps
			p_scraper->CreateBitmaps();
			write_log(preferences.debug_autoconnector(), "[CAutoConnector] Scraper-bitmaps created\n");

			// Clear scraper fields
			p_table_state->Reset();
			write_log(preferences.debug_autoconnector(), "[CAutoConnector] Table state cleared\n");

			// Reset symbols
			p_engine_container->ResetOnConnection();

			write_log(preferences.debug_autoconnector(), "[CAutoConnector] ResetOnConnection executed (during connection)\n");
			write_log(preferences.debug_autoconnector(), "[CAutoConnector] Going to continue with scraper output and scraper DLL\n");

			// Reset "ScraperOutput" dialog, if it is live
			if (m_ScraperOutputDlg) {
				m_ScraperOutputDlg->Reset();
			}

			LoadScraperDLL();
			p_flags_toolbar->ResetButtonsOnConnect();

			// Send "connect" and HWND to scraper DLL, if loaded
			if (theApp._dll_scraper_process_message) {
				(theApp._dll_scraper_process_message) ("connect", &_attached_hwnd);
      }

			p_scraper_access->InitOnConnect();
			// Reset display
			PMainframe()->ResetDisplay();

			// log OH title bar text and table reset
			::GetWindowText(_attached_hwnd, title, MAX_WINDOW_TITLE);
      WriteLogTableReset();

			p_table_positioner->PositionMyWindow();
			p_autoplayer->EngageAutoPlayerUponConnectionIfNeeded();
		}
	}
	write_log(preferences.debug_autoconnector(), "[CAutoConnector] Unlocking autoconnector-mutex\n");
	_autoconnector_mutex->Unlock();
	return (SelectedItem != -1);
}