in src/wffile.c [687:1011]
BOOL WFCheckCompress(
HWND hDlg,
LPTSTR szNameSpec,
DWORD dwNewAttrs,
BOOL bPropertyDlg,
BOOL *bIgnoreAll)
{
DWORD dwFlags, dwAttribs;
TCHAR szTitle[MAXTITLELEN];
TCHAR szTemp[MAXMESSAGELEN];
TCHAR szFilespec[MAXPATHLEN];
BOOL bCompressionAttrChange;
BOOL bIsDir;
BOOL bRet = TRUE;
HCURSOR hCursor;
//
// Make sure we're not in the middle of another compression operation.
// If so, put up an error box warning the user that they need to wait
// to do another compression operation.
//
if (bCompressReEntry)
{
LoadString(hAppInstance, IDS_WINFILE, szTitle, COUNTOF(szTitle));
LoadString(hAppInstance, IDS_MULTICOMPRESSERR, szMessage, COUNTOF(szMessage));
MessageBox(hDlg, szMessage, szTitle, MB_OK | MB_ICONEXCLAMATION);
return (TRUE);
}
bCompressReEntry = TRUE;
//
// Make sure the volume supports File Compression.
//
GetRootPath (szNameSpec, szTemp);
if (GetVolumeInformation (szTemp, NULL, 0L, NULL, NULL, &dwFlags, NULL, 0L)
&& (!(dwFlags & FS_FILE_COMPRESSION)) )
{
//
// The volume does not support file compression, so just
// quit out. Do not return FALSE, since that will not
// allow any other attributes to be changed.
//
bCompressReEntry = FALSE;
return (TRUE);
}
//
// Show the hour glass cursor.
//
if (hCursor = LoadCursor(NULL, IDC_WAIT))
{
hCursor = SetCursor(hCursor);
}
ShowCursor(TRUE);
//
// Get the file attributes.
//
dwAttribs = GetFileAttributes(szNameSpec);
//
// Determine if ATTR_COMPRESSED is changing state.
//
bCompressionAttrChange = !( (dwAttribs & ATTR_COMPRESSED) ==
(dwNewAttrs & ATTR_COMPRESSED) );
//
// Initialize progress global.
//
bShowProgress = FALSE;
//
// Initialize ignore all errors global.
//
bIgnoreAllErrors = *bIgnoreAll;
//
// If the Compression attribute changed or if we're dealing with
// a directory, perform action.
//
bIsDir = IsDirectory(szNameSpec);
if (bCompressionAttrChange || (bIsDir && !bPropertyDlg))
{
//
// Reset globals before progress display.
//
TotalDirectoryCount = 0;
TotalFileCount = 0;
TotalCompressedFileCount = 0;
TotalUncompressedFileCount = 0;
LARGE_INTEGER_NULL(TotalFileSize);
LARGE_INTEGER_NULL(TotalCompressedSize);
szGlobalFile[0] = '\0';
szGlobalDir[0] = '\0';
//
// See if the compressed attribute is set.
//
if (dwNewAttrs & ATTR_COMPRESSED)
{
if (bIsDir)
{
LoadString(hAppInstance, IDS_WINFILE, szTitle, COUNTOF(szTitle));
LoadString(hAppInstance, IDS_COMPRESSDIR, szMessage, COUNTOF(szMessage));
//
// Ask the user if we should compress all files and
// subdirs in this directory.
//
wsprintf(szTemp, szMessage, szNameSpec);
switch (MessageBox(hDlg, szTemp, szTitle,
MB_YESNOCANCEL | MB_ICONEXCLAMATION | MB_TASKMODAL))
{
case ( IDYES ) :
{
lstrcpy(szFilespec, SZ_STAR);
DoSubdirectories = TRUE;
bShowProgress = TRUE;
break;
}
case ( IDCANCEL ) :
{
goto CancelCompress;
}
case ( IDNO ) :
default :
{
szFilespec[0] = TEXT('\0');
DoSubdirectories = FALSE;
break;
}
}
if (bShowProgress)
{
hDlgProgress = CreateDialog(
hAppInstance,
MAKEINTRESOURCE(COMPRESSPROGDLG),
hwndFrame,
CompressProgDlg);
ShowWindow(hDlgProgress, SW_SHOW);
}
AddBackslash(szNameSpec);
lstrcpy(szTemp, szNameSpec);
bRet = WFDoCompress(hDlg, szNameSpec, szFilespec);
//
// Set attribute on Directory if last call was successful.
//
if (bRet)
{
szFilespec[0] = TEXT('\0');
DoSubdirectories = FALSE;
lstrcpy(szNameSpec, szTemp);
bRet = WFDoCompress(hDlg, szNameSpec, szFilespec);
}
if (bShowProgress && hDlgProgress)
{
if (hDCdir)
{
ReleaseDC( GetDlgItem(hDlgProgress, IDD_COMPRESS_DIR),
hDCdir );
hDCdir = NULL;
}
DestroyWindow(hDlgProgress);
hDlgProgress = NULL;
}
}
else
{
//
// Compress single file.
//
DoSubdirectories = FALSE;
lstrcpy(szFilespec, szNameSpec);
StripPath(szFilespec);
StripFilespec(szNameSpec);
AddBackslash(szNameSpec);
bRet = WFDoCompress(hDlg, szNameSpec, szFilespec);
}
}
else
{
if (bIsDir)
{
LoadString(hAppInstance, IDS_WINFILE, szTitle, COUNTOF(szTitle));
LoadString(hAppInstance, IDS_UNCOMPRESSDIR, szMessage, COUNTOF(szMessage));
//
// Ask the user if we should uncompress all files and
// subdirs in this directory.
//
wsprintf(szTemp, szMessage, szNameSpec);
switch (MessageBox(hDlg, szTemp, szTitle,
MB_YESNOCANCEL | MB_ICONEXCLAMATION | MB_TASKMODAL))
{
case ( IDYES ) :
{
lstrcpy(szFilespec, SZ_STAR);
DoSubdirectories = TRUE;
bShowProgress = TRUE;
break;
}
case ( IDCANCEL ) :
{
goto CancelCompress;
}
case ( IDNO ) :
default :
{
szFilespec[0] = TEXT('\0');
DoSubdirectories = FALSE;
break;
}
}
if (bShowProgress)
{
hDlgProgress = CreateDialog(
hAppInstance,
MAKEINTRESOURCE(UNCOMPRESSPROGDLG),
hwndFrame,
UncompressProgDlg);
ShowWindow(hDlgProgress, SW_SHOW);
}
AddBackslash(szNameSpec);
lstrcpy(szTemp, szNameSpec);
bRet = WFDoUncompress(hDlg, szNameSpec, szFilespec);
//
// Set attribute on Directory if last call was successful.
//
if (bRet)
{
szFilespec[0] = TEXT('\0');
DoSubdirectories = FALSE;
lstrcpy(szNameSpec, szTemp);
bRet = WFDoUncompress(hDlg, szNameSpec, szFilespec);
}
if (bShowProgress && hDlgProgress)
{
if (hDCdir)
{
ReleaseDC( GetDlgItem(hDlgProgress, IDD_UNCOMPRESS_DIR),
hDCdir );
hDCdir = NULL;
}
DestroyWindow(hDlgProgress);
hDlgProgress = NULL;
}
}
else
{
//
// Uncompress single file.
//
DoSubdirectories = FALSE;
lstrcpy(szFilespec, szNameSpec);
StripPath(szFilespec);
StripFilespec(szNameSpec);
AddBackslash(szNameSpec);
bRet = WFDoUncompress(hDlg, szNameSpec, szFilespec);
}
}
if (bIsDir)
{
//
// Need to redraw all of the tree list box windows
// so that they can be updated to show whether or not
// the directories are compressed.
//
RedrawAllTreeWindows();
}
}
CancelCompress:
//
// Reset the cursor.
//
if (hCursor)
{
SetCursor(hCursor);
}
ShowCursor(FALSE);
//
// Reset the globals.
//
*bIgnoreAll = bIgnoreAllErrors;
bCompressReEntry = FALSE;
//
// Return the appropriate value.
//
return (bRet);
}