mw4print: MySQL export, configurable banner text
MySQL database export (dbexport.h / dbexport.cpp): - New files dbexport.h / dbexport.cpp implement late-bound MySQL export. libmysql.dll is loaded at runtime via LoadLibrary/GetProcAddress so no MySQL SDK is required at compile time; the app runs normally if the DLL is absent. - After each print job, match data is exported to a MySQL server before PrintDlg() is called: one row in 'match', one row per player in 'player_result', one row per attacker/victim pair in 'pvp'. An optional 'event' table records every individual SRecScore entry (off by default). Tables are created automatically (CREATE TABLE IF NOT EXISTS) on first connect. - Config stored in mw4print.ini (app directory), section [MySQLExport]: Enabled, Host, Port, Database, Username, Password, ExportEvents. - Config loaded at startup (OnCreate); DB_LoadConfig() / DB_SaveConfig(). - Connection timeout set to 5 seconds so the app does not hang if the server is unreachable. - libmysql.dll (MySQL Connector/C 32-bit) added to Gameleap/mw4/ so the deploy script copies it to MW4/ alongside mw4print.exe. Database Settings dialog (File > Database Settings... / Ctrl+D): - MFC dialog: enable checkbox, Host/Port/Database/Username/Password fields, Export Events checkbox, Test Connection button with live status label, OK/Cancel. OK persists settings to mw4print.ini immediately. Configurable banner text (File > Banner Setting...): - The 'WWW.MECHJOCK.COM' URL string printed at the bottom of every score sheet is now configurable. Stored as BannerText= in options.ini under [battle tech print] (same section/file as the other print layout params). File > Banner Setting... opens a dialog to edit it; OK saves to options.ini and takes effect on the next print job with no restart needed. Default value is the original MECHJOCK string if the key is absent.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "mw4dummy.h"
|
||||
#include "recscore.h"
|
||||
#include "dbexport.h"
|
||||
typedef unsigned long UINT4;
|
||||
typedef unsigned char* POINTER;
|
||||
#include "logreport.h"
|
||||
@@ -23,6 +24,7 @@ static char THIS_FILE[] = __FILE__;
|
||||
|
||||
#include "mw4dummy.cpp"
|
||||
#include "recscore.cpp"
|
||||
#include "dbexport.cpp"
|
||||
#include "logreport.cpp"
|
||||
|
||||
#define IDT_TIMER 1000
|
||||
@@ -37,6 +39,12 @@ BEGIN_MESSAGE_MAP(CChildView,CWnd )
|
||||
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
|
||||
ON_COMMAND(ID_FILE_LOGREPORT, OnFileLogReport)
|
||||
ON_COMMAND(ID_FILE_LOG2DATES, OnFileLog2Dates)
|
||||
ON_COMMAND(ID_FILE_DBSETTINGS, OnFileDbSettings)
|
||||
ON_COMMAND(ID_FILE_BANNERSETTING, OnFileBannerSetting)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
BEGIN_MESSAGE_MAP(CDlgDBSettings, CDialog)
|
||||
ON_BN_CLICKED(IDC_DB_TEST, OnTestConnection)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
BEGIN_MESSAGE_MAP(CDlgGet2Dates, CDialog)
|
||||
@@ -299,7 +307,9 @@ int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
||||
{
|
||||
if (CWnd ::OnCreate(lpCreateStruct) == -1)
|
||||
return -1;
|
||||
|
||||
|
||||
DB_LoadConfig();
|
||||
|
||||
m_uTimer = SetTimer(IDT_TIMER, 1 * 1000, NULL);
|
||||
if (!m_uTimer)
|
||||
return -1;
|
||||
@@ -343,6 +353,121 @@ void CChildView::OnTimer(UINT nIDEvent)
|
||||
CWnd ::OnTimer(nIDEvent);
|
||||
}
|
||||
|
||||
void CChildView::OnFileBannerSetting()
|
||||
{
|
||||
CDlgBannerSetting dlg(this);
|
||||
dlg.DoModal();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CDlgBannerSetting
|
||||
|
||||
CDlgBannerSetting::CDlgBannerSetting(CWnd* pParent)
|
||||
: CDialog(CDlgBannerSetting::IDD, pParent)
|
||||
{
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CDlgBannerSetting, CDialog)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
void CDlgBannerSetting::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
}
|
||||
|
||||
BOOL CDlgBannerSetting::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
SetDlgItemText(IDC_BANNER_TEXT, g_szPrintBanner);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CDlgBannerSetting::OnOK()
|
||||
{
|
||||
GetDlgItemText(IDC_BANNER_TEXT, g_szPrintBanner, sizeof(g_szPrintBanner));
|
||||
|
||||
// Persist to options.ini so it survives a restart.
|
||||
char szINI[MAX_PATH];
|
||||
sprintf(szINI, "%s\\options.ini", AssetsDirectory1);
|
||||
WritePrivateProfileString("battle tech print", "BannerText", g_szPrintBanner, szINI);
|
||||
|
||||
CDialog::OnOK();
|
||||
}
|
||||
|
||||
void CChildView::OnFileDbSettings()
|
||||
{
|
||||
CDlgDBSettings dlg(this);
|
||||
dlg.DoModal();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CDlgDBSettings
|
||||
|
||||
CDlgDBSettings::CDlgDBSettings(CWnd* pParent)
|
||||
: CDialog(CDlgDBSettings::IDD, pParent)
|
||||
{
|
||||
}
|
||||
|
||||
void CDlgDBSettings::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
}
|
||||
|
||||
BOOL CDlgDBSettings::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
CheckDlgButton(IDC_DB_ENABLED, g_dbConfig.bEnabled ? BST_CHECKED : BST_UNCHECKED);
|
||||
CheckDlgButton(IDC_DB_EXPORTEVENTS, g_dbConfig.bExportEvents ? BST_CHECKED : BST_UNCHECKED);
|
||||
|
||||
SetDlgItemText(IDC_DB_HOST, g_dbConfig.szHost);
|
||||
SetDlgItemInt (IDC_DB_PORT, g_dbConfig.nPort, FALSE);
|
||||
SetDlgItemText(IDC_DB_DATABASE, g_dbConfig.szDatabase);
|
||||
SetDlgItemText(IDC_DB_USERNAME, g_dbConfig.szUsername);
|
||||
SetDlgItemText(IDC_DB_PASSWORD, g_dbConfig.szPassword);
|
||||
|
||||
SetDlgItemText(IDC_DB_STATUS, "");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CDlgDBSettings::OnOK()
|
||||
{
|
||||
g_dbConfig.bEnabled = IsDlgButtonChecked(IDC_DB_ENABLED) == BST_CHECKED;
|
||||
g_dbConfig.bExportEvents = IsDlgButtonChecked(IDC_DB_EXPORTEVENTS) == BST_CHECKED;
|
||||
|
||||
GetDlgItemText(IDC_DB_HOST, g_dbConfig.szHost, sizeof(g_dbConfig.szHost));
|
||||
g_dbConfig.nPort = (int)GetDlgItemInt(IDC_DB_PORT, NULL, FALSE);
|
||||
GetDlgItemText(IDC_DB_DATABASE, g_dbConfig.szDatabase, sizeof(g_dbConfig.szDatabase));
|
||||
GetDlgItemText(IDC_DB_USERNAME, g_dbConfig.szUsername, sizeof(g_dbConfig.szUsername));
|
||||
GetDlgItemText(IDC_DB_PASSWORD, g_dbConfig.szPassword, sizeof(g_dbConfig.szPassword));
|
||||
|
||||
DB_SaveConfig();
|
||||
CDialog::OnOK();
|
||||
}
|
||||
|
||||
void CDlgDBSettings::OnTestConnection()
|
||||
{
|
||||
// Read fields into a temporary config so we test what's in the UI,
|
||||
// not necessarily what was last saved.
|
||||
SDBConfig saved = g_dbConfig;
|
||||
|
||||
GetDlgItemText(IDC_DB_HOST, g_dbConfig.szHost, sizeof(g_dbConfig.szHost));
|
||||
g_dbConfig.nPort = (int)GetDlgItemInt(IDC_DB_PORT, NULL, FALSE);
|
||||
GetDlgItemText(IDC_DB_DATABASE, g_dbConfig.szDatabase, sizeof(g_dbConfig.szDatabase));
|
||||
GetDlgItemText(IDC_DB_USERNAME, g_dbConfig.szUsername, sizeof(g_dbConfig.szUsername));
|
||||
GetDlgItemText(IDC_DB_PASSWORD, g_dbConfig.szPassword, sizeof(g_dbConfig.szPassword));
|
||||
|
||||
SetDlgItemText(IDC_DB_STATUS, "Testing...");
|
||||
UpdateWindow();
|
||||
|
||||
char szError[512] = "";
|
||||
bool bOK = DB_TestConnection(szError, sizeof(szError));
|
||||
SetDlgItemText(IDC_DB_STATUS, bOK ? "OK - Connected successfully." : szError);
|
||||
|
||||
g_dbConfig = saved; // restore; OnOK() will save the final values
|
||||
}
|
||||
|
||||
void CChildView::OnFileOpen()
|
||||
{
|
||||
// TODO: Add your command handler code here
|
||||
|
||||
Reference in New Issue
Block a user