int DecodeDlg::DecIcon( int row, // Row in UD.DFile const char *cs) // Calculated output filename { int rc; int f = decoder->UD.GetDFileFlags(row); if (decoder->UD.GetDFileInfo(row).IsEmpty()) // No Info { if (f & CUud32acxCtrl::uudFileDecoded) rc = SI_DECODEDOK; else if (f & CUud32acxCtrl::uudFileError) rc = SI_DECODEFAILED; else if (f & CUud32acxCtrl::uudFileOK) { if (cs != NULL && cs[0] != EOS && FExist(cs)) rc = SI_CONFLICT; else rc = SI_OK; } else if (f & CUud32acxCtrl::uudFileNoEnd) rc = SI_QUESTION; else if (f & (CUud32acxCtrl::uudFileNoBegin | CUud32acxCtrl::uudFileMisPart | CUud32acxCtrl::uudFileNoData)) rc = SI_BAD; else rc = SI_QUESTION; } else { // There IS info if (f & CUud32acxCtrl::uudFileDecoded) rc = SI_DECODEDOK; else if (f & CUud32acxCtrl::uudFileError) rc = SI_DECODEFAILED; else if (f & CUud32acxCtrl::uudFileOK) { if (cs != NULL && cs[0] != EOS && FExist(cs)) rc = SII_CONFLICT; else rc = SII_OK; } else if (f & CUud32acxCtrl::uudFileNoEnd) rc = SII_QUESTION; else if (f & (CUud32acxCtrl::uudFileNoBegin | CUud32acxCtrl::uudFileMisPart | CUud32acxCtrl::uudFileNoData)) rc = SII_BAD; else rc = SII_QUESTION; } return(rc); }
void RenOutFile::OnChangeRenFileName() { CString nfn; m_FileName.GetWindowText(nfn); if (FExist(*pathPointer + nfn)) { m_OWrite.Enable(); m_Rename.Disable(); SetDefID(m_OWrite.GetDlgCtrlID()); } else { m_OWrite.Disable(); m_Rename.Enable(); SetDefID(m_Rename.GetDlgCtrlID()); } if (nfn.CompareNoCase(origValue) == 0) c_ResetButton.Disable(); else c_ResetButton.Enable(); }
STDMETHODIMP CUUEngine::DFileTo(short row, BSTR outn, long *retVal) { uulist *ptr = ue.GetUulp(row); if (ptr == NULL) return(CTL_E_INVALIDPROPERTYARRAYINDEX); if (ptr->filename == NULL || (ptr->state & UUFILE_NODATA)) { *retVal = UURET_NODATA; // Do data to decode return(S_OK); } MString outname(outn); char *syserr; DWORD lasterr; short rc; NewStep(); // Let the owner know we're starting a new step rc = ue.UUDecode(ptr); // Decode and get errors if (ptr->binfile == NULL) return(rc); // Couldn't decode/create temp if (FExist(outname)) { // Deal with an existing output file if (OWriteOK) { // Overwriting is OK if (DeleteFile(outname) == FALSE) { // Try to delete it MessageHandler("Could not delete existing output file", UUMSG_ERROR); *retVal = UURET_IOERR; return(S_OK); } } else { // Overwriting not OK MessageHandler("Output file exists", UUMSG_ERROR); *retVal = UURET_EXISTS; return(S_OK); } } // Output file doesn't exist. OK to go. if (MoveFile(ptr->binfile, outname) == FALSE) { // Something went wrong during move lasterr = ::GetLastError(); // Read the error code if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, lasterr, GetUserDefaultLangID(), (LPTSTR) &syserr, 0, NULL) == 0) MessageHandler("Unknown Error", UUMSG_ERROR); // Couldn't convert error number to string else { MessageHandler(syserr, UUMSG_ERROR); // Got a conversion LocalFree(syserr); // Discard the error string after passing it on } *retVal = UURET_IOERR; return(S_OK); } free(ptr->binfile); // Temp file is gone, wasted by MoveFile ptr->binfile = NULL; ptr->state = (ptr->state & ~UUFILE_TMPFILE) | UUFILE_DECODED; *retVal = rc; return S_OK; }
STDMETHODIMP CUUEngine::Encode( BSTR i_iname, BSTR i_oname, BSTR i_nameinfile, long encoding, long lines, long headers, VARIANT destvar, VARIANT fromvar, VARIANT subjectvar, long *retVal) { FILE *outf; int rc, partno; char *onp, *extp, *partname; const char *dest, *from, *subject; MString deststr, fromstr, subjstr; MString iname(i_iname), oname(i_oname), nameinfile(i_nameinfile); dest = (const char *) destvar.bstrVal; if (destvar.vt != VT_BSTR || *dest == EOS) dest = NULL; else { deststr = destvar.bstrVal; dest = (const char *) deststr; } from = (const char *) fromvar.bstrVal; if (fromvar.vt != VT_BSTR || *from == EOS) from = NULL; else { fromstr = fromvar.bstrVal; from = (const char *) fromstr; } subject = (const char *) subjectvar.bstrVal; if (subjectvar.vt != VT_BSTR || *subject == EOS) subject = NULL; else { subjstr = subjectvar.bstrVal; subject = (const char *) subjstr; } if (nameinfile != NULL && nameinfile[0] != EOS) onp = nameinfile.GetBuffer(); // Caller has specified a name else { // Generate our own if ((onp = strrchr(iname, '\\')) == NULL) { // Look for last slash if ((onp = strrchr(iname, ':')) == NULL) onp = iname.GetBuffer(); // No colons, either else onp++; // Point just past colon } else onp++; // Point just past last slash } if (lines == 0 && (extp = strrchr(oname, '.')) != NULL) // Set single-part extension ue.UUSetOption(UUOPT_ENCEXT, 0, extp+1); if (headers) { // User wants headers if (lines == 0) { // Single file if (!OWriteOK && FExist(oname)) { // Can't overwrite output file MessageHandler("Output file exists", UUMSG_ERROR); *retVal = UURET_EXISTS; return(S_OK); } if ((outf = fopen(oname, "w")) == NULL) { MessageHandler("Could not open output file", 1); *retVal = UURET_IOERR; return(S_OK); } NewStep(); // Warn the owner if (headers == UUVBE_SIMPLE) rc = ue.UUEncodeMulti(outf, NULL, iname.GetBuffer(), encoding, onp, NULL, 0); else rc = ue.UUE_PrepSingle(outf, NULL, iname.GetBuffer(), encoding, onp, 0, (char *) dest, (char *) from, (char *) subject, (headers == UUVBE_MAIL)); fclose(outf); } else { // Multi part MString partlocal(oname); // Copy the output name partname = partlocal.GetBuffer(strlen(oname) + 10); // Grab the buffer if ((extp = strrchr(partname, '.')) == NULL) { // No extension? Add one... extp = partname + strlen(partname); *extp++ = '.'; } else extp++; // Just past the last period partno = 1; // First part do { // Always have at least one... sprintf(extp, "%03d", partno); if (!OWriteOK && FExist(partname)) { // Can't overwrite output file MessageHandler("Output file exists", UUMSG_ERROR); *retVal = UURET_EXISTS; return(S_OK); } if ((outf = fopen(partname, "w")) == NULL) { MessageHandler("Error opening output file.", 1); *retVal = UURET_IOERR; return(S_OK); } NewStep(); // Warn the owner crc32_t lcr = 0; if (headers == UUVBE_SIMPLE) rc = ue.UUEncodePartial(outf, NULL, iname.GetBuffer(), encoding, onp, NULL, 0, partno++, (int) lines, &lcr); else rc = ue.UUE_PrepPartial(outf, NULL, iname.GetBuffer(), encoding, onp, 0, partno++, (int) lines, 0, (char *) dest, (char *) from, (char *) subject, (headers == UUVBE_MAIL)); fclose(outf); } while (rc == UURET_CONT); } } else { NewStep(); // Warn the owner rc = ue.UUEncodeToFile(NULL, iname.GetBuffer(), encoding, onp, oname.GetBuffer(), (int) lines); } *retVal = rc; return S_OK; }