Ejemplo n.º 1
0
void CZipCentralDir::RenameFile(WORD uIndex, LPCTSTR lpszNewName)
{
	CZipFileHeader* pHeader = m_headers[uIndex];
	pHeader->SetFileName(lpszNewName);
	if (!m_bConvertAfterOpen)
		ZipCompatibility::FileNameUpdate(*pHeader, false);
	if (m_bFindFastEnabled)
		BuildFindFastArray(m_bCaseSensitive);
}
Ejemplo n.º 2
0
//////////////////////////////////////////////////////////////////////////
//
// 번역기를 사용하여 스크립트 전체를 번역한다.
//
//////////////////////////////////////////////////////////////////////////
BOOL CKAGScriptMgr::SaveToZip(LPCTSTR strFileName, LPCWSTR cwszScript)
{
	BOOL bRetVal = FALSE;

	if(strFileName && cwszScript)
	{		
		// 파일로 저장될 내용 생성
		size_t len = wcslen(cwszScript);
		wchar_t* buf = new wchar_t[len + 1];
		buf[0] = 0xFEFF;
		memcpy(&buf[1], cwszScript, len*sizeof(wchar_t));

		// 기존 ZIP 파일 삭제
		ZIP_INDEX_TYPE zip_idx = m_zip.FindFile(strFileName, CZipArchive::ffNoCaseSens);
		if( ZIP_FILE_INDEX_NOT_FOUND != zip_idx )
		{
			m_zip.RemoveFile(zip_idx);
		}

		// ZIP 파일에 추가
		CZipFileHeader templ;
		templ.SetFileName(strFileName);
		m_zip.SetFileHeaderAttr(templ, 0);
		
		// 아카이브에 새 레코드를 생성한다.
		if( m_zip.OpenNewFile(templ, CZipCompressor::levelFastest) )
		{
			// 데이터 압축 쓰기
			if( m_zip.WriteNewFile(buf, (len+1)*sizeof(wchar_t)) )
			{
				bRetVal = TRUE;
			}

			// 새 레코드 닫기
			m_zip.CloseNewFile();

		}
		
		// 퍼버 해제
		delete [] buf;
	}

	return bRetVal;
}
Ejemplo n.º 3
0
void CZipCentralDir::WriteHeaders(CZipActionCallback* pCallback, bool bOneDisk)
{
	m_info.m_uDiskEntriesNo = 0;
	m_info.m_uDiskWithCD = (WORD)m_pStorage->GetCurrentDisk();
	m_info.m_uOffset = m_pStorage->GetPosition() - m_info.m_uBytesBeforeZip;
	if (!m_info.m_uEntriesNumber)
		return;

	WORD iDisk = m_info.m_uDiskWithCD;
	int iStep = 0; // for the compiler

	if (pCallback)
	{
		pCallback->Init();
		pCallback->SetTotal(m_info.m_uEntriesNumber);
		iStep = CZipActionCallback::m_iStep;// we don't want to wait forever
	}

	int iAborted = 0;
	for (int i = 0; i < m_info.m_uEntriesNumber; i++)
	{
		CZipFileHeader* pHeader = (*this)[i];
		

		CZipString szRemember;
		if (m_bConvertAfterOpen)
			// if CZipArchive::Flush is called we will be still using the archive, so restore changed name
			szRemember = pHeader->GetFileName();

		ConvertFileName(false, true, pHeader);
		m_info.m_uSize += pHeader->Write(m_pStorage);

		if (m_bConvertAfterOpen)
			pHeader->SetFileName(szRemember);

		if (m_pStorage->GetCurrentDisk() != iDisk)
		{
			m_info.m_uDiskEntriesNo = 1;
			iDisk = (WORD)m_pStorage->GetCurrentDisk();
			// update the information about the offset and starting disk if the 
			// first header was written on the new disk
			if (i == 0)
			{
				m_info.m_uOffset = 0;
				m_info.m_uDiskWithCD = iDisk;
			}
		}
		else 
			m_info.m_uDiskEntriesNo++;
		if (pCallback && !(i%iStep))
			if (!pCallback->Callback(iStep))
			{
				
				if (bOneDisk) 
				{
					if (!m_pStorage->IsSpanMode())
						m_pStorage->EmptyWriteBuffer();
					else
						m_pStorage->Flush(); // must be flush before - flush was not called in span mode
					
					// remove saved part from the disk
					m_pStorage->m_pFile->SetLength(m_info.m_uBytesBeforeZip + m_info.m_uOffset);
//	 				We can now abort safely
					iAborted = CZipException::abortedSafely;
				}
				else
					iAborted = CZipException::abortedAction;
				break;
			}
	}

	if (pCallback)
		pCallback->CallbackEnd();

	if (iAborted)
		ThrowError(iAborted);
}