diff --git a/src/syncterm/term.c b/src/syncterm/term.c index 8da34d3b23f8001b38b69b7794eb53900d0b2cbe..c0279113e06069ca13682bd3f1ac23a83074ac13 100644 --- a/src/syncterm/term.c +++ b/src/syncterm/term.c @@ -21,6 +21,7 @@ #include "zmodem.h" #include "xmodem.h" #include "telnet_io.h" +#include "saucedefs.h" #ifdef WITH_WXWIDGETS #include "htmlwin.h" #endif @@ -2031,24 +2032,73 @@ void capture_control(struct bbslist *bbs) if(!cterm->log) { struct file_pick fpick; - char *opts[3]={ + char *opts[]={ "ASCII" ,"Raw" + ,"Binary" + ,"Binary with SAUCE" ,"" }; i=0; - uifc.helpbuf="`Capture Type`\n\n" - "~ ASCII ~ Strips out ANSI sequences\n" - "~ Raw ~ Leaves ANSI sequences in\n\n" - "Raw is useful for stealing ANSI screens from other systems.\n" - "Don't do that though. :-)"; + uifc.helpbuf="~ Capture Type ~\n\n" + "`ASCII` ASCII only (no ANSI escape sequences)\n" + "`Raw` Preserves ANSI sequences\n" + "`Binary` Saves current screen in IBM-CGA/BinaryText format\n" + "`Binary with SAUCE` Saves current screen in BinaryText format with SAUCE\n" + "\n" + "Raw is useful for stealing ANSI screens from other systems.\n" + "Don't do that though. :-)"; if(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,NULL,"Capture Type",opts)!=-1) { - j=filepick(&uifc, "Capture File", &fpick, bbs->dldir, NULL, UIFC_FP_ALLOWENTRY); + j=filepick(&uifc, "Capture File", &fpick, bbs->dldir, i >= 2 ? "*.bin" : NULL + , UIFC_FP_ALLOWENTRY|UIFC_FP_OVERPROMPT); check_exit(FALSE); - if(j!=-1 && fpick.files>=1) - cterm_openlog(cterm, fpick.selected[0], i?CTERM_LOG_RAW:CTERM_LOG_ASCII); + if(j!=-1 && fpick.files>=1) { + if(i >= 2) { + FILE* fp = fopen(fpick.selected[0], "wb"); + if(fp == NULL) { + char err[256]; + sprintf(err, "Error %u opening file '%s'", errno, fpick.selected[0]); + uifc.msg(err); + } else { + char msg[256]; + uifc.pop("Writing to file"); + fwrite(buf, sizeof(uint8_t), txtinfo.screenwidth * txtinfo.screenheight * 2, fp); + if(i > 2) { + time_t t = time(NULL); + struct tm* tm; + struct sauce sauce; + + memset(&sauce, 0, sizeof(sauce)); + memcpy(sauce.id, SAUCE_ID, sizeof(sauce.id)); + memcpy(sauce.ver, SAUCE_VERSION, sizeof(sauce.ver)); + memset(sauce.title, ' ', sizeof(sauce.title)); + memset(sauce.author, ' ', sizeof(sauce.author)); + memset(sauce.group, ' ', sizeof(sauce.group)); + if(bbs != NULL) { + memcpy(sauce.title, bbs->name, min(strlen(bbs->name), sizeof(sauce.title))); + memcpy(sauce.author, bbs->user, min(strlen(bbs->user), sizeof(sauce.author))); + } + if((tm=localtime(&t)) != NULL) // The null-terminator overwrites the first byte of filesize + sprintf(sauce.date, "%04u%02u%02u" + ,1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday); + sauce.filesize = ftell(fp); // LE + sauce.datatype = sauce_datatype_bin; + sauce.filetype = txtinfo.screenwidth / 2; + + fputc(SAUCE_SEPARATOR, fp); + /* No comment block (no comments) */ + fwrite(&sauce, sizeof(sauce), 1, fp); + } + fclose(fp); + uifc.pop(NULL); + sprintf(msg, "Screen saved to '%s'", getfname(fpick.selected[0])); + uifc.msg(msg); + } + } else + cterm_openlog(cterm, fpick.selected[0], i?CTERM_LOG_RAW:CTERM_LOG_ASCII); + } filepick_free(&fpick); } else