?? unzip.c
字號:
hh = mo; mo = dy; dy = hh;
}
hh = (crec.last_mod_file_time >> 11) & 0x1f;
mm = (crec.last_mod_file_time >> 5) & 0x3f;
csize = (longint) crec.compressed_size;
ucsize = (longint) crec.uncompressed_size;
if (crec.general_purpose_bit_flag & 1)
csize -= 12; /* if encrypted, don't count encrypt hdr */
ratio = (ucsize == 0) ? 0 : /* .zip can have 0-length members */
((ucsize > 2000000L) ? /* risk signed overflow if mult. */
(int) ((ucsize-csize) / (ucsize/1000L)) + 5 : /* big */
(int) ((1000L*(ucsize-csize)) / ucsize) + 5); /* small */
#if 0 /* GRR/Euro: add this? define p above */
#if (defined(DOS_OS2) || (defined(UNIX) && !defined(VMS)))
for (p = filename; *p; ++p)
if (!isprint(*p))
*p = '?'; /* change non-printable chars to '?' */
#endif /* DOS_OS2 || UNIX */
#endif /* 0 */
#ifdef MSWIN
{
DWORD dwAddStringOutcome = 0L; /* outcome from adding string: index or error code */
static char __based(__segname("STRINGS_TEXT")) szNoLBSpace[] =
"This archive contains too many files for WizUnZip to list them all!";
static char __based(__segname("STRINGS_TEXT")) szLBError[] =
"A Windows error occurred while filling the listbox!";
#ifdef NEED_EARLY_REDRAW
/* turn on listbox redrawing just before adding last line */
if (j == (ecrec.total_entries_central_dir-1))
(void)SendMessage(hWndList, WM_SETREDRAW, TRUE, 0L);
#endif /* NEED_EARLY_REDRAW */
psLBEntry =
(PSTR)LocalAlloc(LMEM_FIXED, FILNAMSIZ+LONG_FORM_FNAME_INX);
switch (which_hdr) {
case 0: /* short form */
OemToAnsi(filename, filename); /* translate to ANSI */
wsprintf(psLBEntry, "%7ld %02u-%02u-%02u %02u:%02u %c%s",
(long)ucsize, mo, dy, yr, hh, mm, (pInfo->lcflag?'^':' '),
(LPSTR)filename);
dwAddStringOutcome = SendMessage(hWndList, LB_ADDSTRING, 0,
(LONG)(LPSTR)psLBEntry);
break;
case 1: /* verbose */
OemToAnsi(filename, filename); /* translate to ANSI */
wsprintf(psLBEntry,
"%7ld %-7s%7ld %3d%% %02u-%02u-%02u %02u:%02u %08lx %c%s",
(long)ucsize, (LPSTR)method[methnum], (long)csize,
ratio/10, mo, dy, yr, hh, mm, (unsigned long)crec.crc32,
(pInfo->lcflag?'^':' '), (LPSTR)filename);
dwAddStringOutcome = SendMessage(hWndList, LB_ADDSTRING, 0,
(LONG)(LPSTR)psLBEntry);
}
LocalFree((HANDLE)psLBEntry);
if (dwAddStringOutcome == LB_ERR)
{
MessageBox(hWndMain, szLBError, NULL, MB_OK | MB_ICONEXCLAMATION);
return 4; /* probably memory problem. Ignored in WizUnZip */
}
else if (dwAddStringOutcome == LB_ERRSPACE)
{
MessageBox(hWndMain, szNoLBSpace, NULL, MB_OK | MB_ICONEXCLAMATION);
return 4; /* Hit WIN 64K limit. Ignored in WizUnZip version */
}
}
#else /* !MSWIN */
switch (which_hdr) {
case 0: /* short form */
printf("%7ld %02u-%02u-%02u %02u:%02u %c%s\n",
ucsize, mo, dy, yr, hh, mm, (pInfo->lcflag?'^':' '),
filename);
break;
case 1: /* verbose */
printf(
"%7ld %-7s%7ld %3d%% %02u-%02u-%02u %02u:%02u %08lx %c%s\n",
ucsize, method[methnum], csize, ratio/10, mo, dy, yr,
hh, mm, crec.crc32, (pInfo->lcflag?'^':' '), filename);
}
#endif /* ?MSWIN */
error = do_string(crec.file_comment_length, (QCOND? DISPLAY:SKIP));
if (error) {
error_in_archive = error; /* might be just warning */
if (error > 1) /* fatal */
return error;
}
tot_ucsize += (ULONG) ucsize;
tot_csize += (ULONG) csize;
++members;
#ifdef OS2
if ((ea_size = SizeOfEAs(extra_field)) != 0) {
tot_easize += ea_size;
tot_eafiles++;
}
#endif
} else { /* not listing this file */
SKIP_(crec.file_comment_length)
}
} /* end for-loop (j: files in central directory) */
/*---------------------------------------------------------------------------
Print footer line and totals (compressed size, uncompressed size, number
of members in zipfile).
---------------------------------------------------------------------------*/
ratio = (tot_ucsize == 0) ?
0 : ((tot_ucsize > 4000000L) ? /* risk unsigned overflow if mult. */
(int) ((tot_ucsize - tot_csize) / (tot_ucsize/1000L)) + 5 :
(int) ((tot_ucsize - tot_csize) * 1000L / tot_ucsize) + 5);
if (quietflg < 2) {
#ifdef MSWIN
/* Display just the totals since the dashed lines get displayed
* in UpdateListBox(). Get just enough space to display total.
*/
switch (which_hdr) {
case 0: /* short */
wsprintf(lpumb->szTotalsLine, "%7lu %-7u",
(ULONG)tot_ucsize, members);
break;
case 1: /* verbose */
wsprintf(lpumb->szTotalsLine,
"%7lu %7lu %3d%% %-7u",
(ULONG)tot_ucsize, (ULONG)tot_csize, ratio / 10, members);
break;
}
#else /* !MSWIN */
switch (which_hdr) {
case 0: /* short */
printf("%s\n%7lu %-7u\n",
" ------ -------",
tot_ucsize, members);
break;
case 1: /* verbose */
printf(
"%s\n%7lu %7lu %3d%% %-7u\n",
" ------ ------ --- -------",
tot_ucsize, tot_csize, ratio / 10, members);
}
#endif /* ?MSWIN */
#ifdef OS2
if (tot_eafiles && tot_easize)
printf("\n%ld file%s %ld bytes of EA's attached.\n", tot_eafiles,
tot_eafiles == 1 ? " has" : "s have a total of", tot_easize);
#endif
}
/*---------------------------------------------------------------------------
Double check that we're back at the end-of-central-directory record.
---------------------------------------------------------------------------*/
readbuf(sig, 4);
if (strncmp(sig, end_central_sig, 4)) { /* just to make sure again */
fprintf(stderr, EndSigMsg); /* didn't find end-of-central-dir sig */
/* fprintf(stderr, ReportMsg); */
error_in_archive = 1; /* 1: warning error */
}
return error_in_archive;
} /* end function list_files() */
/**************************************/
/* Function process_cdir_file_hdr() */
/**************************************/
int process_cdir_file_hdr() /* return PK-type error code */
{
cdir_byte_hdr byterec;
/*---------------------------------------------------------------------------
Read the next central directory entry and do any necessary machine-type
conversions (byte ordering, structure padding compensation--do so by
copying the data from the array into which it was read (byterec) to the
usable struct (crec)).
---------------------------------------------------------------------------*/
if (readbuf((char *) byterec, CREC_SIZE) <= 0)
return 51; /* 51: unexpected EOF */
crec.version_made_by[0] = byterec[C_VERSION_MADE_BY_0];
crec.version_made_by[1] = byterec[C_VERSION_MADE_BY_1];
crec.version_needed_to_extract[0] = byterec[C_VERSION_NEEDED_TO_EXTRACT_0];
crec.version_needed_to_extract[1] = byterec[C_VERSION_NEEDED_TO_EXTRACT_1];
crec.general_purpose_bit_flag =
makeword(&byterec[C_GENERAL_PURPOSE_BIT_FLAG]);
crec.compression_method =
makeword(&byterec[C_COMPRESSION_METHOD]);
crec.last_mod_file_time =
makeword(&byterec[C_LAST_MOD_FILE_TIME]);
crec.last_mod_file_date =
makeword(&byterec[C_LAST_MOD_FILE_DATE]);
crec.crc32 =
makelong(&byterec[C_CRC32]);
crec.compressed_size =
makelong(&byterec[C_COMPRESSED_SIZE]);
crec.uncompressed_size =
makelong(&byterec[C_UNCOMPRESSED_SIZE]);
crec.filename_length =
makeword(&byterec[C_FILENAME_LENGTH]);
crec.extra_field_length =
makeword(&byterec[C_EXTRA_FIELD_LENGTH]);
crec.file_comment_length =
makeword(&byterec[C_FILE_COMMENT_LENGTH]);
crec.disk_number_start =
makeword(&byterec[C_DISK_NUMBER_START]);
crec.internal_file_attributes =
makeword(&byterec[C_INTERNAL_FILE_ATTRIBUTES]);
crec.external_file_attributes =
makelong(&byterec[C_EXTERNAL_FILE_ATTRIBUTES]); /* LONG, not word! */
crec.relative_offset_local_header =
makelong(&byterec[C_RELATIVE_OFFSET_LOCAL_HEADER]);
pInfo->hostnum = MIN(crec.version_made_by[1], NUM_HOSTS);
/* extnum = MIN(crec.version_needed_to_extract[1], NUM_HOSTS); */
methnum = MIN(crec.compression_method, NUM_METHODS);
if (methnum == NUM_METHODS)
sprintf(unkn, "Unk:%03d", crec.compression_method);
/*---------------------------------------------------------------------------
Set flag for lowercase conversion of filename, depending on which OS the
file is coming from. This section could be ifdef'd if some people have
come to love DOS uppercase filenames under Unix...but really, guys, get
a life. :) NOTE THAT ALL SYSTEM NAMES NOW HAVE TRAILING UNDERSCORES!!!
This is to prevent interference with compiler command-line defines such
as -DUNIX, for example, which are then used in "#ifdef UNIX" constructs.
---------------------------------------------------------------------------*/
pInfo->lcflag = 0;
if (!U_flag) /* as long as user hasn't specified case-preservation */
switch (pInfo->hostnum) {
case DOS_OS2_FAT_:
/* case VMS_: VMS Zip converts filenames to lowercase */
case VM_CMS_: /* all caps? */
case CPM_: /* like DOS, right? */
/* case ATARI_: ? */
/* case Z_SYSTEM_: ? */
/* case TOPS20_: (if we had such a thing...) */
pInfo->lcflag = 1; /* convert filename to lowercase */
break;
default: /* AMIGA_, UNIX_, (ATARI_), OS2_HPFS_, */
break; /* MAC_, (Z_SYSTEM_): no conversion */
}
return 0;
} /* end function process_cdir_file_hdr() */
/***************************************/
/* Function process_local_file_hdr() */
/***************************************/
int process_local_file_hdr() /* return PK-type error code */
{
local_byte_hdr byterec;
/*---------------------------------------------------------------------------
Read the next local file header and do any necessary machine-type con-
versions (byte ordering, structure padding compensation--do so by copy-
ing the data from the array into which it was read (byterec) to the
usable struct (lrec)).
---------------------------------------------------------------------------*/
if (readbuf((char *) byterec, LREC_SIZE) <= 0)
return 51; /* 51: unexpected EOF */
lrec.version_needed_to_extract[0] = byterec[L_VERSION_NEEDED_TO_EXTRACT_0];
lrec.version_needed_to_extract[1] = byterec[L_VERSION_NEEDED_TO_EXTRACT_1];
lrec.general_purpose_bit_flag = makeword(&byterec[L_GENERAL_PURPOSE_BIT_FLAG]);
lrec.compression_method = makeword(&byterec[L_COMPRESSION_METHOD]);
lrec.last_mod_file_time = makeword(&byterec[L_LAST_MOD_FILE_TIME]);
lrec.last_mod_file_date = makeword(&byterec[L_LAST_MOD_FILE_DATE]);
lrec.crc32 = makelong(&byterec[L_CRC32]);
lrec.compressed_size = makelong(&byterec[L_COMPRESSED_SIZE]);
lrec.uncompressed_size = makelong(&byterec[L_UNCOMPRESSED_SIZE]);
lrec.filename_length = makeword(&byterec[L_FILENAME_LENGTH]);
lrec.extra_field_length = makeword(&byterec[L_EXTRA_FIELD_LENGTH]);
csize = (longint) lrec.compressed_size;
ucsize = (longint) lrec.uncompressed_size;
if ((lrec.general_purpose_bit_flag & 8) != 0) {
/* Can't trust local header, use central directory: */
lrec.crc32 = pInfo->crc;
lrec.compressed_size = pInfo->compr_size;
csize = (longint) lrec.compressed_size;
}
return 0; /* 0: no error */
} /* end function process_local_file_hdr() */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -