filecheckdlg.cpp

来自「zip的全部算法源代码」· C++ 代码 · 共 634 行 · 第 1/2 页

CPP
634
字号
	// Add size
	CString sEntryText;
	sEntryText.Format("%ld", dwSize);
	item.pszText = (LPTSTR)(LPCTSTR)sEntryText;
	item.iItem = iItem;
	item.iSubItem = 1;
	m_ZIPDetail.SetItem(&item);

	// Add Unpacked Size
	sEntryText.Format("%ld", dwPackedSize);
	item.iSubItem = 2;
	item.pszText = (LPTSTR)(LPCTSTR)sEntryText;
	m_ZIPDetail.SetItem(&item);

	// Add Ratio
	sEntryText.Format("%d%%", nRatio);
	item.iSubItem = 3;
	item.pszText = (LPTSTR)(LPCTSTR)sEntryText;
	m_ZIPDetail.SetItem(&item);

	// Add Date
	item.iSubItem = 4;
	item.pszText = (LPTSTR)(LPCTSTR)sDateTime;
	m_ZIPDetail.SetItem(&item);

	m_nFiles++;
	m_dwPackedSize += dwPackedSize;
	m_dwUnpackedSize += dwSize;
}

void CFileCheckDlg::AddZIPFileHeaders()
{
	int nItem = 0;
	
	int nSubItem = 0;

	// Add the list control headers
	LV_COLUMN lvc;
	lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	lvc.fmt = LVCFMT_LEFT;
	lvc.iSubItem = nSubItem++;
	lvc.cx = 140;
	lvc.pszText = _T("Name");
	m_ZIPDetail.InsertColumn(0, &lvc);
	
	lvc.fmt = LVCFMT_RIGHT;
	lvc.iSubItem = nSubItem++;
	lvc.cx = 70;
	lvc.pszText = _T("Unpacked");
	m_ZIPDetail.InsertColumn(1, &lvc);

	lvc.fmt = LVCFMT_RIGHT;
	lvc.iSubItem = nSubItem++;
	lvc.cx = 70;
	lvc.pszText = _T("Packed");
	m_ZIPDetail.InsertColumn(2, &lvc);

	lvc.fmt = LVCFMT_RIGHT;
	lvc.iSubItem = nSubItem++;
	lvc.cx = 40;
	lvc.pszText = _T("Ratio");
	m_ZIPDetail.InsertColumn(3, &lvc);

	lvc.fmt = LVCFMT_RIGHT;
	lvc.iSubItem = nSubItem++;
	lvc.cx = 100;
	lvc.pszText = _T("Date/Time");
	m_ZIPDetail.InsertColumn(4, &lvc);


}

void CFileCheckDlg::AddFileListHeaders()
{
	int nItem = 0;
	
	int nSubItem = 0;

	// Add the list control headers
	LV_COLUMN lvc;
	lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	lvc.fmt = LVCFMT_LEFT;
	lvc.iSubItem = nSubItem++;
	lvc.cx = 140;
	lvc.pszText = _T("Name");
	m_FileList.InsertColumn(0, &lvc);
	
	lvc.fmt = LVCFMT_RIGHT;
	lvc.iSubItem = nSubItem++;
	lvc.cx = 100;
	lvc.pszText = _T("Size");
	m_FileList.InsertColumn(1, &lvc);

	lvc.fmt = LVCFMT_RIGHT;
	lvc.iSubItem = nSubItem++;
	lvc.cx = 100;
	lvc.pszText = _T("Date/Time");
	m_FileList.InsertColumn(2, &lvc);

}

int CFileCheckDlg::FillFileList(DWORD * pdwTotalSize)
{
	// Add all files that match the filter

	CFileFind finder;
	CString sFind = m_pUnzipInfo->sSource;

	if (sFind.Right(1) != "\\") {
		sFind += "\\";
	}

	*pdwTotalSize = 0;

	// Check for sensefull filter rule and apply standard
	// filter if necessary
	if (m_sFilter.GetLength() < 3) {
		sFind += "*.zip";
	}
	else {
		sFind += m_sFilter;
	}

	BOOL bFound = finder.FindFile(sFind);

	int nFiles = 0;
	int nItem = 0;

	LV_ITEM item;
	while (bFound) {
		item.mask = LVIF_TEXT | LVIF_IMAGE;
		bFound = finder.FindNextFile();
		if (finder.IsDots() || finder.IsDirectory()) {
			// Ignore the directories and the dots in the file list
			continue;
		}
		nFiles++;
		CString sEntryText = finder.GetFileName();
		item.pszText = (LPTSTR)(LPCTSTR)sEntryText;
		item.iItem = nItem++;
		item.iSubItem = 0;

		CString sFilePath = finder.GetFilePath();
		
		item.iImage = GetIconIndex(sFilePath);
		
		int iItem = m_FileList.InsertItem(&item);

		item.mask = LVIF_TEXT;

		// Add size
		DWORD dwSize = finder.GetLength();
		*pdwTotalSize += dwSize;
		sEntryText.Format("%ld", dwSize);
		item.pszText = (LPTSTR)(LPCTSTR)sEntryText;
		item.iItem = iItem;
		item.iSubItem = 1;
		m_FileList.SetItem(&item);

		// Add Date
		item.iSubItem = 2;
		
		FILETIME ftutc, ft;
		SYSTEMTIME st;

		finder.GetLastWriteTime(&ftutc);

		FileTimeToLocalFileTime(&ftutc, &ft);
		FileTimeToSystemTime(&ft, &st);
		

		char sTime[15];
		char sDate[15];
		char sDateTime[31];
		sDateTime[0] = '\0';

		// Or use LOCALE_USER_DEFAULT???
		GetDateFormat(LOCALE_SYSTEM_DEFAULT, DATE_SHORTDATE, &st, NULL, sDate, 15);
		GetTimeFormat(LOCALE_SYSTEM_DEFAULT, TIME_NOSECONDS, &st, NULL, sTime, 15);
		strcpy(sDateTime, sDate);
		strcat(sDateTime, " ");
		strcat(sDateTime, sTime);

		item.pszText = sDateTime;
		m_FileList.SetItem(&item);
	}

	return nFiles;

}

