zipalotdlg.cpp
来自「zip的全部算法源代码」· C++ 代码 · 共 1,102 行 · 第 1/2 页
CPP
1,102 行
}
if (!DirExists(m_sTargetDir)) {
if (MessageBox("The target directory does not exist. Do you want to create it?", "Warning", MB_YESNO | MB_ICONINFORMATION) == IDYES) {
if (!MakeSureDirectoryPathExists(m_sTargetDir + "\\")) {
// The directory could not be created.
DWORD dwError = GetLastError();
CString sMsg = "The target directory could not be created\r\n\r\nThe Windows error message is:\r\n\r\n";
sMsg += GetSystemMessage(dwError);
MessageBox(sMsg, "Error", MB_ICONEXCLAMATION);
return;
}
}
else {
// The user does not want to create the directory
return;
}
}
KillUnzipDlg();
m_pUnzipDlg = new CUnzipDlg;
m_pUnzipDlg->m_bCanClose = FALSE;
m_pUnzipDlg->m_pbCloseWhenDone = &m_bCloseWhenDone;
if (m_pUnzipDlg != NULL) {
// Prepare the unzip dialog
hStop = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!::IsWindow(m_pUnzipDlg->m_hWnd)) {
m_pUnzipDlg->Create(IDD_UNZIPDLG, this);
}
}
CExtract * pExtractor = NULL;
// Process all the filters
m_sFilter.Replace("/", " / ");
m_UnzipInfo.sFilter = m_sFilter;
int nCounter = 0;
errorCode nRet;
BOOL bNoArchives = TRUE;
char seps[] = "/";
char * token = strtok((LPTSTR)m_UnzipInfo.sFilter, seps);
while( token != NULL )
{
// While there are tokens in "string"
nCounter++;
// Remove trailing spaces
while (*token == ' ') {
token++;
}
if (strlen(token) < 2) {
token = strtok( NULL, seps );
continue;
}
switch (nCounter) {
case 1:
pExtractor = new CUnzip(m_pUnzipDlg);
m_UnzipInfo.type = ZIP;
break;
case 2:
pExtractor = new CUnrar(m_pUnzipDlg);
m_UnzipInfo.type = RAR;
break;
case 3:
pExtractor = new CUnace(m_pUnzipDlg);
m_UnzipInfo.type = ACE;
break;
}
if (pExtractor == NULL) {
break;
}
m_UnzipInfo.sFilter = token;
pExtractor->Init();
pExtractor->unzipInfo = m_UnzipInfo;
nRet = pExtractor->ExtractAll(m_sSourceDir, m_sTargetDir);
bNoArchives &= nRet == EX_NO_ARCHIVES;
TRACE("Return value thread %d\r\n", nRet);
delete pExtractor;
pExtractor = NULL;
if (nRet == EX_CANCELLED) {
m_pUnzipDlg->CancelStatus();
break;
}
if (nRet == EX_OK) {
}
// Get next token:
token = strtok( NULL, seps );
}
m_pUnzipDlg->m_bCanClose = TRUE;
m_pUnzipDlg->UpdateData();
m_bCloseWhenDone = *m_pUnzipDlg->m_pbCloseWhenDone;
if (nRet == EX_CANCELLED) {
m_pUnzipDlg->CancelStatus();
}
else if (bNoArchives) {
KillUnzipDlg();
MessageBox("No files found that could be extracted", "Info", MB_ICONINFORMATION);
}
else if (m_pUnzipDlg->CloseIfDone()) {
KillUnzipDlg();
}
else {
m_pUnzipDlg->EndStatus();
}
// PostProcess();
UpdateSourceHistory(m_sSourceDir);
}
void CZipALotDlg::OnClose()
{
KillUnzipDlg();
CDialog::OnClose();
}
void CZipALotDlg::OnCancel()
{
KillUnzipDlg();
CDialog::OnCancel();
}
BOOL CZipALotDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message== WM_LBUTTONDOWN || pMsg->message== WM_LBUTTONUP || pMsg->message== WM_MOUSEMOVE) {
m_ToolTip.RelayEvent(pMsg);
}
return CDialog::PreTranslateMessage(pMsg);
}
void CZipALotDlg::OnCheckFiles()
{
m_UnzipInfo.sSource = m_sSourceDir;
m_UnzipInfo.sTarget = m_sTargetDir;
CWaitCursor wait;
UpdateData();
CFileCheckDlg dlg(&m_UnzipInfo);
dlg.DoModal();
}
void CZipALotDlg::GenTargetName()
{
int nSel = -1;
if ((nSel = m_SourceCombo.GetCurSel()) != -1) {
m_SourceCombo.GetLBText(nSel, m_sSourceDir);
}
else {
m_SourceCombo.GetWindowText(m_sSourceDir);
}
if (m_sSourceDir.IsEmpty()) {
return;
}
// Build the default unzip directory name
if (m_sTargetDir.IsEmpty() || !m_bLockTarget) {
m_sTargetDir = m_sSourceDir;
if (m_sSourceDir.Right(1) != "\\")
m_sTargetDir += "\\";
m_sTargetDir += m_sUnzipped;
}
m_TargetBox.SetWindowText(m_sTargetDir);
ToolUpdate();
}
void CZipALotDlg::ToolUpdate()
{
// The tooltips shall show the full name of the directories
m_ToolTip.UpdateTipText(m_sSourceDir, GetDlgItem(IDC_SOURCEDIR));
m_ToolTip.UpdateTipText(m_sTargetDir, GetDlgItem(IDC_TARGETDIR));
}
void CZipALotDlg::OnFilterButton()
{
ShowDetails(!m_bFilterShown);
}
void CZipALotDlg::ShowDetails(BOOL bShow)
{
if (m_bFilterShown && bShow) {
return;
}
if (!m_bFilterShown && !bShow) {
return;
}
RECT dlgrect, inforect, wholeRect;
GetWindowRect(&dlgrect);
m_PropCtrl.GetWindowRect(&inforect);
static int offset = dlgrect.right - inforect.right;
wholeRect = dlgrect;
if (bShow) {
// Expand the dialog
wholeRect.right += ((inforect.right - inforect.left) + offset);
SetDlgItemText(IDC_FILTERBUTTON, "<<< Filter settings");
m_ToolTip.UpdateTipText("Close the filter settings...", GetDlgItem(IDC_FILTERBUTTON));
}
else {
// Make the dialog smaller.
wholeRect.right -= ((inforect.right - inforect.left) + offset);
SetDlgItemText(IDC_FILTERBUTTON, "Filter settings >>>");
m_ToolTip.UpdateTipText("Open the filter settings...", GetDlgItem(IDC_FILTERBUTTON));
}
// If the window is visible, we create a nice sliding efffect...
if (IsWindowVisible()) {
RECT updateRect;
updateRect = dlgrect;
// Get the desktopwindow
CWnd * pWnd = GetDesktopWindow();
int nStep = 16;
// How many times to we have to update the window
int nTimes = ((inforect.right - inforect.left) + offset) / nStep - 1;
for(int x = 0; x < nTimes; x++) {
if (bShow) {
// Move the right border of the window to the right
dlgrect.right += nStep;
// Get the rectangle the window has grown
updateRect.left = updateRect.right;
updateRect.right = updateRect.left + nStep;
}
else {
// Move the right border of the window to the left
dlgrect.right -= nStep;
// Get the rectangle the window became smaller
updateRect.right = updateRect.left;
updateRect.left = updateRect.right - nStep;
}
// Resize and repaint the dialog
MoveWindow(&dlgrect, TRUE);
// Update the new area
pWnd->InvalidateRect(&updateRect);
UpdateWindow();
Sleep(10);
}
}
m_bFilterShown = bShow;
MoveWindow(&wholeRect, TRUE);
/*if (bShow) {
// Expand the dialog
dlgrect.right += ((inforect.right - inforect.left) + offset);
SetDlgItemText(IDC_FILTERBUTTON, "<<< Filter settings");
m_bFilterShown = TRUE;
m_ToolTip.UpdateTipText("Close the filter settings...", GetDlgItem(IDC_FILTERBUTTON));
}
else {
// Make the dialog smaller.
dlgrect.right -= ((inforect.right - inforect.left) + offset);
SetDlgItemText(IDC_FILTERBUTTON, "Filter settings >>>");
m_bFilterShown = FALSE;
m_ToolTip.UpdateTipText("Open the filter settings...", GetDlgItem(IDC_FILTERBUTTON));
}
if (true || IsWindowVisible()) {
RECT rtClip;
m_PropSheet.GetClientRect(&rtClip);
int nWidth = 16;
if (bShow) {
MoveWindow(&dlgrect);
}
int x = 0;
for(x = 0; x <= (inforect.right - inforect.left); x += nWidth) {
rtClip.right = bShow ? x + 20 : inforect.right - x;
m_PropSheet.ScrollWindow(bShow ? nWidth : -nWidth, 0, NULL, &rtClip);
m_PropSheet.InvalidateRect(&rtClip, FALSE);
m_PropSheet.UpdateWindow();
Sleep(10);
}
if (!bShow) {
MoveWindow(&dlgrect);
}
}
else {
MoveWindow(&dlgrect);
}*/
/*MoveWindow(&dlgrect);
for(int x = 0; x < 10; x++) {
m_PropSheet.ScrollWindow(x, 0);
m_PropSheet.InvalidateRect(NULL, TRUE);
m_PropSheet.UpdateWindow();
Sleep(20);
}*/
// Force the window to be redrawn
/*InvalidateRect(NULL);
UpdateWindow();*/
}
void CZipALotDlg::OnDestroy()
{
WinHelp(0l, HELP_QUIT);
CDialog::OnDestroy();
}
BOOL CZipALotDlg::DirExists(CString sDir)
{
if (sDir.Right(1) != "\\") {
sDir += "\\";
}
sDir += "*.*";
CFileFind finder;
BOOL bFound = finder.FindFile(sDir);
finder.Close();
return bFound;
}
void CZipALotDlg::OnTargetLock()
{
UpdateData();
if (m_bLockTarget) {
m_TargetBox.SetReadOnly(TRUE);
m_TargetPickerButton.ModifyStyle(0, WS_DISABLED);
}
else {
m_TargetBox.SetReadOnly(FALSE);
m_TargetPickerButton.ModifyStyle(WS_DISABLED, 0);
}
// Update the window
RECT pickRect;
m_TargetPickerButton.GetWindowRect(&pickRect);
ScreenToClient(&pickRect);
InvalidateRect(&pickRect, TRUE);
UpdateWindow();
}
void CZipALotDlg::FillSourceHistoryCombo()
{
m_SourceCombo.ResetContent();
CZipALotApp * pApp = (CZipALotApp *)AfxGetApp();
if (pApp) {
CString sName;
for (int i = 0; i < HISTORY_SIZE; i++) {
pApp->GetMRUDirName(i, sName);
if (!sName.IsEmpty()) {
m_SourceCombo.AddString(sName);
}
}
}
UpdateData(FALSE);
}
void CZipALotDlg::UpdateSourceHistory(CString &sPath)
{
if (!sPath.IsEmpty()) {
AfxGetApp()->AddToRecentFileList(sPath);
FillSourceHistoryCombo();
}
}
void CZipALotDlg::OnSourceShow()
{
UpdateData();
HINSTANCE hInst = ShellExecute(m_hWnd, "explore", m_sSourceDir, NULL, NULL, SW_SHOWDEFAULT);
if ((long)hInst == ERROR_FILE_NOT_FOUND) {
MessageBox("The directory " + m_sSourceDir + " doesn't exist!", "Error", MB_OK | MB_ICONEXCLAMATION);
}
}
void CZipALotDlg::OnTargetShow()
{
UpdateData();
UpdateData();
HINSTANCE hInst = ShellExecute(m_hWnd, "explore", m_sTargetDir, NULL, NULL, SW_SHOWDEFAULT);
if ((long)hInst == ERROR_FILE_NOT_FOUND) {
MessageBox("The directory " + m_sTargetDir + " doesn't exist!", "Error", MB_OK | MB_ICONEXCLAMATION);
}
}
void CZipALotDlg::OnDropFiles(HDROP hDropInfo)
{
CString sFileName;
// Get the first filename
DragQueryFile(hDropInfo, 0, sFileName.GetBuffer(_MAX_PATH), _MAX_PATH);
sFileName.ReleaseBuffer();
CFileFind finder;
if (finder.FindFile(sFileName)) {
finder.FindNextFile();
// Remove any selection from the combo box
m_SourceCombo.SetCurSel(-1);
if (finder.IsDirectory()) {
m_sSourceDir = sFileName;
}
else {
// Cut off the path if it's a file
m_sSourceDir = sFileName.Left(sFileName.ReverseFind('\\'));
if (m_sSourceDir.GetAt(1) == ':') {
// Append Backslash to drive names
m_sSourceDir += "\\";
}
}
UpdateData(FALSE);
GenTargetName();
}
finder.Close();
CDialog::OnDropFiles(hDropInfo);
}
void CZipALotDlg::PostProcess()
{
CPostProcessDlg dlg(m_sTargetDir);
dlg.DoModal();
}
void CZipALotDlg::OnUseTemp()
{
CString sTemp;
LPTSTR sTempBuf = m_sTargetDir.GetBuffer(_MAX_PATH);
GetTempPath(_MAX_PATH, sTempBuf);
m_sTargetDir.ReleaseBuffer();
m_bLockTarget = TRUE;
UpdateData(FALSE);
OnTargetLock();
}
void CZipALotDlg::OnWarezWizard()
{
CWizSheet propSheet(IDC_WAREZWIZARD);
*propSheet.m_Data.m_psCurSource = m_sSourceDir;
*propSheet.m_Data.m_psCurTarget = m_sTargetDir;
propSheet.m_Data.m_sDefaultInstallDir = m_sDefaultInstallDir;
CWizPageSource wizSource;
CWizPageTarget wizTarget;
wizTarget.m_sUnzipped = m_sUnzipped;
CWizPageNFO wizNFO;
CWizPageAction wizPageAction;
CWizUnzip wizUnzip;
CWizEnd wizEnd;
CWizError wizError;
/*wizPage1.m_psSource = &propSheet.m_sSource;
wizPage2.m_psTarget = &propSheet.m_sTarget;
wizPage2.m_psSource = &propSheet.m_sSource;
wizPage2.m_psTempExtractDir = &propSheet.m_sTempExtractDir;
wizPage3.m_psTempExtractDir = &propSheet.m_sTempExtractDir;
wizPage4.m_psTempExtractDir = &propSheet.m_sTempExtractDir;
wizPage4.m_psTarget = &propSheet.m_sTarget;
wizPage4.m_psSource = &propSheet.m_sSource;
wizPage4.m_psFileToExtract = &propSheet.m_sFileToExtract;
wizPage4.m_psGameDir = &m_sDefaultGameDir;
wizPage4.m_psInstalledDir = &propSheet.m_sInstalledDir;
wizUnzip.m_psTarget = &propSheet.m_sTarget;
wizUnzip.m_psSource = &propSheet.m_sSource;
wizUnzip.m_pError = &propSheet.error;
wizUnzip.m_psFileToExtract = &propSheet.m_sFileToExtract;
wizError.m_pError = &propSheet.error;*/
propSheet.AddPage(&wizSource);
propSheet.AddPage(&wizTarget);
propSheet.AddPage(&wizUnzip);
propSheet.AddPage(&wizNFO);
propSheet.AddPage(&wizPageAction);
propSheet.AddPage(&wizEnd);
propSheet.AddPage(&wizError);
propSheet.SetWizardMode();
propSheet.DoModal();
}
void CZipALotDlg::KillUnzipDlg()
{
if (m_pUnzipDlg == NULL) {
return;
}
TRACE("Kill DLG\r\n");
m_pUnzipDlg->Kill();
delete m_pUnzipDlg;
m_pUnzipDlg = NULL;
TRACE("DLG killed\r\n");
}
void CZipALotDlg::OnConfig()
{
CConfigDlg dlg;
dlg.m_sInstallDir = m_sDefaultInstallDir;
dlg.m_sStartSource = m_sStartSource;
dlg.m_sStartTarget = m_sStartTarget;
dlg.m_sUnzipped = m_sUnzipped;
dlg.m_bTargetLocked = m_bTargetLockedStart;
dlg.m_bCloseWhenDone = m_bCloseWhenDone;
dlg.m_bFilterSettings = m_bFilterSettings;
dlg.DoModal();
m_sDefaultInstallDir = dlg.m_sInstallDir;
m_sStartSource = dlg.m_sStartSource;
m_sStartTarget = dlg.m_sStartTarget;
m_sUnzipped = dlg.m_sUnzipped;
m_bTargetLockedStart = dlg.m_bTargetLocked;
m_bCloseWhenDone = dlg.m_bCloseWhenDone;
m_bFilterSettings = dlg.m_bFilterSettings;
if (dlg.m_bHistoryDeleted) {
FillSourceHistoryCombo();
}
//GenTargetName();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?