Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
/*
Copyright (c) 1990-2003 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
//******************************************************************************
//
// File: WINMAIN.CPP
//
// Description: This module contains all the Windows specific code for Pocket
// UnZip. It contains the entire user interface. This code knows
// almost nothing about the Info-ZIP code. All Info-ZIP related
// functions are wrapped by helper functions in INTRFACE.CPP. The
// code in this module only calls those wrapper functions and
// INTRFACE.CPP handles all the details and callbacks of the
// Info-ZIP code.
//
// Copyright: All the source files for Pocket UnZip, except for components
// written by the Info-ZIP group, are copyrighted 1997 by Steve P.
// Miller. The product "Pocket UnZip" itself is property of the
// author and cannot be altered in any way without written consent
// from Steve P. Miller.
//
// Disclaimer: All project files are provided "as is" with no guarantee of
// their correctness. The authors are not liable for any outcome
// that is the result of using this source. The source for Pocket
// UnZip has been placed in the public domain to help provide an
// understanding of its implementation. You are hereby granted
// full permission to use this source in any way you wish, except
// to alter Pocket UnZip itself. For comments, suggestions, and
// bug reports, please write to stevemil@pobox.com.
//
// Functions: WinMain
// InitializeApplication
// ShutdownApplication
// RegisterUnzip
// BuildImageList
// WndProc
// OnCreate
// OnFileOpen
// OnActionView
// OnActionSelectAll
// OnViewExpandedView
// OnHelp
// OnGetDispInfo
// OnDeleteItem
// OnItemChanged
// Sort
// CompareFunc
// SetCaptionText
// DrawBanner
// AddDeleteColumns
// ResizeColumns
// GetZipErrorString
// AddFileToListView
// EnableAllMenuItems
// CheckAllMenuItems
// CenterWindow
// AddTextToEdit
// FormatValue
// BuildAttributesString
// BuildTypeString
// GetFileFromPath
// ForwardSlashesToBackSlashesA
// ForwardSlashesToBackSlashesW
// DeleteDirectory(LPTSTR szPath);
// RegWriteKey
// RegReadKey
// WriteOptionString
// WriteOptionInt
// GetOptionString
// GetOptionInt
// DisableEditing
// EditSubclassProc
// GetMenuString
// InitializeMRU
// AddFileToMRU
// RemoveFileFromMRU
// ActivateMRU
// ReadZipFileList
// DlgProcProperties
// MergeValues
// CheckThreeStateBox
// ExtractOrTestFiles
// DlgProcExtractOrTest
// FolderBrowser
// DlgProcBrowser
// SubclassSaveAsDlg
// DlgProcExtractProgress
// DlgProcViewProgress
// UpdateProgress
// PromptToReplace
// DlgProcReplace
// DlgProcPassword
// DlgProcViewAssociation
// DlgProcComment
// DlgProcAbout
//
//
// Date Name History
// -------- ------------ -----------------------------------------------------
// 02/01/97 Steve Miller Created (Version 1.0 using Info-ZIP UnZip 5.30)
//
//******************************************************************************
extern "C" {
#define __WINMAIN_CPP__
#define UNZIP_INTERNAL
#include "unzip.h"
#include "crypt.h" // Needed to pick up CRYPT define setting and return values.
#include "unzvers.h" // Only needed by consts.h (VERSION_DATE & VersionDate)
#include "consts.h" // Only include once - defines constant string messages.
#include <commctrl.h> // Common controls - mainly ListView and ImageList
#include <commdlg.h> // Common dialogs - OpenFile dialog
#ifndef _WIN32_WCE
#include <shlobj.h> // On NT, we use the SHBrowseForFolder() stuff.
#include <shellapi.h> // CommandLineToArgvW() and ExtractIconEx()
#endif
#include "intrface.h" // Interface between Info-ZIP and us
#include "winmain.h" // Us
}
#include <tchar.h> // Must be outside of extern "C" block
//******************************************************************************
//***** "Local" Global Variables
//******************************************************************************
static LPCTSTR g_szAppName = TEXT("Pocket UnZip");
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
static FILE_TYPE_NODE *g_pftHead = NULL;
#ifdef _WIN32_WCE
static LPCTSTR g_szHelpFile = TEXT("\\windows\\punzip.htp");
#else
static TCHAR g_szTempDirPath[_MAX_PATH];
static LPCTSTR g_szHelpFile = TEXT("punzip.html");
#endif
static COLUMN g_columns[] = {
{ TEXT("Name"), LVCFMT_LEFT },
{ TEXT("Size"), LVCFMT_RIGHT },
{ TEXT("Type"), LVCFMT_LEFT },
{ TEXT("Modified"), LVCFMT_LEFT },
{ TEXT("Attributes"), LVCFMT_LEFT },
{ TEXT("Compressed"), LVCFMT_RIGHT },
{ TEXT("Ratio"), LVCFMT_RIGHT },
{ TEXT("Method"), LVCFMT_LEFT },
{ TEXT("CRC"), LVCFMT_LEFT },
{ TEXT("Comment"), LVCFMT_LEFT }
};
//******************************************************************************
//***** Local Function Prototypes
//******************************************************************************
// Startup and Shutdown Functions
void InitializeApplication(LPCTSTR szZipFile);
void ShutdownApplication();
void RegisterUnzip();
void BuildImageList();
// Our Main Window's Message Handler
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// Event Handlers for our Main Window
int OnCreate();
void OnFileOpen();
void OnActionView();
void OnActionSelectAll();
void OnViewExpandedView();
void OnHelp();
// Event Handlers for our List View
void OnGetDispInfo(LV_DISPINFO *plvdi);
void OnDeleteItem(NM_LISTVIEW *pnmlv);
void OnItemChanged(NM_LISTVIEW *pnmlv);
// List View Sort Functions
void Sort(int sortColumn, BOOL fForce);
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM sortColumn);
// Helper/Utility Functions
void SetCaptionText(LPCTSTR szPrefix);
void DrawBanner(HDC hdc);
void AddDeleteColumns();
void ResizeColumns();
LPCTSTR GetZipErrorString(int error);
void AddFileToListView(FILE_NODE *pFile);
void EnableAllMenuItems(UINT uMenuItem, BOOL fEnabled);
void CheckAllMenuItems(UINT uMenuItem, BOOL fChecked);
void CenterWindow(HWND hWnd);
void AddTextToEdit(LPCSTR szText);
LPTSTR FormatValue(LPTSTR szValue, zusz_t uzValue);
LPTSTR BuildAttributesString(LPTSTR szBuffer, DWORD dwAttributes);
LPCSTR BuildTypeString(FILE_NODE *pFile, LPSTR szType);
LPCSTR GetFileFromPath(LPCSTR szPath);
void ForwardSlashesToBackSlashesA(LPSTR szBuffer);
#ifdef UNICODE
void ForwardSlashesToBackSlashesW(LPWSTR szBuffer);
# define ForwardSlashesToBackSlashes ForwardSlashesToBackSlashesW
#else
# define ForwardSlashesToBackSlashes ForwardSlashesToBackSlashesA
#endif
void DeleteDirectory(LPTSTR szPath);
// Registry Functions
void RegWriteKey(HKEY hKeyRoot, LPCTSTR szSubKey, LPCTSTR szValue);
BOOL RegReadKey(HKEY hKeyRoot, LPCTSTR szSubKey, LPTSTR szValue, DWORD cBytes);
void WriteOptionString(LPCTSTR szOption, LPCTSTR szValue);
void WriteOptionInt(LPCTSTR szOption, DWORD dwValue);
LPTSTR GetOptionString(LPCTSTR szOption, LPCTSTR szDefault, LPTSTR szValue, DWORD nSize);
DWORD GetOptionInt(LPCTSTR szOption, DWORD dwDefault);
// EDIT Control Subclass Functions
void DisableEditing(HWND hWndEdit);
LRESULT CALLBACK EditSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// MRU Functions
void InitializeMRU();
void AddFileToMRU(LPCSTR szFile);
void RemoveFileFromMRU(LPCTSTR szFile);
void ActivateMRU(UINT uIDItem);
// Open Zip File Functions
void ReadZipFileList(LPCTSTR wszPath);
// Zip File Properties Dialog Functions
BOOL CALLBACK DlgProcProperties(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
void MergeValues(int *p1, int p2);
void CheckThreeStateBox(HWND hDlg, int nIDButton, int state);
// Extract/Test Dialog Functions
void ExtractOrTestFiles(BOOL fExtract);
BOOL CALLBACK DlgProcExtractOrTest(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
// Folder Browsing Dialog Functions
BOOL FolderBrowser(LPTSTR szPath, DWORD dwLength);
BOOL CALLBACK DlgProcBrowser(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
void SubclassSaveAsDlg();
// Extraction/Test/View Progress Dialog Functions
BOOL CALLBACK DlgProcExtractProgress(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK DlgProcViewProgress(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
void UpdateProgress(EXTRACT_INFO *pei, BOOL fFull);
// Replace File Dialog Functions
int PromptToReplace(LPCSTR szPath);
BOOL CALLBACK DlgProcReplace(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
// Password Dialog Functions
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
// Entrypoint is a tiny bit different on Windows CE - UNICODE command line.
#ifdef _WIN32_WCE
extern "C" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
#else
extern "C" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
#endif
{
// Wrap the whole ball of wax in a big exception handler.
__try {
// Store global instance handle.
g_hInst = hInstance;
// Create our banner font. We need to do this before creating our window.
// This font handle will be deleted in ShutdownApplication().
LOGFONT lf;
ZeroMemory(&lf, sizeof(lf));
lf.lfHeight = 16;
lf.lfWeight = FW_BOLD;
lf.lfCharSet = ANSI_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
_tcscpy(lf.lfFaceName, TEXT("MS Sans Serif"));
g_hFontBanner = CreateFontIndirect(&lf);
// Define the window class for our application's main window.
WNDCLASS wc;
ZeroMemory(&wc, sizeof(wc));
wc.lpszClassName = g_szClass;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
TCHAR *szZipPath = NULL;
#ifdef _WIN32_WCE
// Get our main window's small icon. On Windows CE, we need to send ourself
// a WM_SETICON in order for our task bar to update itself.
g_hIconMain = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_UNZIP),
IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
wc.hIcon = g_hIconMain;
// On Windows CE, we only need the WS_VISIBLE flag.
DWORD dwStyle = WS_VISIBLE;
// Get and store command line file (if any).
if (lpCmdLine && *lpCmdLine) {
szZipPath = lpCmdLine;
}
#else
// On NT we add a cursor, icon, and menu to our application's window class.
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_UNZIP));
wc.lpszMenuName = MAKEINTRESOURCE(IDR_UNZIP);
// On Windows NT, we use the standard overlapped window style.
DWORD dwStyle = WS_OVERLAPPEDWINDOW;
TCHAR szBuffer[_MAX_PATH];
// Get and store command line file (if any).
if (lpCmdLine && *lpCmdLine) {
MBSTOTSTR(szBuffer, lpCmdLine, countof(szBuffer));
szZipPath = szBuffer;
}
#endif
// Register our window class with the OS.
if (!RegisterClass(&wc)) {
DebugOut(TEXT("RegisterClass() failed [%u]"), GetLastError());
}
// Create our main window using our registered window class.
g_hWndMain = CreateWindow(wc.lpszClassName, g_szAppName, dwStyle,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
// Quit now if we failed to create our main window.
if (!g_hWndMain) {
DebugOut(TEXT("CreateWindow() failed [%u]"), GetLastError());
ShutdownApplication();
return 0;
}
// Make sure our window is visible. Really only needed for NT.
ShowWindow(g_hWndMain, nCmdShow);
// Load our keyboard accelerator shortcuts.
MSG msg;
HACCEL hAccel = LoadAccelerators(g_hInst, MAKEINTRESOURCE(IDR_UNZIP));
DWORD dwPaintFlags = 0;
// The message pump. Loop until we get a WM_QUIT message.
while (GetMessage(&msg, NULL, 0, 0)) {
// Check to see if this is an accelerator and handle it if neccessary.
if (!TranslateAccelerator(g_hWndMain, hAccel, &msg)) {
// If a normal message, then dispatch it to the correct window.
TranslateMessage(&msg);
DispatchMessage(&msg);
// Wait until our application is up and visible before trying to
// initialize some of our structures and load any command line file.
if ((msg.message == WM_PAINT) && (dwPaintFlags != 0x11)) {
if (msg.hwnd == g_hWndWaitFor) {
dwPaintFlags |= 0x01;
} else if (msg.hwnd == g_hWndList) {
dwPaintFlags |= 0x10;
}
if (dwPaintFlags == 0x11) {
InitializeApplication((szZipPath && *szZipPath) ?
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
ShutdownApplication();
// Nice clean finish - were out of here.
return msg.wParam;
} __except(EXCEPTION_EXECUTE_HANDLER) {
// Something very bad happened. Try our best to appear somewhat graceful.
MessageBox(NULL,
TEXT("An internal error occurred. Possible causes are that you are ")
TEXT("out of memory, a ZIP file (if one is loaded) contains an ")
TEXT("unexpected error, or there is a bug in our program (that's why ")
TEXT("it's free). Pocket UnZip cannot continue. It will exit now, ")
TEXT("but you may restart it and try again.\n\n")
TEXT("If the problem persists, please write to stevemil@pobox.com with ")
TEXT("any information that might help track down the problem."),
g_szAppName, MB_ICONERROR | MB_OK);
}
return 1;
}
//******************************************************************************
//***** Startup and Shutdown Functions
//******************************************************************************
void InitializeApplication(LPCTSTR szZipFile) {
// This function is called after our class is registered and all our windows
// are created and visible to the user.
// Show hour glass cursor.
HCURSOR hCur = SetCursor(LoadCursor(NULL, IDC_WAIT));
// Register UnZip in the registry to handle ".ZIP" files.
RegisterUnzip();
// 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];
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
return 0;
case IDM_ACTION_SELECT_ALL:
OnActionSelectAll();
return 0;
case IDM_VIEW_EXPANDED_VIEW:
OnViewExpandedView();
return 0;
case IDM_VIEW_COMMENT:
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_COMMENT), hWnd, (DLGPROC)DlgProcComment);
return 0;
case IDM_HELP_ABOUT:
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, (DLGPROC)DlgProcAbout);
return 0;
case IDHELP:
return SendMessage(hWnd, WM_HELP, 0, 0);
default:
// Check to see if a MRU file was selected.
if ((LOWORD(wParam) >= MRU_START_ID) &&
(LOWORD(wParam) < (MRU_START_ID + MRU_MAX_FILE)))
{
ActivateMRU(LOWORD(wParam));
}
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
//******************************************************************************
//***** Event Handlers for our Main Window
//******************************************************************************
int OnCreate() {
// Our toolbar buttons.
static TBBUTTON tbButton[] = {
{ 0, 0, 0, TBSTYLE_SEP, 0, 0, 0, -1 },
{ 0, IDM_FILE_OPEN, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 },
{ 0, 0, 0, TBSTYLE_SEP, 0, 0, 0, -1 },
{ 1, IDM_FILE_PROPERTIES, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 },
{ 0, 0, 0, TBSTYLE_SEP, 0, 0, 0, -1 },
{ 2, IDM_ACTION_EXTRACT, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 },
{ 3, IDM_ACTION_EXTRACT_ALL, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 },
{ 0, 0, 0, TBSTYLE_SEP, 0, 0, 0, -1 },
{ 4, IDM_ACTION_TEST, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 },
{ 5, IDM_ACTION_TEST_ALL, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 },
{ 0, 0, 0, TBSTYLE_SEP, 0, 0, 0, -1 },
{ 6, IDM_ACTION_VIEW, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 },
{ 0, 0, 0, TBSTYLE_SEP, 0, 0, 0, -1 },
{ 7, IDM_VIEW_EXPANDED_VIEW, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 },
{ 8, IDM_VIEW_COMMENT, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 }
};
// Our toolbar buttons' tool tip text.
static LPTSTR szToolTips[] = {
TEXT(""), // Menu
TEXT("Open (Ctrl+O)"),
TEXT("Properties (Alt+Enter)"),
TEXT("Extract Selected Files"),
TEXT("Extract All Files"),
TEXT("Test Selected Files"),
TEXT("Test All Files"),
TEXT("View Selected File"),
TEXT("Expanded View"),
TEXT("View Zip File Comment")
};
// Initialize the common controls.
InitCommonControls();
// Check to see if we have a help file.
BOOL fHelp = (GetFileAttributes(g_szHelpFile) != 0xFFFFFFFF);
// Set our window's icon so it can update the task bar.
if (g_hIconMain) {
SendMessage(g_hWndMain, WM_SETICON, FALSE, (LPARAM)g_hIconMain);
}
// Create the tree control. Our main window will resize it to fit.
g_hWndList = CreateWindow(WC_LISTVIEW, TEXT(""),
WS_VSCROLL | WS_CHILD | WS_VISIBLE |
LVS_REPORT | LVS_SHOWSELALWAYS,
0, 0, 0, 0, g_hWndMain, NULL, g_hInst, NULL);
#ifdef _WIN32_WCE
// Create a command bar and add the toolbar bitmaps to it.
g_hWndCmdBar = CommandBar_Create(g_hInst, g_hWndMain, 1);
CommandBar_AddBitmap(g_hWndCmdBar, g_hInst, IDB_TOOLBAR, 9, 16, 16);
CommandBar_InsertMenubar(g_hWndCmdBar, g_hInst, IDR_UNZIP, 0);
CommandBar_AddButtons(g_hWndCmdBar, countof(tbButton), tbButton);
CommandBar_AddAdornments(g_hWndCmdBar, fHelp ? CMDBAR_HELP : 0, 0);
// Add tool tips to the tool bar.
CommandBar_AddToolTips(g_hWndCmdBar, countof(szToolTips), szToolTips);
// Store the height of the command bar for later calculations.
g_cyCmdBar = CommandBar_Height(g_hWndCmdBar);
// We set our wait window handle to our menu window within our command bar.
// This is the last window that will be painted during startup of our app.
g_hWndWaitFor = GetWindow(g_hWndCmdBar, GW_CHILD);
// Add the help item to our help menu if we have a help file.
if (fHelp) {
HMENU hMenu = GetSubMenu(CommandBar_GetMenu(g_hWndCmdBar, 0), 3);
InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
InsertMenu(hMenu, 0, MF_BYPOSITION | MF_ENABLED, IDHELP, TEXT("&Help"));
}
#else
// Create a tool bar and add the toolbar bitmaps to it.
g_hWndCmdBar = CreateToolbarEx(g_hWndMain, WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS,
1, 9, g_hInst, IDB_TOOLBAR, tbButton,
countof(tbButton), 16, 16, 16, 16,
sizeof(TBBUTTON));
// Get our tool tip control.
HWND hWndTT = (HWND)SendMessage(g_hWndCmdBar, TB_GETTOOLTIPS, 0, 0);
// Set our tool tip strings.
TOOLINFO ti;
ti.cbSize = sizeof(ti);
int tip = 0, button;
while (SendMessage(hWndTT, TTM_ENUMTOOLS, tip++, (LPARAM)&ti)) {
for (button = 0; button < countof(tbButton); button++) {
if (tbButton[button].idCommand == (int)ti.uId) {
ti.lpszText = szToolTips[tbButton[button].iBitmap + 1];
SendMessage(hWndTT, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
break;
}
}
}
// Store the height of the tool bar for later calculations.
RECT rc;
GetWindowRect(g_hWndCmdBar, &rc);
g_cyCmdBar = rc.bottom - rc.top;
// We set our wait window handle to our toolbar.
// This is the last window that will be painted during the startup of our app.
g_hWndWaitFor = g_hWndCmdBar;
// Add the help item to our help menu if we have a help file.
if (fHelp) {
HMENU hMenu = GetSubMenu(GetMenu(g_hWndMain), 3);
InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
InsertMenu(hMenu, 0, MF_BYPOSITION | MF_ENABLED, IDHELP, TEXT("&Help\tF1"));
}
#endif // _WIN32_WCE
// Enable Full Row Select - This feature is supported on Windows CE and was
// introduced to Win95/NT with IE 3.0. If the user does not have a
// COMCTL32.DLL that supports this feature, then they will just see the
// old standard First Column Select.
SendMessage(g_hWndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT |
SendMessage(g_hWndList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0));
// Get our expanded view option from the registry.
g_fExpandedView = GetOptionInt(TEXT("ExpandedView"), FALSE);
// Show or remove menu check for expanded view option.
CheckAllMenuItems(IDM_VIEW_EXPANDED_VIEW, g_fExpandedView);
// Create our columns.
AddDeleteColumns();
// Set our current sort column to our name column
Sort(0, TRUE);
return 0;
}
//******************************************************************************
void OnFileOpen() {
TCHAR szPath[_MAX_PATH] = TEXT("");
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = g_hWndMain;
ofn.hInstance = g_hInst;
ofn.lpstrFilter = TEXT("ZIP files (*.zip)\0*.zip\0SFX files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0");
ofn.nFilterIndex = 1;
ofn.lpstrFile = szPath;
ofn.nMaxFile = countof(szPath);
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
ofn.lpstrDefExt = TEXT("zip");
if (GetOpenFileName(&ofn)) {
ReadZipFileList(szPath);
}
}
//******************************************************************************
void OnActionView() {
// We only allow a view if one item is selected.
int count = ListView_GetSelectedCount(g_hWndList);
if (count != 1) {
return;
}
// Query the selected item for its FILE_NODE.
LV_ITEM lvi;
ZeroMemory(&lvi, sizeof(lvi));
lvi.mask = LVIF_IMAGE | LVIF_PARAM;
lvi.iItem = ListView_GetNextItem(g_hWndList, -1, LVNI_SELECTED);
ListView_GetItem(g_hWndList, &lvi);
FILE_NODE *pfn = (FILE_NODE*)lvi.lParam;
// Bail out if the selected item is a folder or volume label.
if (pfn->dwAttributes & (FILE_ATTRIBUTE_DIRECTORY | ZFILE_ATTRIBUTE_VOLUME)) {
MessageBox(g_hWndMain, TEXT("You cannot view folders or volume labels."),
g_szAppName, MB_ICONINFORMATION | MB_OK);
return;
}
// Make sure our temporary directory exists.
CreateDirectory(g_szTempDir, NULL);
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
sei.nShow = SW_SHOWNORMAL;
#ifdef _WIN32_WCE
TCHAR szApp[_MAX_PATH];
// On Windows CE, there is no default file association dialog that appears
// when ShellExecuteEx() is given an unknown file type. We check to see if
// file is unknown, and display our own file association prompt.
// Check our file image to see if this file has no associated viewer.
if (lvi.iImage == IMAGE_GENERIC) {
// Display our file association prompt dialog.
if (IDOK != DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_VIEW_ASSOCIATION),
g_hWndMain, (DLGPROC)DlgProcViewAssociation,
(LPARAM)szApp))
{
// If the user aborted the association prompt, then delete file and exit.
SetFileAttributes(szPath, FILE_ATTRIBUTE_NORMAL);
if (!DeleteFile(szPath)) {
SetFileAttributes(szPath, FILE_ATTRIBUTE_READONLY);
}
return;
}
// Set the file to be the viewer app and the parameters to be the file.
// Note: Some applications require that arguments with spaces be quoted,
// while other applications choked when quotes we part of the filename.
// In the end, it seems safer to leave the quotes off.
sei.lpFile = szApp;
sei.lpParameters = szPath;
} else {
sei.lpFile = szPath;
}
#else
// On NT, ShellExecuteEx() will prompt user for association if needed.
sei.lpFile = szPath;
#endif
// Launch the file. All errors will be displayed by ShellExecuteEx().
ShellExecuteEx(&sei);
}
//******************************************************************************
void OnActionSelectAll() {
for (int i = ListView_GetItemCount(g_hWndList) - 1; i >= 0; i--) {
ListView_SetItemState(g_hWndList, i, LVIS_SELECTED, LVIS_SELECTED);
}
}
//******************************************************************************
void OnViewExpandedView() {
// Toggle our expanded view option.
g_fExpandedView = !g_fExpandedView;
// Show or remove menu check and toolbar button press.
CheckAllMenuItems(IDM_VIEW_EXPANDED_VIEW, g_fExpandedView);
// Display the new columns.
AddDeleteColumns();
// Re-sort if we just did away with out sort column.
if (!g_fExpandedView && (g_sortColumn > 3)) {
Sort(0, TRUE);
}
// Write our expanded view option to the registry.
WriteOptionInt(TEXT("ExpandedView"), g_fExpandedView);
}
//******************************************************************************
void OnHelp() {
// Prepare to launch the help file.
SHELLEXECUTEINFO sei;
ZeroMemory(&sei, sizeof(sei));
sei.cbSize = sizeof(sei);
sei.hwnd = g_hWndMain;
sei.lpFile = g_szHelpFile;
// Launch the file.
ShellExecuteEx(&sei);
}
//******************************************************************************
//***** Event Handlers for our List View
//******************************************************************************
void OnGetDispInfo(LV_DISPINFO *plvdi) {
// Make sure we have the minimum amount of data to process this event.
if ((plvdi->item.iItem < 0) || !plvdi->item.lParam || !plvdi->item.pszText) {
return;
}
// Get a pointer to the file node for this item.
FILE_NODE *pFile = (FILE_NODE*)plvdi->item.lParam;
CHAR szBuffer[_MAX_PATH * 2];
switch (plvdi->item.iSubItem) {
case 0: // Name
// Copy the string to a temporary buffer.
strcpy(szBuffer, pFile->szPathAndMethod);
// Change all forward slashes to back slashes in the buffer
ForwardSlashesToBackSlashesA(szBuffer);
// Convert the string to UNICODE and store it in our list control.
MBSTOTSTR(plvdi->item.pszText, szBuffer, plvdi->item.cchTextMax);
return;
case 1: // Size
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
return;
case 3: // Modified
int hour; hour = (pFile->dwModified >> 6) & 0x001F;
_stprintf(plvdi->item.pszText, TEXT("%u/%u/%u %u:%02u %cM"),
(pFile->dwModified >> 16) & 0x000F,
(pFile->dwModified >> 11) & 0x001F,
((pFile->dwModified >> 20) & 0x0FFF) % 100,
(hour % 12) ? (hour % 12) : 12,
pFile->dwModified & 0x003F,
hour >= 12 ? 'P' : 'A');
return;
case 4: // Attributes
BuildAttributesString(plvdi->item.pszText, pFile->dwAttributes);
return;
case 5: // Compressed
FormatValue(plvdi->item.pszText, pFile->uzCompressedSize);
return;
case 6: // Ratio
int factor; factor = ratio(pFile->uzSize, pFile->uzCompressedSize);
_stprintf(plvdi->item.pszText, TEXT("%d.%d%%"), factor / 10,
((factor < 0) ? -factor : factor) % 10);
return;
case 7: // Method
MBSTOTSTR(plvdi->item.pszText, pFile->szPathAndMethod + strlen(pFile->szPathAndMethod) + 1,
plvdi->item.cchTextMax);
return;
case 8: // CRC
_stprintf(plvdi->item.pszText, TEXT("%08X"), pFile->dwCRC);
return;
case 9: // Comment
MBSTOTSTR(plvdi->item.pszText, pFile->szComment ? pFile->szComment : "",
plvdi->item.cchTextMax);
return;
}
}
//******************************************************************************
void OnDeleteItem(NM_LISTVIEW *pnmlv) {
if (pnmlv->lParam) {
// Free any comment string associated with this item.
if (((FILE_NODE*)pnmlv->lParam)->szComment) {
delete[] (CHAR*)((FILE_NODE*)pnmlv->lParam)->szComment;
}
// Free the item itself.
delete[] (LPBYTE)pnmlv->lParam;
}
}
//******************************************************************************
void OnItemChanged(NM_LISTVIEW *pnmlv) {
int count = ListView_GetSelectedCount(pnmlv->hdr.hwndFrom);
EnableAllMenuItems(IDM_FILE_PROPERTIES, count > 0);
EnableAllMenuItems(IDM_ACTION_EXTRACT, count > 0);
EnableAllMenuItems(IDM_ACTION_TEST, count > 0);
EnableAllMenuItems(IDM_ACTION_VIEW, count == 1);
}
//******************************************************************************
//***** List View Sort Functions
//******************************************************************************
void Sort(int sortColumn, BOOL fForce) {
// Do not change the column header text if it is already correct.
if (sortColumn != g_sortColumn) {
TCHAR szColumn[32];
LV_COLUMN lvc;
lvc.mask = LVCF_TEXT;
lvc.pszText = szColumn;
// Remove the '^' from the current sort column.
if (g_sortColumn != -1) {
_stprintf(szColumn, (g_columns[g_sortColumn].format == LVCFMT_LEFT) ?
TEXT("%s ") : TEXT(" %s"), g_columns[g_sortColumn].szName);
ListView_SetColumn(g_hWndList, g_sortColumn, &lvc);
}
// Set the new sort column.
g_sortColumn = sortColumn;
// Add the '^' to the new sort column.
_stprintf(szColumn, (g_columns[g_sortColumn].format == LVCFMT_LEFT) ?
TEXT("%s ^") : TEXT("^ %s"), g_columns[g_sortColumn].szName);
ListView_SetColumn(g_hWndList, g_sortColumn, &lvc);
// Sort the list by the new column.
ListView_SortItems(g_hWndList, CompareFunc, g_sortColumn);
} else if (fForce) {
// Force the list to sort by the same column.
ListView_SortItems(g_hWndList, CompareFunc, g_sortColumn);
}
}
//******************************************************************************
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM sortColumn) {
FILE_NODE *pFile1 = (FILE_NODE*)lParam1, *pFile2 = (FILE_NODE*)lParam2;
TCHAR szBuffer1[8], szBuffer2[8];
// Return Negative value if the first item should precede the second.
// Return Positive value if the first item should follow the second.
// Return Zero if the two items are equivalent.
int result = 0;
// Compute the relationship based on the current sort column
switch (sortColumn) {
case 1: // Size - Smallest to Largest
if (pFile1->uzSize != pFile2->uzSize) {
result = ((pFile1->uzSize < pFile2->uzSize) ? -1 : 1);
}
break;
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
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, '.');
// Search our known extension list for this extension.
if (pszExt && *(pszExt + 1)) {
// Loop through our linked list
for (FILE_TYPE_NODE *pft = g_pftHead; pft; pft = pft->pNext) {
// Check for a match.
if (!_stricmp(pszExt + 1, pft->szExtAndDesc)) {
// We found a match, store the image and type string and exit loop.
lvi.iImage = pft->image;
pFile->szType = pft->szExtAndDesc + strlen(pft->szExtAndDesc) + 1;
if (!*pFile->szType) {
pFile->szType = NULL;
}
break;
}
}
}
}
// Add the item to our list.
ListView_InsertItem(g_hWndList, &lvi);
}
//******************************************************************************
void EnableAllMenuItems(UINT uMenuItem, BOOL fEnabled) {
#ifdef _WIN32_WCE
HMENU hMenu = CommandBar_GetMenu(g_hWndCmdBar, 0);
#else
HMENU hMenu = GetMenu(g_hWndMain);
#endif
EnableMenuItem(hMenu, uMenuItem, fEnabled ? MF_ENABLED : MF_GRAYED);
SendMessage(g_hWndCmdBar, TB_ENABLEBUTTON, uMenuItem, MAKELONG(fEnabled, 0));
}
//******************************************************************************
void CheckAllMenuItems(UINT uMenuItem, BOOL fChecked) {
#ifdef _WIN32_WCE
HMENU hMenu = CommandBar_GetMenu(g_hWndCmdBar, 0);
#else
HMENU hMenu = GetMenu(g_hWndMain);
#endif
CheckMenuItem(hMenu, uMenuItem, fChecked ? MF_CHECKED : MF_UNCHECKED);
SendMessage(g_hWndCmdBar, TB_PRESSBUTTON, uMenuItem, MAKELONG(fChecked, 0));
}
//******************************************************************************
void CenterWindow(HWND hWnd) {
RECT rc, rcParent;
// Get our window rectangle.
GetWindowRect(hWnd, &rc);
// Get our parent's window rectangle.
GetWindowRect(GetParent(hWnd), &rcParent);
// Center our window over our parent's window.
SetWindowPos(hWnd, NULL,
rcParent.left + ((rcParent.right - rcParent.left) - (rc.right - rc.left)) / 2,
rcParent.top + ((rcParent.bottom - rcParent.top ) - (rc.bottom - rc.top )) / 2,
0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
//******************************************************************************
void AddTextToEdit(LPCSTR szText) {
if (!g_hWndEdit) {
return;
}
// Add the characters one by one to our edit box while performing the
// the following newline conversions:
// Single CR -> CR/LF
// Single LF -> CR/LF
// CR and LF -> CR/LF
// LF and CR -> CR/LF
// 0 - 31 -> ^char
TCHAR szOut[256], *pszOut = szOut;
CHAR *pszIn = (LPSTR)szText, cPrev = '\0';
while (*pszIn) {
if (*pszIn == '\n') {
if (cPrev == '\r') {
cPrev = '\0';
} else {
*(pszOut++) = TEXT('\r');
*(pszOut++) = TEXT('\n');
cPrev = '\n';
}
} else if (*pszIn == '\r') {
if (cPrev == '\n') {
cPrev = '\0';
} else {
*(pszOut++) = TEXT('\r');
*(pszOut++) = TEXT('\n');
cPrev = '\r';
}
} else if ((*pszIn < 32) && (*pszIn != '\t')) {
*(pszOut++) = (TCHAR)'^';
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
//******************************************************************************
LRESULT CALLBACK EditSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
BOOL fCtrl, fShift;
switch (uMsg) {
// For cut, paste, delete, and undo, the control post itself a message.
// we throw away that message. This works as a fail-safe in case we miss
// some keystroke that causes one of these operations. This also disables
// the context menu on NT from causing one of these actions to occur.
case WM_CUT:
case WM_PASTE:
case WM_CLEAR:
case WM_UNDO:
MessageBeep(0);
return 0;
// WM_CHAR is used for normal characters. A-Z, numbers, symbols, enter,
// backspace, esc, and tab. In does not include del or movement keys.
case WM_CHAR:
fCtrl = (GetKeyState(VK_CONTROL) & 0x8000) ? TRUE : FALSE;
// We only allow CTRL-C (copy), plain ESC, plain TAB, plain ENTER.
if (( fCtrl && (wParam == 3)) ||
(!fCtrl && (wParam == VK_ESCAPE)) ||
(!fCtrl && (wParam == VK_RETURN)) ||
(!fCtrl && (wParam == VK_TAB)))
{
break;
}
MessageBeep(0);
return 0;
// WM_KEYDOWN handles del, insert, arrows, pg up/down, home/end.
case WM_KEYDOWN:
fCtrl = (GetKeyState(VK_CONTROL) & 0x8000) ? TRUE : FALSE;
fShift = (GetKeyState(VK_SHIFT) & 0x8000) ? TRUE : FALSE;
// Skip all forms of DELETE, SHIFT-INSERT (paste),
// CTRL-RETURN (hard-return), and CTRL-TAB (hard-tab).
if (( (wParam == VK_DELETE)) ||
(fShift && (wParam == VK_INSERT)) ||
(fCtrl && (wParam == VK_RETURN)) ||
(fCtrl && (wParam == VK_TAB)))
{
MessageBeep(0);
return 0;
}
break;
}
return CallWindowProc(g_wpEdit, hWnd, uMsg, wParam, lParam);
}
//******************************************************************************
//***** MRU Functions
//******************************************************************************
#ifdef _WIN32_WCE
int GetMenuString(HMENU hMenu, UINT uIDItem, LPTSTR lpString, int nMaxCount,
UINT uFlag) {
MENUITEMINFO mii;
ZeroMemory(&mii, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_TYPE;
mii.dwTypeData = lpString;
mii.cch = nMaxCount;
return (GetMenuItemInfo(hMenu, uIDItem, uFlag == MF_BYPOSITION, &mii) ?
mii.cch : 0);
}
#endif
//******************************************************************************
void InitializeMRU() {
TCHAR szMRU[MRU_MAX_FILE][_MAX_PATH + 4], szOption[8];
int i, j;
// Get our menu handle.
#ifdef _WIN32_WCE
HMENU hMenu = GetSubMenu(CommandBar_GetMenu(g_hWndCmdBar, 0), 0);
#else
HMENU hMenu = GetSubMenu(GetMenu(g_hWndMain), 0);
#endif
// Read all our current MRUs from the registry.
for (i = 0, j = 0; i < MRU_MAX_FILE; i++) {
// Build option name for current MRU and read from registry.
_stprintf(szOption, TEXT("MRU%d"), i+1);
GetOptionString(szOption, TEXT(""), &szMRU[i][3], sizeof(TCHAR) * _MAX_PATH);
// If this MRU exists, then add it.
if (szMRU[i][3]) {
// Build the accelerator prefix for this menu item.
szMRU[i][0] = TEXT('&');
szMRU[i][1] = TEXT('1') + j;
szMRU[i][2] = TEXT(' ');
// Add the item to our menu.
InsertMenu(hMenu, 4 + j, MF_BYPOSITION | MF_STRING, MRU_START_ID + j,
szMRU[i]);
// Increment our actual MRU count.
j++;
}
}
}
//******************************************************************************
void AddFileToMRU(LPCSTR szFile) {
TCHAR szMRU[MRU_MAX_FILE + 1][_MAX_PATH + 4], szOption[8];
int i, j;
// Store the new file in our first MRU index.
MBSTOTSTR(&szMRU[0][3], szFile, _MAX_PATH);
//---------------------------------------------------------------------------
// We first read the current MRU list from the registry, merge in our new
// file at the top, and then write back to the registry. The registry merge
// is done to allow multiple instances of Pocket UnZip to maintain a global
// MRU list independent to this current instance's MRU list.
//---------------------------------------------------------------------------
// Read all our current MRUs from the registry.
for (i = 1; i <= MRU_MAX_FILE; i++) {
// Build option name for current MRU and read from registry.
_stprintf(szOption, TEXT("MRU%d"), i);
GetOptionString(szOption, TEXT(""), &szMRU[i][3], sizeof(TCHAR) * _MAX_PATH);
}
// Write our new merged MRU list back to the registry.
for (i = 0, j = 0; (i <= MRU_MAX_FILE) && (j < MRU_MAX_FILE); i++) {
// If this MRU exists and is different then our new file, then add it.
if ((i == 0) || (szMRU[i][3] && _tcsicmp(&szMRU[0][3], &szMRU[i][3]))) {
// Build option name for current MRU and write to registry.
_stprintf(szOption, TEXT("MRU%d"), ++j);
WriteOptionString(szOption, &szMRU[i][3]);
}
}
//---------------------------------------------------------------------------
// The next thing we need to do is read our local MRU from our File menu,
// merge in our new file, and store the new list back to our File menu.
//---------------------------------------------------------------------------
// Get our menu handle.
#ifdef _WIN32_WCE
HMENU hMenu = GetSubMenu(CommandBar_GetMenu(g_hWndCmdBar, 0), 0);
#else
HMENU hMenu = GetSubMenu(GetMenu(g_hWndMain), 0);
#endif
// Read all our current MRUs from our File Menu.
for (i = 1; i <= MRU_MAX_FILE; i++) {
// Query our file Menu for a MRU file.
if (GetMenuString(hMenu, MRU_START_ID + i - 1, szMRU[i],
countof(szMRU[0]), MF_BYCOMMAND))
{
// Delete this item from the menu for now.
DeleteMenu(hMenu, MRU_START_ID + i - 1, MF_BYCOMMAND);
} else {
szMRU[i][3] = TEXT('\0');
}
}
// Write our new merged MRU list back to the File menu.
for (i = 0, j = 0; (i <= MRU_MAX_FILE) && (j < MRU_MAX_FILE); i++) {
// If this MRU exists and is different then our new file, then add it.
if ((i == 0) || (szMRU[i][3] && _tcsicmp(&szMRU[0][3], &szMRU[i][3]))) {
// Build the accelerator prefix for this menu item.
szMRU[i][0] = TEXT('&');
szMRU[i][1] = TEXT('1') + j;
szMRU[i][2] = TEXT(' ');
// Add the item to our menu.
InsertMenu(hMenu, 4 + j, MF_BYPOSITION | MF_STRING, MRU_START_ID + j,
szMRU[i]);
// Increment our actual MRU count.
j++;
}
}
}
//******************************************************************************
void RemoveFileFromMRU(LPCTSTR szFile) {
TCHAR szMRU[MRU_MAX_FILE][_MAX_PATH + 4], szOption[8];
int i, j;
BOOL fFound;
//---------------------------------------------------------------------------
// We first look for this file in our global MRU stored in the registry. We
// read the current MRU list from the registry, and then write it back while
// removing all occurrances of the file specified.
//---------------------------------------------------------------------------
// Read all our current MRUs from the registry.
for (i = 0, fFound = FALSE; i < MRU_MAX_FILE; i++) {
// Build option name for current MRU and read from registry.
_stprintf(szOption, TEXT("MRU%d"), i+1);
GetOptionString(szOption, TEXT(""), &szMRU[i][3], sizeof(TCHAR) * _MAX_PATH);
// Check for a match.
if (!_tcsicmp(szFile, &szMRU[i][3])) {
szMRU[i][3] = TEXT('\0');
fFound = TRUE;
}
}
// Only write the MRU back to the registry if we found a file to remove.
if (fFound) {
// Write the updated MRU list back to the registry.
for (i = 0, j = 0; i < MRU_MAX_FILE; i++) {
// If this MRU still exists, then add it.
if (szMRU[i][3]) {
// Build option name for current MRU and write to registry.
_stprintf(szOption, TEXT("MRU%d"), ++j);
WriteOptionString(szOption, &szMRU[i][3]);
}
}
// If our list got smaller, clear the unused items in the registry.
while (j++ < MRU_MAX_FILE) {
_stprintf(szOption, TEXT("MRU%d"), j);
WriteOptionString(szOption, TEXT(""));
}
}
//---------------------------------------------------------------------------
// We next thing we do is look for this file in our local MRU stored in our
// File menu. We read the current MRU list from the menu, and then write it
// back while removing all occurrances of the file specified.
//---------------------------------------------------------------------------
// Get our menu handle.
#ifdef _WIN32_WCE
HMENU hMenu = GetSubMenu(CommandBar_GetMenu(g_hWndCmdBar, 0), 0);
#else
HMENU hMenu = GetSubMenu(GetMenu(g_hWndMain), 0);
#endif
// Read all our current MRUs from our File Menu.
for (i = 0, fFound = FALSE; i < MRU_MAX_FILE; i++) {
// Query our file Menu for a MRU file.
if (!GetMenuString(hMenu, MRU_START_ID + i, szMRU[i], countof(szMRU[0]),
MF_BYCOMMAND))
{
szMRU[i][3] = TEXT('\0');
}
// Check for a match.
if (!_tcsicmp(szFile, &szMRU[i][3])) {
szMRU[i][3] = TEXT('\0');
fFound = TRUE;
}
}
// Only update menu if we found a file to remove.
if (fFound) {
// Clear out our menu's MRU list.
for (i = MRU_START_ID; i < (MRU_START_ID + MRU_MAX_FILE); i++) {
DeleteMenu(hMenu, i, MF_BYCOMMAND);
}
// Write the rest of our MRU list back to the menu.
for (i = 0, j = 0; i < MRU_MAX_FILE; i++) {
// If this MRU still exists, then add it.
if (szMRU[i][3]) {
// Build the accelerator prefix for this menu item.
szMRU[i][0] = TEXT('&');
szMRU[i][1] = TEXT('1') + j;
szMRU[i][2] = TEXT(' ');
// Add the item to our menu.
InsertMenu(hMenu, 4 + j, MF_BYPOSITION | MF_STRING, MRU_START_ID + j,
szMRU[i]);
// Increment our actual MRU count.
j++;
}
}
}
}
//******************************************************************************
void ActivateMRU(UINT uIDItem) {
TCHAR szFile[_MAX_PATH + 4];
// Get our menu handle.
#ifdef _WIN32_WCE
HMENU hMenu = GetSubMenu(CommandBar_GetMenu(g_hWndCmdBar, 0), 0);
#else
HMENU hMenu = GetSubMenu(GetMenu(g_hWndMain), 0);
#endif
// Query our menu for the selected MRU.
if (GetMenuString(hMenu, uIDItem, szFile, countof(szFile), MF_BYCOMMAND)) {
// Move past 3 character accelerator prefix and open the file.
ReadZipFileList(&szFile[3]);
}
}
//******************************************************************************
//***** Open Zip File Functions
//******************************************************************************
void ReadZipFileList(LPCTSTR wszPath) {
// Show wait cursor.
HCURSOR hCur = SetCursor(LoadCursor(NULL, IDC_WAIT));
TSTRTOMBS(g_szZipFile, wszPath, countof(g_szZipFile));
// Update our banner to show that we are loading.
g_fLoading = TRUE;
DrawBanner(NULL);
// Update our caption to show that we are loading.
SetCaptionText(TEXT("Loading"));
// Clear our list view.
ListView_DeleteAllItems(g_hWndList);
// Ghost all our Unzip related menu items.
EnableAllMenuItems(IDM_FILE_PROPERTIES, FALSE);
EnableAllMenuItems(IDM_ACTION_EXTRACT, FALSE);
EnableAllMenuItems(IDM_ACTION_EXTRACT_ALL, FALSE);
EnableAllMenuItems(IDM_ACTION_TEST, FALSE);
EnableAllMenuItems(IDM_ACTION_TEST_ALL, FALSE);
EnableAllMenuItems(IDM_ACTION_VIEW, FALSE);
EnableAllMenuItems(IDM_ACTION_SELECT_ALL, FALSE);
EnableAllMenuItems(IDM_VIEW_COMMENT, FALSE);
// Let Info-ZIP and our callbacks do the work.
SendMessage(g_hWndList, WM_SETREDRAW, FALSE, 0);
int result = DoListFiles(g_szZipFile);
SendMessage(g_hWndList, WM_SETREDRAW, TRUE, 0);
// Restore/remove cursor.
SetCursor(hCur);
// Update our column widths
ResizeColumns();
if ((result == PK_OK) || (result == PK_WARN)) {
// Sort the items by name.
Sort(0, TRUE);
// Update this file to our MRU list and menu.
AddFileToMRU(g_szZipFile);
// Enabled the comment button if the zip file has a comment.
if (lpUserFunctions->cchComment) {
EnableAllMenuItems(IDM_VIEW_COMMENT, TRUE);
}
// Update other items that are related to having a Zip file loaded.
EnableAllMenuItems(IDM_ACTION_EXTRACT_ALL, TRUE);
EnableAllMenuItems(IDM_ACTION_TEST_ALL, TRUE);
EnableAllMenuItems(IDM_ACTION_SELECT_ALL, TRUE);
} else {
// Make sure we didn't partially load and added a few files.
ListView_DeleteAllItems(g_hWndList);
// If the file itself is bad or missing, then remove it from our MRU.
if ((result == PK_ERR) || (result == PK_BADERR) || (result == PK_NOZIP) ||
(result == PK_FIND) || (result == PK_EOF))
{
RemoveFileFromMRU(wszPath);
}
// Display an error.
TCHAR szError[_MAX_PATH + 128];
_stprintf(szError, TEXT("Failure loading \"%s\".\n\n"), wszPath);
_tcscat(szError, GetZipErrorString(result));
MessageBox(g_hWndMain, szError, g_szAppName, MB_OK | MB_ICONERROR);
// Clear our file status.
*g_szZipFile = '\0';
}
// Update our caption to show that we are done loading.
SetCaptionText(NULL);
// Update our banner to show that we are done loading.
g_fLoading = FALSE;
DrawBanner(NULL);
}
//******************************************************************************
//***** Zip File Properties Dialog Functions
//******************************************************************************
BOOL CALLBACK DlgProcProperties(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_INITDIALOG: {
// Add "General" and "Comments" tabs to tab control. We are using a
// poor man's version of a property sheet. We display our 2 pages
// by showing and hiding controls as necessary. For our purposes,
// this is much easier than dealing with separate property pages.
TC_ITEM tci;
tci.mask = TCIF_TEXT;
tci.pszText = TEXT("General");
TabCtrl_InsertItem(GetDlgItem(hDlg, IDC_TAB), 0, &tci);
tci.pszText = TEXT("Comment");
TabCtrl_InsertItem(GetDlgItem(hDlg, IDC_TAB), 1, &tci);
#ifdef _WIN32_WCE
// Add "Ok" button to caption bar.
SetWindowLong(hDlg, GWL_EXSTYLE, WS_EX_CAPTIONOKBTN |
GetWindowLong(hDlg, GWL_EXSTYLE));
#endif
// Center us over our parent.
( run in 3.232 seconds using v1.01-cache-2.11-cpan-f56aa216473 )