mw4print: add -debug flag for step-by-step diagnostic logging

Adds runtime diagnostic logging to track down why printing is broken.
Pass -debug (or /debug) on the command line; all output goes to
mw4print-debug.txt next to the exe (append mode, timestamped lines).
No effect on normal operation when the flag is absent.

What is logged:
- Startup: AssetsDirectory1 path and full command line
- OnCreate: DB config loaded, timer created
- DoCopyData / OnFileOpen: each file queued for printing with filename
- OnTimer: which file is being processed each second, LoadPR result
- DoPrint: nPlayers count, PrintDlg call + result (on failure logs
  CommDlgExtendedError hex code), DB export call/result, SetupFonts
  result, StartDoc result, EndDoc vs AbortDoc, final return code

The CommDlgExtendedError value on a PrintDlg failure will identify the
root cause (e.g. CDERR_NODEFAULTPRN = no default printer configured).

Co-authored-by: Claude Sonnet 4.6 (Anthropic) <noreply@anthropic.com>
Co-authored-by: GitHub Copilot <copilot@github.com>
This commit is contained in:
2026-08-07 21:53:02 -05:00
co-authored by Claude Sonnet 4.6 GitHub Copilot
parent 10301ee5dd
commit 3256c103a2
5 changed files with 88 additions and 3 deletions
@@ -1,6 +1,27 @@
ReplicatorID ReplicatorID::Null;
char AssetsDirectory1[MAX_PATH];
HWND hWindow;
bool g_bDebugLog = false;
void DbgLog(const char* fmt, ...)
{
if (!g_bDebugLog) return;
char szPath[MAX_PATH];
sprintf(szPath, "%s\\mw4print-debug.txt", AssetsDirectory1);
FILE* f = fopen(szPath, "at");
if (f) {
SYSTEMTIME st;
GetLocalTime(&st);
fprintf(f, "[%02d:%02d:%02d.%03d] ",
st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
va_list args;
va_start(args, fmt);
vfprintf(f, fmt, args);
va_end(args);
fputc('\n', f);
fclose(f);
}
}
MemoryStream::MemoryStream(
void *stream_start,