예제 #1
0
	bool CheckOrder(const CZipString& sz1, const CZipString& sz2, 
		int iSep1, int iSep2, bool bCheckTheBeginning = false) const
	{
		if (iSep1)
		{
			if (iSep2)
			{
				if (iSep1 == iSep2)
					return (sz1.*pZipComp)(sz2) < 0;

				if (bCheckTheBeginning)
				{

					int is = sz1.GetLength() > sz2.GetLength() ? sz2.GetLength() : sz1.GetLength();
					int iSeparators = 0;
					// find the common path beginning
					int iLastSepPos = -1;
					for (int i = 0; i < is; i++)
					{
						CZipString sz = sz2.Mid(i, 1);
						if ((sz1.Mid(i, 1).*pZipComp)(sz) != 0) // must be Mid 'cos of case sens. here
							break;
						else if (CZipPathComponent::IsSeparator(sz[0]))
						{
							iLastSepPos = i;
							iSeparators++;
						}
					}
					
					// if necessary remove the common path beginning and check again
					if (iLastSepPos != -1)
						return CheckOrder(sz1.Mid(iLastSepPos), sz2.Mid(iLastSepPos), iSep1 - iSeparators, iSep2 - iSeparators);
							
				}
				return (sz1.*pZipComp)(sz2) < 0;		
			} 
			else
				return false;
		}
		else
			if (iSep2)
				return true;
			else
				return (sz1.*pZipComp)(sz2) < 0;
	}
예제 #2
0
ZIPINLINE  bool ZipPlatform::RemoveFile(LPCTSTR lpszFileName, bool bThrow, int iMode)
{
	if ((iMode & ZipPlatform::dfmRemoveReadOnly) != 0)
	{
		DWORD attr;
		if (ZipPlatform::GetFileAttr(lpszFileName, attr)
			&& (ZipCompatibility::GetAsInternalAttributes(attr, ZipPlatform::GetSystemID()) & ZipCompatibility::attROnly) != 0)
		{
			ZipPlatform::SetFileAttr(lpszFileName, ZipPlatform::GetDefaultAttributes());
		}
	}
#ifdef SHFileOperation
	if ((iMode & ZipPlatform::dfmRecycleBin) == 0)
	{
#endif
		if (::DeleteFile((LPTSTR)(LPCTSTR)CZipPathComponent::AddPrefix(lpszFileName, false)))		
			return true;
#ifdef SHFileOperation
	}
	else
	{
		CZipString file = lpszFileName;
#if defined _UNICODE && _MSC_VER >= 1400
		if (file.GetLength() >= MAX_PATH)
		{
			// cannot prefix for SHFileOperation, use short path
			CZipString temp = CZipPathComponent::AddPrefix(lpszFileName, false);
			DWORD size = ::GetShortPathName(temp, NULL, 0);
			if (size != 0)
			{
				size = ::GetShortPathName(temp, file.GetBuffer(size), size);
				file.ReleaseBuffer();
			}			
			if (size == 0)
			{
				if (bThrow)
					CZipException::Throw(CZipException::notRemoved, lpszFileName);
				return false;
			}			
			// GetShortPathName keeps the prefix - remove it
			int prefixLength = CZipPathComponent::IsPrefixed(file);
			if (prefixLength > 0)
			{
				file = file.Mid(prefixLength);
			}
		}
#endif
		int length = file.GetLength();
		CZipAutoBuffer buffer((length + 2) * sizeof(TCHAR), true); // double NULL is required
		memcpy(buffer, (LPCTSTR)file, length * sizeof(TCHAR));
		SHFILEOPSTRUCT shFileOp = {0};
		shFileOp.wFunc = FO_DELETE;
		shFileOp.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI; 
		shFileOp.pFrom = (LPCTSTR)(char*)buffer;
		if (SHFileOperation(&shFileOp) == 0 && !shFileOp.fAnyOperationsAborted)
			return true;
	}
#endif
	if (bThrow)
		CZipException::Throw(CZipException::notRemoved, lpszFileName);
	return false;		
}