void CFileCheckDlg::HideZIPDetails()
{
	if (m_bInfoShown) {
		// Hide the two controls

		RECT dlgrect, inforect;
		GetWindowRect(&dlgrect);
		m_DetailGroup.GetWindowRect(&inforect);

		// Make the dialog smaller.
		dlgrect.bottom -= (inforect.bottom - inforect.top);
		MoveWindow(&dlgrect);

		m_bInfoShown = FALSE;

		// Force the window to be redrawn
		InvalidateRect(NULL);
		UpdateWindow();
	}

}

void CFileCheckDlg::ShowZIPDetails()
{
	if (!m_bInfoShown) {
		// Hide the two controls
		//m_InfoCtrl.ModifyStyle(WS_VISIBLE, 0);
		//m_DetailGroup.InvalidateRect(NULL);
		RECT dlgrect, inforect;
		GetWindowRect(&dlgrect);
		m_DetailGroup.GetWindowRect(&inforect);

		// Make the dialog smaller.
		dlgrect.bottom += (inforect.bottom - inforect.top);
		MoveWindow(&dlgrect);

		m_bInfoShown = TRUE;

		// Force the window to be redrawn
		InvalidateRect(NULL);
		UpdateWindow();
	}

}


int CFileCheckDlg::GetIconIndex(const CString &sPath)
{
		SHFILEINFO shinfo;

		// We get the index of the file from the ImageList.

		// WARNING: These calls are hideously expensive in terms of time!!!
		SHGetFileInfo(sPath, FILE_ATTRIBUTE_NORMAL, &shinfo, sizeof(shinfo), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
		return shinfo.iIcon;
}

void CFileCheckDlg::OnItemChangedFileList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

	if (pNMListView->iItem == -1 || nLastProcessed == pNMListView->iItem || m_bSorting) {
		return;
	}

	nLastProcessed = pNMListView->iItem;

	m_nFiles = 0;
	m_dwPackedSize = 0;
	m_dwUnpackedSize = 0;
	m_nEncrypted = 0;

	CUnzip unzipper(NULL);
	unzipper.Init();
	CString sZIPFile = m_pUnzipInfo->sSource;
	if (sZIPFile.Right(1) != "\\") {
		sZIPFile += "\\";
	}
	unzipper.InsertFile = &InsertFile;
	sZIPFile += m_FileList.GetItemText(pNMListView->iItem, 0);
	m_ZIPDetail.DeleteAllItems();
	
	// Only show the info
	m_pUnzipInfo->bExtract = FALSE;
	BOOL bTemp = m_pUnzipInfo->bOwnDir;
	m_pUnzipInfo->bOwnDir = FALSE;
	unzipper.unzipInfo = *m_pUnzipInfo;

	int nRet = unzipper.Extract(sZIPFile, NULL);
	m_pUnzipInfo->bOwnDir = bTemp;

	CString sMsg;
	sMsg.Format("%d files - unpacked: %s - packed: %s Bytes", m_nFiles, FormatNumber(m_dwUnpackedSize), FormatNumber(m_dwPackedSize));
	if (m_nEncrypted > 0) {
		CString sEnc;
		sEnc.Format(" - %d encrypted [+]", m_nEncrypted);
		sMsg += sEnc;
	}
	SetDlgItemText(IDC_ZIPTOTAL, sMsg);

	ShowZIPDetails();
	
	*pResult = 0;
}

void CFileCheckDlg::OnFullList() 
{
	//m_ImageList.Detach();
	CWhatIfDlg dlg(m_pUnzipInfo);
	dlg.DoModal();
	AttachSystemImageList();
}

void CFileCheckDlg::AttachSystemImageList()
{
	HIMAGELIST hSmallSystemImageList;
	SHFILEINFO shinfo;

	// Get the handle of the (normal) system imagelist.
	hSmallSystemImageList = (HIMAGELIST)SHGetFileInfo((LPCTSTR)_T("C:\\"), 0, &shinfo, sizeof(shinfo), SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
	m_ImageList.Attach(hSmallSystemImageList);
	::SendMessage(m_FileList.m_hWnd, LVM_SETIMAGELIST, (WPARAM)LVSIL_SMALL, (LPARAM)hSmallSystemImageList);
	::SendMessage(m_ZIPDetail.m_hWnd, LVM_SETIMAGELIST, (WPARAM)LVSIL_SMALL, (LPARAM)hSmallSystemImageList);
	m_ImageList.Detach();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?