Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
// Enumerate the system file assoications and build an image list.
BuildImageList();
// Load our initial MRU into our menu.
InitializeMRU();
// Restore/remove our cursor.
SetCursor(hCur);
// Clear our initialization window handle.
g_hWndWaitFor = NULL;
// Load our command line file if one was specified. Otherwise, just update
// our banner to show that no file is loaded.
if (szZipFile) {
ReadZipFileList(szZipFile);
} else {
DrawBanner(NULL);
}
// Enable some controls.
EnableAllMenuItems(IDM_FILE_OPEN, TRUE);
EnableAllMenuItems(IDM_FILE_CLOSE, TRUE);
EnableAllMenuItems(IDM_VIEW_EXPANDED_VIEW, TRUE);
EnableAllMenuItems(IDM_HELP_ABOUT, TRUE);
// Set our temporary directory.
#ifdef _WIN32_WCE
g_szTempDir = TEXT("\\Temporary Pocket UnZip Files");
#else
g_szTempDir = TEXT("C:\\Temporary Pocket UnZip Files");
// Set the drive to be the same drive as the OS installation is on.
if (GetWindowsDirectory(g_szTempDirPath, countof(g_szTempDirPath))) {
lstrcpy(g_szTempDirPath + 3, TEXT("Temporary Pocket UnZip Files"));
g_szTempDir = g_szTempDirPath;
}
#endif
}
//******************************************************************************
void ShutdownApplication() {
// Free our banner font.
if (g_hFontBanner) {
DeleteObject(g_hFontBanner);
g_hFontBanner = NULL;
}
// Delete our FILE_TYPE_NODE linked list.
for (FILE_TYPE_NODE *pft = g_pftHead; pft; ) {
FILE_TYPE_NODE *pftNext = pft->pNext;
delete[] (BYTE*)pft;
pft = pftNext;
}
g_pftHead = NULL;
// If there are no other instances of our application open, then delete our
// temporary directory and all the files in it. Any files opened for viewing
// should be locked and will fail to delete. This is to be expected.
if (g_szTempDir && (FindWindow(g_szClass, NULL) == NULL)) {
TCHAR szPath[_MAX_PATH];
_tcscpy(szPath, g_szTempDir);
DeleteDirectory(szPath);
}
}
//******************************************************************************
void RegisterUnzip() {
#ifdef _WIN32_WCE
// WARNING! Since Windows CE does not support any way to get your binary's
// name at runtime, we have to hard-code in "punzip.exe". If our binary is
// not named this or is in a non-path directory, then we will fail to
// register ourself with the system as the default application to handle
// ".zip" files.
TCHAR szPath[32] = TEXT("punzip.exe");
TCHAR szTstPath[32];
#else
// Get our module's path and file name. We use the short path name for the
// registry because it is guaranteed to contain no spaces.
TCHAR szLongPath[_MAX_PATH];
TCHAR szPath[_MAX_PATH];
TCHAR szTstPath[_MAX_PATH];
GetModuleFileName(NULL, szLongPath, countof(szLongPath));
GetShortPathName(szLongPath, szPath, countof(szPath));
#endif
// Store a pointer to the end of our path for easy appending.
LPTSTR szEnd = szPath + _tcslen(szPath);
BOOL fDoRegisterPUnZip = TRUE;
// Associate "ZIP" file extensions to our application
if (RegReadKey(HKEY_CLASSES_ROOT, TEXT(".zip"), szTstPath, sizeof(szTstPath)))
{
if (_tcscmp(szTstPath, TEXT("zipfile")) != 0)
fDoRegisterPUnZip = FALSE;
else if (RegReadKey(HKEY_CLASSES_ROOT, TEXT("zipfile\\shell\\Open\\command"),
szTstPath, sizeof(szTstPath)) &&
(_tcsncmp(szTstPath, szPath, _tcslen(szPath)) != 0))
fDoRegisterPUnZip = FALSE;
if (!fDoRegisterPUnZip)
{
fDoRegisterPUnZip =
(IDOK == MessageBox(g_hWndMain,
TEXT("Currently, Pocket UnZip is not registered as default ")
TEXT("handler for Zip archives.\n\n")
TEXT("Please, confirm that Pocket UnZip should now register itself ")
TEXT("as default application for handling Zip archives (.zip files)"),
g_szAppName,
MB_ICONQUESTION | MB_OKCANCEL));
}
}
if (fDoRegisterPUnZip) {
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
// Re-calcualte our column widths.
ResizeColumns();
}
//******************************************************************************
void ResizeColumns() {
// Hide the window since we are going to be doing some column shifting.
ShowWindow(g_hWndList, SW_HIDE);
// Resize all the columns to best fit both the column data and the header.
for (int column = 0; column < countof(g_columns); column++) {
ListView_SetColumnWidth(g_hWndList, column, LVSCW_AUTOSIZE_USEHEADER);
}
// Show the window again.
ShowWindow(g_hWndList, SW_SHOW);
}
//******************************************************************************
LPCTSTR GetZipErrorString(int error) {
switch (error) {
case PK_OK: // no error
return TEXT("Operation completed successfully.");
case PK_WARN: // warning error
return TEXT("There were warnings during the operation.");
case PK_ERR: // error in zipfile
case PK_BADERR: // severe error in zipfile
return TEXT("The operation could not be successfully completed. ")
TEXT("Possible causes are that the ZIP file contains errors, ")
TEXT("or that an error occurred while trying to create a ")
TEXT("directory or file.");
case PK_MEM: // insufficient memory
case PK_MEM2: // insufficient memory
case PK_MEM3: // insufficient memory
case PK_MEM4: // insufficient memory
case PK_MEM5: // insufficient memory
return TEXT("There is not enough memory to perform the operation. ")
TEXT("Try closing other running applications or adjust your ")
TEXT("memory configuration.");
case PK_NOZIP: // zipfile not found or corrupt.
return TEXT("The ZIP file either contains errors or could not be found.");
case PK_PARAM: // bad or illegal parameters specified
break; // Not used in the Windows CE port.
case PK_FIND: // no files found in ZIP file
return TEXT("The ZIP file contains errors that prevented the ")
TEXT("operation from completing successfully. A possible ")
TEXT("cause is that one or more of the files listed as being ")
TEXT("in the ZIP file could not actually be found within the ")
TEXT("ZIP file itself.");
case PK_DISK: // disk full or file locked
return TEXT("An error occurred while attempting to save a file. ")
TEXT("Possible causes are that your file storage is full or ")
TEXT("read only, or that a file with the same name already ")
TEXT("exists and is locked by another application.");
case PK_EOF: // unexpected end of file
return TEXT("The ZIP file contains errors that prevented the ")
TEXT("operation from completing successfully. A possible ")
TEXT("cause is that your ZIP file is incomplete and might be ")
TEXT("truncated.");
case IZ_UNSUP: // no files found: all unsup. compr/encrypt.
return TEXT("None of the files could be processed because they were ")
TEXT("all compressed using an unsupported compression or ")
TEXT("encryption algorithm.");
case IZ_BADPWD: // no files found: all had bad password.
return TEXT("None of the files could be processed because all the ")
TEXT("password(s) specified were incorrect.");
case PK_EXCEPTION: // exception occurred
return TEXT("An internal error occurred. Possible causes are that ")
TEXT("you are out of memory, you are out of file storage ")
TEXT("space, the ZIP file contains unexpected errors, or there ")
TEXT("is a bug in our program (that's why it's free).");
case IZ_CTRLC: // canceled by user's interaction
case PK_ABORTED: // user aborted
return TEXT("The operation was aborted.");
}
return TEXT("An unknown error occurred while processing the ZIP file.");
}
//******************************************************************************
void AddFileToListView(FILE_NODE *pFile) {
// Set up our List View Item structure.
LV_ITEM lvi;
ZeroMemory(&lvi, sizeof(lvi));
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
lvi.pszText = LPSTR_TEXTCALLBACK;
lvi.lParam = (LPARAM)pFile;
lvi.iImage = IMAGE_GENERIC;
// Special case Volume Labels.
if (pFile->dwAttributes & ZFILE_ATTRIBUTE_VOLUME) {
pFile->szType = "Volume Label";
lvi.iImage = IMAGE_VOLUME;
// Special case folders.
} else if (pFile->dwAttributes & FILE_ATTRIBUTE_DIRECTORY) {
pFile->szType = "Folder";
lvi.iImage = IMAGE_FOLDER;
// Do a lookup on the file extension.
} else {
// Locate the file portion of our path.
LPCSTR pszFile = GetFileFromPath(pFile->szPathAndMethod);
// Find the extension portion of our file.
LPCSTR pszExt = MBSRCHR(pszFile, '.');
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
return;
}
// Compute our total progress bar position.
dwTotal = (DWORD)(((DWORDLONG)PROGRESS_MAX *
(DWORDLONG)(pei->uzBytesWrittenPreviousFiles +
pei->uzBytesWrittenThisFile +
pei->dwFile)) /
(DWORDLONG)(pei->uzByteCount +
pei->dwFileCount));
dwPercentage = dwTotal / (PROGRESS_MAX / 100);
// Set our total progress indicators.
SendMessage(pei->hWndProgTotal, PBM_SETPOS, dwTotal, 0);
// Set our total percentage text.
_stprintf(szBuffer, TEXT("%u%%"), dwPercentage);
SetWindowText(pei->hWndPercentage, szBuffer);
// Set our current file and byte process counts.
FormatValue(szBuffer, pei->dwFile - 1);
SetWindowText(pei->hWndFilesProcessed, szBuffer);
FormatValue(szBuffer, pei->uzBytesWrittenPreviousFiles +
pei->uzBytesWrittenThisFile);
SetWindowText(pei->hWndBytesProcessed, szBuffer);
if (fFull) {
// Build our message string.
_tcscpy(szBuffer, pei->fExtract ? TEXT("Extract") : TEXT("Test"));
size_t preflen = _tcslen(szBuffer);
MBSTOTSTR(szBuffer+preflen, pei->szFile,countof(szBuffer)-preflen);
// Change all forward slashes to back slashes in the buffer.
ForwardSlashesToBackSlashes(szBuffer);
// Update the file name in our dialog.
SetWindowText(pei->hWndEditFile, szBuffer);
}
}
//******************************************************************************
//***** Replace File Dialog Functions
//******************************************************************************
int PromptToReplace(LPCSTR szPath) {
// Check to see if we are extracting for view only.
if (g_fViewing) {
// Build prompt.
TCHAR szMessage[_MAX_PATH + 128];
_stprintf(szMessage,
#ifdef UNICODE
TEXT("A file named \"%S\" has already been extracted for viewing. ")
#else
TEXT("A file named \"%s\" has already been extracted for viewing. ")
#endif
TEXT("That file might be opened and locked for viewing by another application.\n\n")
TEXT("Would you like to attempt to overwrite it with the new file?"),
GetFileFromPath(szPath));
// Display prompt.
if (IDYES == MessageBox(g_hDlgProgress, szMessage, g_szAppName,
MB_ICONWARNING | MB_YESNO))
{
// Tell Info-ZIP to continue with extraction.
return IDM_REPLACE_YES;
}
// Remember that the file was skipped and tell Info-ZIP to abort extraction.
g_fSkipped = TRUE;
return IDM_REPLACE_NO;
}
// Otherwise, do the normal replace prompt dialog.
return DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_REPLACE), g_hWndMain,
(DLGPROC)DlgProcReplace, (LPARAM)szPath);
}
//******************************************************************************
BOOL CALLBACK DlgProcReplace(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
TCHAR szMessage[_MAX_PATH + 32];
switch (uMsg) {
case WM_INITDIALOG:
// Play the question tone to alert the user.
MessageBeep(MB_ICONQUESTION);
// Display a message with the file name.
#ifdef UNICODE
_stprintf(szMessage, TEXT("\"%S\" already exists."), (LPCSTR)lParam);
#else
_stprintf(szMessage, TEXT("\"%s\" already exists."), (LPCSTR)lParam);
#endif
// Change all forward slashes to back slashes in the buffer.
ForwardSlashesToBackSlashes(szMessage);
// Display the file string.
SetDlgItemText(hDlg, IDC_FILE, szMessage);
// Center our dialog over our parent.
CenterWindow(hDlg);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDCANCEL:
case IDOK:
EndDialog(hDlg, IDM_REPLACE_NO);
break;
case IDM_REPLACE_ALL:
case IDM_REPLACE_NONE:
case IDM_REPLACE_YES:
( run in 0.434 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )