Ejemplo n.º 1
0
CZipCentralDir::CZipCentralDir()
{
	m_bConvertAfterOpen  = true;
	m_bFindFastEnabled = false;
	m_bCaseSensitive = false;
	m_pCompare = GetCZipStrCompFunc(ZipPlatform::GetSystemCaseSensitivity());
	m_pStorage = NULL;
	m_pOpenedFile = NULL;
	m_iBufferSize = 32768;
	
}
Ejemplo n.º 2
0
void CZipCentralDir::BuildFindFastArray( bool bCaseSensitive )
{
	m_findarray.RemoveAll();
	m_bCaseSensitive = bCaseSensitive;
	m_pCompare = GetCZipStrCompFunc(bCaseSensitive);
	int iCount = m_headers.GetSize();
	if (!m_bConvertAfterOpen)
	{
		for (int i = 0; i < iCount; i++)
		{
			CZipFileHeader fh = *m_headers[i];
			ConvertFileName(true, false, &fh);
			InsertFindFastElement(&fh, i); // this method requires the name to be already converted
		}
	}
	else
		for (int i = 0; i < iCount; i++)
			InsertFindFastElement(m_headers[i], i);
}
Ejemplo n.º 3
0
int CZipCentralDir::FindFile(LPCTSTR lpszFileName, bool bCaseSensitive, bool bSporadically, bool bFileNameOnly)
{
	// this is required for fast finding and is done only once
	if (!m_bConvertAfterOpen)
	{
		TRACE(_T("%s(%i) : Converting all the filenames.\n"),__FILE__,__LINE__);
		ConvertAll();
	}
	if (!m_bFindFastEnabled)
		EnableFindFast(true, bSporadically ? !bCaseSensitive : bCaseSensitive);
	int iResult = -1;
	if (bFileNameOnly)
	{
		//  a non-effective search (treat an array as unsorted)

		// set the proper compare function
		if (bCaseSensitive != m_bCaseSensitive)
			m_pCompare = GetCZipStrCompFunc(bCaseSensitive);

		int iSize = m_findarray.GetSize();
		for (int i = 0; i < iSize; i++)
		{
			CZipString sz = GetProperHeaderFileName(m_findarray[i].m_pHeader);
			CZipPathComponent::RemoveSeparators(sz); // to find a dir
			CZipPathComponent zpc(sz);
			sz = zpc.GetFileName();
			if ((sz.*m_pCompare)(lpszFileName) == 0)
			{
				iResult = i;
				break;
			}
		}

		// restore the compare function
		if (bCaseSensitive != m_bCaseSensitive)
			m_pCompare = GetCZipStrCompFunc(!bCaseSensitive);
	}
	else if (bCaseSensitive == m_bCaseSensitive)
		iResult = FindFileNameIndex(lpszFileName);
	else
	{
		if (bSporadically)
		{
			//  a non-effective search (treat an array as unsorted)

			m_pCompare = GetCZipStrCompFunc(bCaseSensitive);			
			int iSize = m_findarray.GetSize();
			for (int i = 0; i < iSize; i++)
				if (CompareElement(lpszFileName, (WORD)i) == 0)
				{
					iResult = i;
					break;
				}
			m_pCompare = GetCZipStrCompFunc(!bCaseSensitive);
		}
		else
		{
			BuildFindFastArray(bCaseSensitive);		
			iResult = FindFileNameIndex(lpszFileName);
		}
	}
	return iResult == -1 ? -1 : m_findarray[iResult].m_uIndex;	
}