int ZipOp::ZipStreamStream(void) { fwindow_size = 0L; if (fGEncrypt) { fkey = fGPassword; if (!fkey || !*(fkey)) { // use global if (GetUserPW() != DZ_ERR_GOOD) return -1; // error fkey = fuser_key; } } fZipInfile = new ZStream(this, _T("0:<INSTREAM>"), fSS->fSSInput); AutoStream inz(&fZipInfile); fimax = fSS->Size; fcrc = crc32(0L, NULL, 0); fisize = 0; CB->SetArg1(1); CB->UserCB(zacCount); // Pass total filesize. CB->SetFileSize(fimax); CB->UserCB(zacSize); ulg f_crc = 0; __int64 fsz = 0; bool haveCRC = false; if (fkey) { if (!fNoPrecalc) { if (Verbose < 0) Notify(ITRACE, _T("about to call Precalculate CRC")); // +++++ get CRC before we start CB->UserXItem(fimax, 13, _T("*PreCalculate")); __int64 pos1 = 0; if (!fZipInfile->IsFile) pos1 = fZipInfile->SetPosition(0, FILE_CURRENT); // get start posn f_crc = crc32(0L, NULL, 0); unsigned long byts; while (true) { unsigned ToRead = sizeof(fwindow); if (fimax > 0 && (fsz + ToRead) > fimax) { ToRead = (unsigned)(fimax - fsz); if (!ToRead) break; } if (!fZipInfile->Read(fwindow, ToRead, &byts) || !byts) break; fsz += byts; f_crc = crc32(f_crc, (const uch*)fwindow, (int)byts); CB->UserXProgress(byts, 13); if (Abort_Flag) Fatal(DZ_ERM_ABORT, 0); } fSS->CRC = f_crc; haveCRC = true; // reposition if (fZipInfile->SetPosition(pos1, FILE_BEGIN) != pos1) { if (Verbose) Notify(IVERBOSE, _T("Could not reposition %s [%s]"), fZipInfile->fname.c_str(), SysMsg().c_str()); return DZError(DZ_ERM_ERROR_SEEK); } if (fimax > fsz) fimax = fsz; } // ----- get CRC before we start // Since we do not yet know the crc here, we pretend that the crc is the // modification time: // if (!haveCRC) // fSS->CRC = z->tim << 16; if (Verbose < 0) Notify(ITRACE, _T("using supplied CRC %lu"), fSS->CRC); } // connect to output fZipOutfile = new ZStream(this, _T("0:<OUTSTREAM>"), fSS->fSSOutput); AutoStream outz(&fZipOutfile); CB->UserItem(fimax, _T("<INSTREAM>")); if (fkey) crypthead(fkey, fSS->CRC); // write // Write stored or deflated file to zip file fSS->Method &= 0xFF; if (fSS->Method != DEFLATE) fSS->Method = 0; if (flevel < 1) fSS->Method = 0; int mthd = (int)fSS->Method; if (mthd == DEFLATE) { if (Verbose < 0) Notify(ITRACE, _T("about to call Deflate")); bi_init(); ush att = BINARY; ush flg = FLAG_ENCRYPT_BIT; // will be changed in deflate() ct_init(&att, &mthd); lm_init(flevel, &flg); // PERFORM THE DEFLATE fSS->Size = deflate(); if (Abort_Flag) Fatal(DZ_ERM_ABORT, 0); } else { int k; if (Verbose) Notify(IVERBOSE, _T("Storing %s "), fZipInfile->fname.c_str()); while ((k = read_buf(fwindow, sizeof(fwindow))) > 0 && k != EOF) { if (Abort_Flag) Fatal(DZ_ERM_ABORT, 0); if (!zfwrite(fwindow, (extent)k)) return DZ_ERM_TEMP_FAILED; } } /* Finished Item */ CB->UserItem(-1, _T("<INSTREAM>")); // mark end of item CB->UserCB(zacEndOfBatch); // done with stream compression if (haveCRC) { if (f_crc != fcrc) Notify(DZ_ERR_ERROR_READ | IWARNING, _T(" File CRC changed while zipping: %s"), fZipInfile->fname.c_str()); if (fisize != fsz) Notify(DZ_ERR_ERROR_READ | IWARNING, _T(" File size changed while zipping: %s"), fZipInfile->fname.c_str()); } fSS->Size = fisize; fSS->CRC = fcrc; fSS->Method = (DWORD)mthd | (fkey ? 0xff00 : 0); return DZ_ERR_GOOD; }
/* =========================================================================== select files to be processed */ int ZipSelect(struct Globals *pG, const ZCL2 *C) { int i; // arg counter, root directory flag int k; // next argument type, marked counter, const char *p; // steps through option arguments int r; // temporary variable long g_before; // 1.74 global 'before' int argno, arg1; if ((p = getenv("TZ")) == NULL || *p == '\0') pG->extra_fields = 0; // disable storing "Unix" time stamps SetExclFilters(pG); // Process arguments diag("ready to read zip file", pG); // the read will be done in file: zipfile.c if ((r = readzipfile(pG)) != ZEN_OK) { diag("err returned from \"readzipfile\"", pG); return (ziperr(r, pG)); } if (pG->action == UPDATE || pG->action == FRESHEN) pG->doall = 1; r = 0; arg1 = - 1; g_before = pG->before; for (argno = 0; !r && argno < C->fTotFileSpecs; argno++) { char *fspec; FileData *fileArg = &C->fFDS[argno]; if (!fileArg) continue; fspec = fileArg->fFileSpec; if (!fspec || *fspec == '>') continue; pG->FileArg = fileArg; pG->key = 0; //pG->user_key; // set globals pG->recurse = fileArg->fRecurse; r = C->fLevel; r = r < 0 ? 0 : (r > 9 ? 9 : r); if (r != pG->level) { pG->level = r; pG->method = r ? DEFLATE : STORE; if (pG->verbose) Inform(pG, 0, IDIAG, "setting compression level to %d", r); } // Set the new RootDir if needed; DLL v1.608, Component v1.60L if (fileArg->fRootDir) { // We can't use SetCurrentDirectory() because there is only one cd // in each process // when a user uses threads it went wrong. FREE(pG->OrigCurrentDir); // DLL v1.6017 pG->OCDlength = lstrlen(fileArg->fRootDir); if ((pG->OrigCurrentDir = (char*)MALLOC(pG->OCDlength + 2)) == NULL) { // RP allow space for '\' Inform(pG, ZEN_MEM36, 0, "CurrentDir allocation error"); return ziperr(ZEN_MEM36, pG); } lstrcpy(pG->OrigCurrentDir, fileArg->fRootDir); if (pG->verbose) Inform(pG, 0, IERROR, "Root dir now %s", pG->OrigCurrentDir); } if (C->fVersion > 178) { if (fileArg->fLevel) { r = fileArg->fLevel; r = r < 0 ? 0 : (r > 9 ? 9 : r); if (r != pG->level) { pG->level = r; pG->method = r ? DEFLATE : STORE; if (pG->verbose) Inform(pG, 0, IDIAG, "setting compression level to %d", r); } } if (fileArg->fFromDate) pG->before = fileArg->fFromDate == (unsigned) - 1 ? 0 : fileArg ->fFromDate; else pG->before = g_before; } #ifdef USE_STRM_INPUT if (arg1 < 0) { arg1 = argno; if (pG->UseInStream) { // Here we fill in the FoundList from the input stream data // newname (fileio.c) adds to found list. If error m!=0 on return if ((r = newname(fspec, pG->InStreamSize, pG)) != ZEN_OK) { if (pG->verbose) Inform(pG, 0, IDIAG, "Stream filename could not be added in newname call"); if (pG->zcount) FREE(pG->zsort); return r; } break; } } #endif #ifdef CRYPT if (fileArg->fEncrypt) { pG->key = fileArg->fPassword; if (!pG->key || !*(pG->key)) { // use global if ((r = GetUserPW(pG)) != ZEN_OK) break; pG->key = pG->user_key; } // pG->doesEncrypt = 1; // 1.73 } #endif pG->doall = 0; // do selected if ((pG->action == ADD) || (pG->action == UPDATE)) { if (pG->verbose) Inform(pG, 0, IDIAG, "collecting %s %s", fspec, pG->recurse ? "recurse" : " "); r = Wild(fspec, pG); } else // Freshen or Delete - must be internal file { if (pG->verbose) Inform(pG, 0, IDIAG, "collecting %s %s", fspec, pG->recurse ? "recurse" : " "); r = procname(fspec, pG->recurse, pG); } if (r != ZEN_OK) { if ((int)(char)(r &0xFF) == ZEN_MISS) { /* this occurs if new file wasn't found */ Inform(pG, r, IERROR, "File specification \"%s\" skipped", fspec); r = 0; } } if (r) return ziperr(r, pG); } return 0; }