From: Toni Wilen Date: Sun, 5 Jul 2026 17:31:30 +0000 (+0300) Subject: Print to file X-Git-Url: https://gitweb.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=1b9b87e7b0839e927b5e98ab176eb1e07ccf3282;p=francis%2Fwinuae.git Print to file --- diff --git a/include/options.h b/include/options.h index 68412f93..43a5fa59 100644 --- a/include/options.h +++ b/include/options.h @@ -791,8 +791,8 @@ struct uae_prefs { TCHAR cartident[256]; int cart_internal; TCHAR pci_devices[256]; - TCHAR prtname[256]; - TCHAR sername[256]; + TCHAR prtname[MAX_DPATH]; + TCHAR sername[MAX_DPATH]; TCHAR a2065name[MAX_DPATH]; TCHAR ne2000pciname[MAX_DPATH]; TCHAR ne2000pcmcianame[MAX_DPATH]; diff --git a/od-win32/parser.cpp b/od-win32/parser.cpp index e365347e..7b3750b3 100644 --- a/od-win32/parser.cpp +++ b/od-win32/parser.cpp @@ -38,6 +38,7 @@ #include "ahidsound_new.h" #include "xwin.h" #include "drawing.h" +#include "uae.h" #ifdef WITH_MIDIEMU #include "midiemu.h" #endif @@ -55,6 +56,7 @@ static uae_char prtbuf[PRTBUFSIZE]; static int prtbufbytes,wantwrite; static HANDLE hPrt = INVALID_HANDLE_VALUE; +static struct zfile *PrtFile = NULL; static DWORD dwJob; static int prtopen; void DoSomeWeirdPrintingStuff(uae_char val); @@ -275,7 +277,7 @@ static void flushprtbuf (void) return; } #endif - if (hPrt == INVALID_HANDLE_VALUE) { + if (hPrt == INVALID_HANDLE_VALUE && PrtFile == NULL) { if (!doflushprinter(prtopen)) return; openprinter (); @@ -287,6 +289,8 @@ static void flushprtbuf (void) } else { write_log (_T("PRINTER: Couldn't write data!\n")); } + } else if (PrtFile != NULL) { + zfile_fwrite(prtbuf, pbyt, 1, PrtFile); } } @@ -503,13 +507,13 @@ static DWORD GetPrinterDriverVersion(HANDLE handle) return version; } -static void openprinter (void) +static void openprinter(void) { DOC_INFO_1 DocInfo; static int first; DWORD error = 0; - closeprinter (); + closeprinter(); if (!currprefs.prtname[0]) return; @@ -517,10 +521,25 @@ static void openprinter (void) prtopen = 1; return; } else if (currprefs.parallel_matrix_emulation >= PARALLEL_MATRIX_EPSON) { - epson_init (currprefs.prtname, currprefs.parallel_matrix_emulation); + epson_init(currprefs.prtname, currprefs.parallel_matrix_emulation); } else if (hPrt == INVALID_HANDLE_VALUE) { - flushprtbuf (); - if (OpenPrinter (currprefs.prtname, &hPrt, NULL)) { + flushprtbuf(); + if (!_tcsnicmp(currprefs.prtname, _T("FILE:"), 5)) { + TCHAR path[MAX_DPATH]; + fetch_datapath(path, sizeof(path) / sizeof(TCHAR)); + _tcscat(path, currprefs.prtname + 5); + fixtrailing(path); + for (int idx = 0; idx < 1000; idx++) { + TCHAR path2[MAX_DPATH]; + _tcscpy(path2, path); + _stprintf(path2 + _tcslen(path2), _T("Print_%03d.dat"), idx); + if (zfile_exists(path2)) { + continue; + } + PrtFile = zfile_fopen(path2, _T("wb")); + break; + } + } else if (OpenPrinter (currprefs.prtname, &hPrt, NULL)) { DWORD version = GetPrinterDriverVersion(hPrt); // Fill in the structure with info about this "document." DocInfo.pDocName = _T("WinUAE Document"); @@ -540,6 +559,8 @@ static void openprinter (void) } if (hPrt != INVALID_HANDLE_VALUE) { write_log (_T("PRINTER: Opening printer \"%s\" with handle 0x%x.\n"), currprefs.prtname, hPrt); + } else if (PrtFile != NULL) { + write_log(_T("PRINTER: Opening file printer \"%s\".\n"), currprefs.prtname + 5); } else if (*currprefs.prtname) { write_log (_T("PRINTER: ERROR - Couldn't open printer \"%s\" for output. Error %08x\n"), currprefs.prtname, error); } @@ -558,8 +579,9 @@ void flushprinter(void) return; } #endif - if (!doflushprinter(prtopen)) + if (!doflushprinter(prtopen)) { return; + } flushprtbuf(); closeprinter(); } @@ -578,6 +600,11 @@ void closeprinter (void) hPrt = INVALID_HANDLE_VALUE; write_log (_T("PRINTER: Closing printer.\n")); } + if (PrtFile != NULL) { + zfile_fclose(PrtFile); + PrtFile = NULL; + write_log(_T("PRINTER: Closing file printer.\n")); + } if (currprefs.parallel_postscript_emulation) prtopen = 1; else diff --git a/od-win32/resources/resource.h b/od-win32/resources/resource.h index b4f6b839..00fddbf2 100644 --- a/od-win32/resources/resource.h +++ b/od-win32/resources/resource.h @@ -447,6 +447,7 @@ #define IDS_SYNCMODE_COMBINED2 453 #define IDS_SYNCMODE_CSYNC2 454 #define IDS_SYNCMODE_HVSYNC2 455 +#define IDS_PRINTER_PRINT_TO_FILE 456 #define IDS_QS_MODELS 1000 #define IDS_QS_MODEL_A500 1001 #define IDS_QS_MODEL_A500P 1002 diff --git a/od-win32/resources/winuae.rc b/od-win32/resources/winuae.rc index 4332d089..2929d67a 100644 --- a/od-win32/resources/winuae.rc +++ b/od-win32/resources/winuae.rc @@ -2241,6 +2241,7 @@ BEGIN IDS_SYNCMODE_COMBINED2 "Combined + Sync" IDS_SYNCMODE_CSYNC2 "Composite Sync + Sync" IDS_SYNCMODE_HVSYNC2 "H/V Sync + Sync" + IDS_PRINTER_PRINT_TO_FILE "Print to file" END STRINGTABLE diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index b42ce198..49d16f07 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -5012,18 +5012,18 @@ static int target_parse_option_host(struct uae_prefs *p, const TCHAR *option, co return 1; } - if (cfgfile_string_escape(option, value, _T("parallel_port"), &p->prtname[0], 256)) { + if (cfgfile_string_escape(option, value, _T("parallel_port"), &p->prtname[0], sizeof(p->prtname) / sizeof(TCHAR))) { if (!_tcscmp(p->prtname, _T("none"))) p->prtname[0] = 0; if (!_tcscmp(p->prtname, _T("default"))) { p->prtname[0] = 0; - DWORD size = 256; + DWORD size = sizeof(p->prtname) / sizeof(TCHAR); GetDefaultPrinter(p->prtname, &size); } return 1; } - if (cfgfile_string_escape(option, value, _T("midiout_device_name"), tmpbuf, 256)) { + if (cfgfile_string_escape(option, value, _T("midiout_device_name"), tmpbuf, sizeof(tmpbuf) / sizeof(TCHAR))) { p->win32_midioutdev = -2; if (!_tcsicmp (tmpbuf, _T("default")) || (midioutportinfo[0] && !_tcsicmp (tmpbuf, midioutportinfo[0]->name))) p->win32_midioutdev = -1; @@ -5034,7 +5034,7 @@ static int target_parse_option_host(struct uae_prefs *p, const TCHAR *option, co } return 1; } - if (cfgfile_string_escape(option, value, _T("midiin_device_name"), tmpbuf, 256)) { + if (cfgfile_string_escape(option, value, _T("midiin_device_name"), tmpbuf, sizeof(tmpbuf) / sizeof(TCHAR))) { p->win32_midiindev = -1; for (int i = 0; i < MAX_MIDI_PORTS && midiinportinfo[i]; i++) { if (!_tcsicmp (midiinportinfo[i]->name, tmpbuf)) { diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index 6ad2da7b..afa505b7 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -17882,7 +17882,7 @@ static void enable_for_portsdlg (HWND hDlg) ew (hDlg, IDC_SAMPLERLIST, issampler); ew (hDlg, IDC_SAMPLER_STEREO, issampler && workprefs.win32_samplersoundcard >= 0); ew (hDlg, IDC_PRINTERAUTOFLUSH, isprinter); - ew (hDlg, IDC_PRINTERTYPELIST, isprinter); + ew (hDlg, IDC_PRINTERTYPELIST, isprinter && _tcsnicmp(workprefs.prtname, _T("FILE:"), 5)); ew (hDlg, IDC_FLUSHPRINTER, isprinteropen () && isprinter ? TRUE : FALSE); ew (hDlg, IDC_PSPRINTER, full_property_sheet && ghostscript_available && isprinter ? TRUE : FALSE); ew (hDlg, IDC_PSPRINTERDETECT, full_property_sheet && isprinter ? TRUE : FALSE); @@ -18105,6 +18105,7 @@ static void values_from_portsdlg (HWND hDlg) TCHAR tmp[256]; BOOL success; int item; + static const GUID printtofileguid = { 0xdd1fbb39, 0xea59, 0x4523, { 0x82, 0xc9, 0xc4, 0x58, 0xcf, 0xe6, 0x1c, 0x8c } }; item = xSendDlgItemMessage (hDlg, IDC_SAMPLERLIST, CB_GETCURSEL, 0, 0L); if(item != CB_ERR) { @@ -18120,9 +18121,23 @@ static void values_from_portsdlg (HWND hDlg) if(item != CB_ERR) { int got = 0; _tcscpy (tmp, workprefs.prtname); - if (item > 0) { + if (item == 1) { + TCHAR path[MAX_DPATH] = { 0 }; + if (!_tcsnicmp(workprefs.prtname, _T("FILE:"), 5)) { + _tcscpy(path, workprefs.prtname + 5); + } + if (DirectorySelection(hDlg, &printtofileguid, path)) { + _tcscpy(workprefs.prtname, _T("FILE:")); + _tcscat(workprefs.prtname, path); + got = 1; + ew(hDlg, IDC_PRINTERTYPELIST, FALSE); + } else { + xSendDlgItemMessage(hDlg, IDC_PRINTERLIST, CB_SETCURSEL, 0, 0L); + } + xSendDlgItemMessage(hDlg, IDC_PRINTERTYPELIST, CB_SETCURSEL, 0, 0L); + } else if (item > 1) { workprefs.win32_samplersoundcard = -1; - item--; + item -= 2; if (item < dwEnumeratedPrinters) { _tcscpy (workprefs.prtname, pInfo[item].pName); got = 1; @@ -18194,7 +18209,9 @@ static void values_to_portsdlg (HWND hDlg) CheckDlgButton (hDlg, IDC_SAMPLER_STEREO, workprefs.sampler_stereo); result = 0; - if(workprefs.prtname[0]) { + if (!_tcsnicmp(workprefs.prtname, _T("FILE:"), 5)) { + result = 1; + } else if(workprefs.prtname[0]) { int i, got = 1; TCHAR tmp[10]; result = xSendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_FINDSTRINGEXACT, -1, (LPARAM)workprefs.prtname); @@ -18280,7 +18297,7 @@ static void values_to_portsdlg (HWND hDlg) WIN32GUI_LoadUIString (IDS_INVALIDCOMPORT, szMessage, MAX_DPATH); pre_gui_message (szMessage); // Select "none" as the COM-port - xSendDlgItemMessage (hDlg, IDC_SERIAL, CB_SETCURSEL, 0L, 0L); + xSendDlgItemMessage(hDlg, IDC_SERIAL, CB_SETCURSEL, 0L, 0L); // Disable the chosen serial-port selection workprefs.sername[0] = 0; workprefs.use_serial = 0; @@ -18288,11 +18305,11 @@ static void values_to_portsdlg (HWND hDlg) workprefs.use_serial = 1; } } - xSendDlgItemMessage (hDlg, IDC_DONGLELIST, CB_SETCURSEL, workprefs.dongle, 0L); + xSendDlgItemMessage(hDlg, IDC_DONGLELIST, CB_SETCURSEL, workprefs.dongle, 0L); } -static void init_portsdlg (HWND hDlg) +static void init_portsdlg(HWND hDlg) { static int first; int port; @@ -18300,8 +18317,8 @@ static void init_portsdlg (HWND hDlg) if (!first) { first = 1; - if (load_ghostscript () > 0) { - unload_ghostscript (); + if (load_ghostscript() > 0) { + unload_ghostscript(); ghostscript_available = 1; } } @@ -18327,14 +18344,14 @@ static void init_portsdlg (HWND hDlg) xSendDlgItemMessage(hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)_T("Multi-Player Soccer Manager")); xSendDlgItemMessage(hDlg, IDC_DONGLELIST, CB_ADDSTRING, 0, (LPARAM)_T("Football Director 2")); - xSendDlgItemMessage (hDlg, IDC_SERIAL, CB_RESETCONTENT, 0, 0L); - xSendDlgItemMessage (hDlg, IDC_SERIAL, CB_ADDSTRING, 0, (LPARAM)szNone.c_str()); + xSendDlgItemMessage(hDlg, IDC_SERIAL, CB_RESETCONTENT, 0, 0L); + xSendDlgItemMessage(hDlg, IDC_SERIAL, CB_ADDSTRING, 0, (LPARAM)szNone.c_str()); for (port = 0; port < MAX_SERPAR_PORTS && comports[port]; port++) { if (!_tcsicmp(comports[port]->dev, SERIAL_INTERNAL)) { _tcscpy(tmp, comports[port]->name); if (!shmem_serial_state()) shmem_serial_create(); - switch(shmem_serial_state()) + switch (shmem_serial_state()) { case 1: _tcscat(tmp, _T(" [Master]")); @@ -18343,41 +18360,48 @@ static void init_portsdlg (HWND hDlg) _tcscat(tmp, _T(" [Slave]")); break; } - xSendDlgItemMessage (hDlg, IDC_SERIAL, CB_ADDSTRING, 0, (LPARAM)tmp); + xSendDlgItemMessage(hDlg, IDC_SERIAL, CB_ADDSTRING, 0, (LPARAM)tmp); } else { - xSendDlgItemMessage (hDlg, IDC_SERIAL, CB_ADDSTRING, 0, (LPARAM)comports[port]->name); - } - } - - xSendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_RESETCONTENT, 0, 0L); - WIN32GUI_LoadUIString (IDS_PRINTER_PASSTHROUGH, tmp, MAX_DPATH); - xSendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_PRINTER_ASCII, tmp, MAX_DPATH); - xSendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_PRINTER_EPSON9, tmp, MAX_DPATH); - xSendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_PRINTER_EPSON48, tmp, MAX_DPATH); - xSendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_PRINTER_POSTSCRIPT_DETECTION, tmp, MAX_DPATH); - xSendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); - WIN32GUI_LoadUIString (IDS_PRINTER_POSTSCRIPT_EMULATION, tmp, MAX_DPATH); - xSendDlgItemMessage (hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); - - xSendDlgItemMessage (hDlg, IDC_SAMPLERLIST, CB_RESETCONTENT, 0, 0L); - xSendDlgItemMessage (hDlg, IDC_SAMPLERLIST, CB_ADDSTRING, 0, (LPARAM)szNone.c_str()); - enumerate_sound_devices (); + xSendDlgItemMessage(hDlg, IDC_SERIAL, CB_ADDSTRING, 0, (LPARAM)comports[port]->name); + } + } + + xSendDlgItemMessage(hDlg, IDC_PRINTERTYPELIST, CB_RESETCONTENT, 0, 0L); + WIN32GUI_LoadUIString(IDS_PRINTER_PASSTHROUGH, tmp, MAX_DPATH); + xSendDlgItemMessage(hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString(IDS_PRINTER_ASCII, tmp, MAX_DPATH); + xSendDlgItemMessage(hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString(IDS_PRINTER_EPSON9, tmp, MAX_DPATH); + xSendDlgItemMessage(hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString(IDS_PRINTER_EPSON48, tmp, MAX_DPATH); + xSendDlgItemMessage(hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString(IDS_PRINTER_POSTSCRIPT_DETECTION, tmp, MAX_DPATH); + xSendDlgItemMessage(hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); + WIN32GUI_LoadUIString(IDS_PRINTER_POSTSCRIPT_EMULATION, tmp, MAX_DPATH); + xSendDlgItemMessage(hDlg, IDC_PRINTERTYPELIST, CB_ADDSTRING, 0, (LPARAM)tmp); + + xSendDlgItemMessage(hDlg, IDC_SAMPLERLIST, CB_RESETCONTENT, 0, 0L); + xSendDlgItemMessage(hDlg, IDC_SAMPLERLIST, CB_ADDSTRING, 0, (LPARAM)szNone.c_str()); + enumerate_sound_devices(); for (int card = 0; card < MAX_SOUND_DEVICES && record_devices[card]; card++) { int type = record_devices[card]->type; TCHAR tmp[MAX_DPATH]; - _stprintf (tmp, _T("%s: %s"), + _stprintf(tmp, _T("%s: %s"), type == SOUND_DEVICE_XAUDIO2 ? _T("XAudio2") : (type == SOUND_DEVICE_DS ? _T("DSOUND") : (type == SOUND_DEVICE_AL ? _T("OpenAL") : (type == SOUND_DEVICE_PA ? _T("PortAudio") : _T("WASAPI")))), record_devices[card]->name); if (type == SOUND_DEVICE_DS) - xSendDlgItemMessage (hDlg, IDC_SAMPLERLIST, CB_ADDSTRING, 0, (LPARAM)tmp); + xSendDlgItemMessage(hDlg, IDC_SAMPLERLIST, CB_ADDSTRING, 0, (LPARAM)tmp); } - xSendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_RESETCONTENT, 0, 0L); - xSendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_ADDSTRING, 0, (LPARAM)szNone.c_str()); + xSendDlgItemMessage(hDlg, IDC_PRINTERLIST, CB_RESETCONTENT, 0, 0L); + xSendDlgItemMessage(hDlg, IDC_PRINTERLIST, CB_ADDSTRING, 0, (LPARAM)szNone.c_str()); + WIN32GUI_LoadUIString(IDS_PRINTER_PRINT_TO_FILE, tmp, MAX_DPATH); + if (!_tcsnicmp(workprefs.prtname, _T("FILE:"), 5)) { + _tcscat(tmp, _T(" (")); + _tcscat(tmp, workprefs.prtname + 5); + _tcscat(tmp, _T(")")); + } + xSendDlgItemMessage(hDlg, IDC_PRINTERLIST, CB_ADDSTRING, 0, (LPARAM)tmp); if(!pInfo) { int flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS; DWORD needed = 0; @@ -18394,10 +18418,9 @@ static void init_portsdlg (HWND hDlg) } } if (pInfo) { - for(port = 0; port < (int)dwEnumeratedPrinters; port++) + for(port = 0; port < (int)dwEnumeratedPrinters; port++) { xSendDlgItemMessage (hDlg, IDC_PRINTERLIST, CB_ADDSTRING, 0, (LPARAM)pInfo[port].pName); - } else { - ew (hDlg, IDC_PRINTERLIST, FALSE); + } } if (paraport_mask) { int mask = paraport_mask;