mw4print: persist banner text via banner.txt
- Add banner.txt load/save helpers in banner settings dialog - Load banner from banner.txt first, with options.ini BannerText fallback - Fix options.ini path join to include missing path separator
This commit is contained in:
@@ -359,6 +359,39 @@ void CChildView::OnFileBannerSetting()
|
||||
dlg.DoModal();
|
||||
}
|
||||
|
||||
static void LoadBannerTextFile()
|
||||
{
|
||||
char szPath[MAX_PATH];
|
||||
sprintf(szPath, "%s\\banner.txt", AssetsDirectory1);
|
||||
|
||||
FILE* f = fopen(szPath, "rt");
|
||||
if (f) {
|
||||
char szBuf[sizeof(g_szPrintBanner)];
|
||||
if (fgets(szBuf, sizeof(szBuf), f)) {
|
||||
size_t n = strlen(szBuf);
|
||||
while (n && (szBuf[n - 1] == '\r' || szBuf[n - 1] == '\n')) {
|
||||
szBuf[--n] = '\0';
|
||||
}
|
||||
strncpy(g_szPrintBanner, szBuf, sizeof(g_szPrintBanner) - 1);
|
||||
g_szPrintBanner[sizeof(g_szPrintBanner) - 1] = '\0';
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
static void SaveBannerTextFile()
|
||||
{
|
||||
char szPath[MAX_PATH];
|
||||
sprintf(szPath, "%s\\banner.txt", AssetsDirectory1);
|
||||
|
||||
FILE* f = fopen(szPath, "wt");
|
||||
if (f) {
|
||||
fputs(g_szPrintBanner, f);
|
||||
fputc('\n', f);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CDlgBannerSetting
|
||||
|
||||
@@ -378,6 +411,7 @@ void CDlgBannerSetting::DoDataExchange(CDataExchange* pDX)
|
||||
BOOL CDlgBannerSetting::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
LoadBannerTextFile();
|
||||
SetDlgItemText(IDC_BANNER_TEXT, g_szPrintBanner);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -385,11 +419,7 @@ BOOL CDlgBannerSetting::OnInitDialog()
|
||||
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);
|
||||
SaveBannerTextFile();
|
||||
|
||||
CDialog::OnOK();
|
||||
}
|
||||
|
||||
@@ -269,7 +269,8 @@ static RECT s_rcTextMargin; // check!!! - margin 2 panes on bottom relative to t
|
||||
static int s_nTextHeight; // check!!! - text line height
|
||||
|
||||
// Configurable banner text printed at the bottom of each sheet.
|
||||
// Set via [battle tech print] BannerText= in options.ini next to the exe.
|
||||
// Primary source: banner.txt next to mw4print.exe (first line only).
|
||||
// Legacy fallback: [battle tech print] BannerText= in options.ini.
|
||||
char g_szPrintBanner[256] = "Join the worlds greatest Battletech community at WWW.MECHJOCK.COM today!";
|
||||
|
||||
void _stdcall GetFileName4GUID(char szBuf[256], const char* pcszDrv, const char* pcszPath, const char* pcszExt, const GUID& guid = *(const GUID*)NULL);
|
||||
@@ -3490,7 +3491,7 @@ bool CRecScoreFull::LoadPR(const char* pcszFile)
|
||||
void CRecScoreFull::LoadPrintParams() const
|
||||
{
|
||||
MString strOI(&AssetsDirectory1[0]);
|
||||
strOI += "options.ini";
|
||||
strOI += "\\options.ini";
|
||||
|
||||
LoadPrintParam(strOI, "CellMarginLR", s_nCellMarginLR, U_point(200), U_point(10), U_point(500));
|
||||
LoadPrintParam(strOI, "CellMarginTV", s_nCellMarginTV, U_point(200), U_point(10), U_point(500));
|
||||
@@ -3512,9 +3513,33 @@ void CRecScoreFull::LoadPrintParams() const
|
||||
LoadPrintParam(strOI, "TextHeight", s_nTextHeight, U_point(1100), U_point(600), U_point(1500));
|
||||
|
||||
// Configurable banner/URL text printed at the bottom of each sheet.
|
||||
GetPrivateProfileString("battle tech print", "BannerText",
|
||||
"Join the worlds greatest Battletech community at WWW.MECHJOCK.COM today!",
|
||||
g_szPrintBanner, sizeof(g_szPrintBanner), strOI);
|
||||
// Prefer banner.txt for persistence (game may sanitize unknown options.ini keys).
|
||||
bool bLoadedBanner = false;
|
||||
{
|
||||
char szBannerPath[MAX_PATH];
|
||||
sprintf(szBannerPath, "%s\\banner.txt", AssetsDirectory1);
|
||||
FILE* fBanner = fopen(szBannerPath, "rt");
|
||||
if (fBanner) {
|
||||
char szBuf[sizeof(g_szPrintBanner)];
|
||||
if (fgets(szBuf, sizeof(szBuf), fBanner)) {
|
||||
size_t n = strlen(szBuf);
|
||||
while (n && (szBuf[n - 1] == '\r' || szBuf[n - 1] == '\n')) {
|
||||
szBuf[--n] = '\0';
|
||||
}
|
||||
if (szBuf[0]) {
|
||||
strncpy(g_szPrintBanner, szBuf, sizeof(g_szPrintBanner) - 1);
|
||||
g_szPrintBanner[sizeof(g_szPrintBanner) - 1] = '\0';
|
||||
bLoadedBanner = true;
|
||||
}
|
||||
}
|
||||
fclose(fBanner);
|
||||
}
|
||||
}
|
||||
if (!bLoadedBanner) {
|
||||
GetPrivateProfileString("battle tech print", "BannerText",
|
||||
"Join the worlds greatest Battletech community at WWW.MECHJOCK.COM today!",
|
||||
g_szPrintBanner, sizeof(g_szPrintBanner), strOI);
|
||||
}
|
||||
LoadPrintParam(strOI, "ImageTitleHeight", g_aFonts[FNTI_IMAGE_TITLE].m_nTextHeight, U_point(1500), U_point(900), U_point(2000));
|
||||
LoadPrintParam(strOI, "TableTextHeight", g_aFonts[FNTI_TABLE_TEXT].m_nTextHeight, U_point(900), U_point(600), U_point(1200));
|
||||
LoadPrintParam(strOI, "MHTextHeight", g_aFonts[FNTI_MISSION_HIGHLIGHTS].m_nTextHeight, U_point(1200), U_point(800), U_point(1600));
|
||||
|
||||
Reference in New Issue
Block a user