zipalotdlg.cpp
来自「zip的全部算法源代码」· C++ 代码 · 共 1,102 行 · 第 1/2 页
CPP
1,102 行
/*************************************************************************
ZipALot
**************************************************************************
Copyright (C) October, 2000 Jean-Pierre Bergamin, james@ractive.ch
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
***************************************************************************/
// ZipALotDlg.cpp : implementation file
//
#include "stdafx.h"
#include <imagehlp.h>
#include "ZipALot.h"
#include "ZipALotDlg.h"
#include "DirectoryPicker.h"
#include "PasswordDlg.h"
#include "Unzip.h"
#include "Unace.h"
#include "Unrar.h"
#include "FileCheckDlg.h"
#include "HyperLink.h"
#include "PostProcessDlg.h"
#include "WizPageSource.h"
#include "WizPageTarget.h"
#include "WizUnzip.h"
#include "WizPageNFO.h"
#include "WizPageAction.h"
#include "WizError.h"
#include "WizEnd.h"
#include "ConfigDlg.h"
#include "WizSheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/* return codes of password fetches (negative = user abort; positive = error) */
#define IZ_PW_ENTERED 0 /* got some password string; use/try it */
#define IZ_PW_CANCEL -1 /* no password available (for this entry) */
#define IZ_PW_CANCELALL -2 /* no password, skip any further pwd. request */
#define IZ_PW_ERROR 5 /* = PK_MEM2 : failure (no mem, no tty, ...) */
// Global function to the a windows error message
// You won't win a design competition with a global funtion, but it's easy to use ;-)
HANDLE hStop;
BOOL Pump(HWND hWnd) {
if (!::IsWindow(hWnd)) {
return FALSE;
}
MSG msg;
// Retrieve and dispatch any waiting messages.
while (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (!AfxGetApp ()->PumpMessage ()) {
::PostQuitMessage (0);
return FALSE;
}
}
return TRUE;
}
CString GetSystemMessage(DWORD dwError)
{
CString sError;
// There's a windows error code.
// Convert that to a string and show it, too.
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
sError = (LPCTSTR)lpMsgBuf;
// Free the buffer.
LocalFree( lpMsgBuf );
return sError;
}
////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CHyperLink m_Email;
CHyperLink m_HomePage;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_EMAIL, m_Email);
DDX_Control(pDX, IDC_HOMEPAGE, m_HomePage);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CZipALotDlg dialog
CZipALotDlg::CZipALotDlg(CWnd* pParent /*=NULL*/)
: CDialog(CZipALotDlg::IDD, pParent), rb("Settings")
{
//{{AFX_DATA_INIT(CZipALotDlg)
m_sSourceDir = _T("");
m_sTargetDir = _T("");
m_bOverwrite = FALSE;
m_bOwnDir = FALSE;
m_bCaseInsensitive = FALSE;
m_bOnlyNewer = FALSE;
m_bRecreateDir = FALSE;
m_bLockTarget = FALSE;
//}}AFX_DATA_INIT
// Set the standard values
m_UnzipInfo.bCaseInsensitive = FALSE;
m_UnzipInfo.bExtract = TRUE;
m_UnzipInfo.bOnlyNewer = FALSE;
m_UnzipInfo.bOverwrite = FALSE;
m_UnzipInfo.bRecreateDir = TRUE;
m_UnzipInfo.sDontExFilter = NULL;
m_UnzipInfo.sExFilter = NULL;
m_UnzipInfo.sFilter = NULL;
m_UnzipInfo.sSource = NULL;
m_UnzipInfo.sTarget = NULL;
m_UnzipInfo.bOwnDir = FALSE;
CString sProgDir = getenv("ProgramFiles");
// And "save" them
rb.Bind(m_bLockTarget, "LockTarget", FALSE);
rb.Bind(m_sTargetDir, "TargetDir", "");
rb.Bind(m_bCloseWhenDone, "CloseIfDone", FALSE);
rb.Bind(m_sDefaultInstallDir, "Games dir", sProgDir);
rb.Bind(m_sStartSource, "Start Source", "");
rb.Bind(m_sStartTarget, "Start Target", "");
rb.Bind(m_sUnzipped, "Unzipped", "unzipped");
rb.Bind(m_bTargetLockedStart, "Target locked startup", FALSE);
rb.Bind(m_bFilterSettings, "Show filter settings", FALSE);
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CZipALotDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CZipALotDlg)
DDX_Control(pDX, IDC_PROPSHEET, m_PropCtrl);
DDX_Control(pDX, IDC_SOURCEDIR, m_SourceCombo);
DDX_Control(pDX, IDC_TARGETPICKER, m_TargetPickerButton);
DDX_Control(pDX, IDC_TARGETDIR, m_TargetBox);
DDX_Text(pDX, IDC_SOURCEDIR, m_sSourceDir);
DDX_Text(pDX, IDC_TARGETDIR, m_sTargetDir);
DDX_Check(pDX, IDC_LOCKTARGET, m_bLockTarget);
//}}AFX_DATA_MAP
/*DDX_Check(pDX, IDC_OVERWRITE, m_UnzipInfo.bOverwrite);
DDX_Check(pDX, IDC_OWNDIR, m_UnzipInfo.bOwnDir);
DDX_Check(pDX, IDC_CASEINSENSITIV, m_UnzipInfo.bCaseInsensitive);
DDX_Check(pDX, IDC_ONLYNEWER, m_UnzipInfo.bOnlyNewer);
DDX_Check(pDX, IDC_RECREATEDIR, m_UnzipInfo.bRecreateDir);
unzip_info.bExtract = TRUE;
unzip_info.sDontExFilter = NULL;
unzip_info.sExFilter = NULL;
unzip_info.sFilter = NULL;*/
if (::IsWindow(m_ExpertPage.m_hWnd)) {
m_ExpertPage.UpdateData();
}
if (m_bFilter && !m_sFilter.IsEmpty()) {
m_UnzipInfo.sFilter = (LPTSTR)(LPCTSTR)m_sFilter;
}
// Set the pointer to the filter, but only if it is not empty
if (m_bExtractCheck && !m_sExtractFilter.IsEmpty()) {
m_UnzipInfo.sExFilter = (LPTSTR)(LPCTSTR)m_sExtractFilter;
}
else {
m_UnzipInfo.sExFilter = NULL;
}
if (m_bDontExtractCheck && !m_sDontExtractFilter.IsEmpty()) {
m_UnzipInfo.sDontExFilter = (LPTSTR)(LPCTSTR)m_sDontExtractFilter;
}
else {
m_UnzipInfo.sDontExFilter = NULL;
}
}
BEGIN_MESSAGE_MAP(CZipALotDlg, CDialog)
//{{AFX_MSG_MAP(CZipALotDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SOURCEPICKER, OnSourcepicker)
ON_BN_CLICKED(IDC_TARGETPICKET, OnTargetpicket)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_CHECKFILES, OnCheckFiles)
ON_BN_CLICKED(IDC_FILTERBUTTON, OnFilterButton)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_LOCKTARGET, OnTargetLock)
ON_BN_CLICKED(IDC_SOURCESHOW, OnSourceShow)
ON_BN_CLICKED(IDC_TARGETSHOW, OnTargetShow)
ON_WM_DROPFILES()
ON_BN_CLICKED(IDC_USETEMP, OnUseTemp)
ON_BN_CLICKED(IDC_WAREZWIZARD, OnWarezWizard)
ON_BN_CLICKED(IDOK, OnOK)
ON_CBN_SELCHANGE(IDC_SOURCEDIR, GenTargetName)
ON_CBN_EDITCHANGE(IDC_SOURCEDIR, GenTargetName)
ON_BN_CLICKED(IDC_CONFIG, OnConfig)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CZipALotDlg message handlers
BOOL CZipALotDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ALWAYSONTOP);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ALWAYSONTOP, strAboutMenu);
}
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_sFilter = "*.zip/*.rar/*.ace";
m_SimplePage.m_pUnzipInfo = &m_UnzipInfo;
m_SimplePage.m_psFilter = &m_sFilter;
m_SimplePage.m_psExtractFilter = &m_sExtractFilter;
m_SimplePage.m_psDontExtractFilter = &m_sDontExtractFilter;
m_SimplePage.m_pbExtractCheck = &m_bExtractCheck;
m_ExpertPage.m_pUnzipInfo = &m_UnzipInfo;
m_ExpertPage.m_psFilter = &m_sFilter;
m_ExpertPage.m_psExtractFilter = &m_sExtractFilter;
m_ExpertPage.m_psDontExtractFilter = &m_sDontExtractFilter;
m_ExpertPage.m_pbFilter = &m_bFilter;
m_ExpertPage.m_pbExtractCheck = &m_bExtractCheck;
m_ExpertPage.m_pbDontExtractCheck = &m_bDontExtractCheck;
m_PropSheet.AddPage(&m_SimplePage);
m_PropSheet.AddPage(&m_ExpertPage);
m_PropSheet.Create(this, WS_CHILD | WS_VISIBLE, 0);
CTabCtrl * pTabCtrl = m_PropSheet.GetTabControl();
DWORD dwStyle= pTabCtrl->GetStyle();
pTabCtrl->ModifyStyle(0, TCS_HOTTRACK | TCS_RIGHTJUSTIFY | WS_TABSTOP);
m_PropSheet.ModifyStyleEx (0, WS_EX_CONTROLPARENT);
m_PropSheet.ModifyStyle( 0, WS_TABSTOP);
CRect rcSheet;
GetDlgItem(IDC_PROPSHEET)->GetWindowRect( &rcSheet );
ScreenToClient( &rcSheet );
m_PropSheet.SetWindowPos(NULL, rcSheet.left-7, rcSheet.top-7, rcSheet.right - 100, rcSheet.bottom,
SWP_NOZORDER | SWP_NOACTIVATE);
m_PropSheet.ModifyStyle(0, WS_EX_TOOLWINDOW);
/*CUnzip unzipper(NULL);
if (!unzipper.Init()) {
CString sMsg = "Cannot find Unzip32.dll\r\nPlease download if from\r\nhttp://www.ractive.ch/gpl/download/Unzip32.dll";
MessageBox(sMsg, "Error", MB_OK);
EndDialog(1);
}*/
m_pUnzipDlg = NULL;
HICON hIcon = (HICON)LoadImage(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_CHANGEDIR), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
if (hIcon) {
((CButton *)GetDlgItem(IDC_SOURCEPICKER))->SetIcon(hIcon);
((CButton *)GetDlgItem(IDC_TARGETPICKER))->SetIcon(hIcon);
}
hIcon = (HICON)LoadImage(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_CHECKOUT), IMAGE_ICON, 43, 36, LR_DEFAULTCOLOR);
if (hIcon) {
((CButton *)GetDlgItem(IDC_CHECKFILES))->SetIcon(hIcon);
}
hIcon = (HICON)LoadImage(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_EXTRACT), IMAGE_ICON, 43, 36, LR_DEFAULTCOLOR);
if (hIcon) {
((CButton *)GetDlgItem(IDOK))->SetIcon(hIcon);
}
hIcon = (HICON)LoadImage(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_WIZARD), IMAGE_ICON, 43, 36, LR_DEFAULTCOLOR);
if (hIcon) {
((CButton *)GetDlgItem(IDC_WAREZWIZARD))->SetIcon(hIcon);
}
hIcon = (HICON)LoadImage(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_CONFIG), IMAGE_ICON, 43, 36, LR_DEFAULTCOLOR);
if (hIcon) {
((CButton *)GetDlgItem(IDC_CONFIG))->SetIcon(hIcon);
}
/*if (m_hIcon) {
((CButton *)GetDlgItem(IDOK))->SetIcon(m_hIcon);
}*/
// TODO
m_ToolTip.Create(this);
m_ToolTip.Activate(TRUE);
m_ToolTip.AddTool(GetDlgItem(IDOK), IDOK);
m_ToolTip.AddTool(GetDlgItem(IDC_CHECKFILES), IDC_CHECKFILES);
m_ToolTip.AddTool(GetDlgItem(IDC_WAREZWIZARD), IDC_WAREZWIZARD);
m_ToolTip.AddTool(GetDlgItem(IDC_SOURCEPICKER), IDC_SOURCEPICKER);
m_ToolTip.AddTool(GetDlgItem(IDC_TARGETPICKER), IDC_TARGETPICKER);
m_ToolTip.AddTool(GetDlgItem(IDC_FILTERBUTTON), IDC_FILTERBUTTON);
m_ToolTip.AddTool(GetDlgItem(IDC_LOCKTARGET), IDC_LOCKTARGET);
m_ToolTip.AddTool(GetDlgItem(IDC_SOURCEDIR), IDC_SOURCEDIR);
m_ToolTip.AddTool(GetDlgItem(IDC_TARGETDIR), IDC_TARGETDIR);
m_ToolTip.AddTool(GetDlgItem(IDC_SOURCESHOW), IDC_SOURCESHOW);
m_ToolTip.AddTool(GetDlgItem(IDC_TARGETSHOW), IDC_TARGETSHOW);
m_ToolTip.AddTool(GetDlgItem(IDC_CONFIG), IDC_CONFIG);
GenTargetName();
m_bFilterShown = TRUE;
ShowDetails(m_bFilterSettings);
FillSourceHistoryCombo();
if (m_SourceCombo.GetCount() > 0) {
m_SourceCombo.SetCurSel(0);
m_SourceCombo.GetLBText(0, m_sSourceDir);
GenTargetName();
}
if (!m_sStartSource.IsEmpty()) {
m_sSourceDir = m_sStartSource;
UpdateSourceHistory(m_sStartSource);
}
if (!m_sStartTarget.IsEmpty()) {
m_sTargetDir = m_sStartTarget;
}
if (!m_sShellDir.IsEmpty()) {
m_sSourceDir = m_sShellDir;
UpdateData(FALSE);
if (m_sStartTarget.IsEmpty()) {
GenTargetName();
}
}
m_bLockTarget = m_bTargetLockedStart;
UpdateData(FALSE);
OnTargetLock();
DragAcceptFiles(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CZipALotDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else if ((nID & 0xFFF0) == IDM_ALWAYSONTOP) {
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
if (pSysMenu->GetMenuState(IDM_ALWAYSONTOP, MF_BYCOMMAND) == MF_CHECKED) {
SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
pSysMenu->CheckMenuItem(IDM_ALWAYSONTOP, MF_UNCHECKED);
}
else {
SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
pSysMenu->CheckMenuItem(IDM_ALWAYSONTOP, MF_CHECKED);
}
}
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CZipALotDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CZipALotDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CZipALotDlg::OnSourcepicker()
{
UpdateData();
// Open a browse dialog
CDirectoryPicker picker(m_hWnd, &m_sSourceDir);
m_SourceCombo.SetCurSel(-1);
UpdateData(FALSE);
GenTargetName();
}
void CZipALotDlg::OnTargetpicket()
{
UpdateData();
CDirectoryPicker picker(m_hWnd, &m_sTargetDir);
ToolUpdate();
UpdateData(FALSE);
}
void CZipALotDlg::OnOK()
{
TRACE("\r\n======================\r\n\r\n");
m_PropSheet.PressButton(PSBTN_APPLYNOW);
UpdateData();
if (m_sSourceDir.IsEmpty() || m_sTargetDir.IsEmpty()) {
MessageBox("Please enter the source and target directory!", "Error", MB_ICONEXCLAMATION);
return;
}
// Check if the directories exist
if (!DirExists(m_sSourceDir)) {
MessageBox("The source directory does not exist. Please choose another one?", "Error", MB_ICONEXCLAMATION);
return;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?