Beispiel #1
0
int WINAPI ZipFile(const char *pszPath,const char *pszZipFile)
{
	try
	{
		CZipArchive zip;//压缩

		CString strZip,strPath;

		strZip.Format("%s",pszZipFile);
		strPath.Format("%s",pszPath);

		zip.Open(strZip, CZipArchive::create, 0  );
		if(zip.AddNewFile(pszPath, 8) == FALSE)
		{
			zip.Close();
			return 0;
		}
		zip.Close();

	}
	catch(...)
	{
		return 0;
	}
	return 1;
}
Beispiel #2
0
bool CSimpleZip::Add( const void* src, const unsigned int& srcSize, void* dst, unsigned int& dstSize, std::string& szErrmsg)
{
	if ( NULL==src )
	{
		szErrmsg =  "CSimpleZip: Invalid source.";
		return false;
	}

	bool bRet = false;
	CZipMemFile mfIn;
	CZipMemFile mfOut;
	CZipArchive zip;
	try
	{
		mfIn.Write(src, srcSize);
		zip.Open(mfOut, CZipArchive::zipCreate);
		zip.AddNewFile(mfIn, _T("temp.txt"));
		zip.Close();
		int nLen = (int)mfOut.GetLength();
		if ( NULL==dst || dstSize<nLen )
		{
			dstSize = nLen;
			szErrmsg = "CSimpleZip: The size of destination buffer is too small.";
			return false;
		}
		BYTE* b = mfOut.Detach();
		memcpy_s(dst, dstSize, b, nLen);
		dstSize = nLen;
		free(b);
		bRet = true;
	}
	catch(CZipException& e)
	{
		if (!zip.IsClosed())
			zip.Close();
		szErrmsg =  e.GetErrorDescription().c_str();
	}
	catch(...)
	{
		if (!zip.IsClosed())
			zip.Close();
		szErrmsg =  "CSimpleZip: failed to add, catch exception.";
	}
	return bRet;
}
Beispiel #3
0
void WorkerThread::runRezip() {
	emit(beginRunRezip());
	emit(stageEvent("Finding and saving modified game data"));
	
	emit(infoEvent("Identifying modified files (including previously modified files)"));
	QMap<QString, uint32_t> newChecksums;
	collectFiles(m_tempPath, &newChecksums);
	QStringList modified; // TODO: also determine removed files?
	QMapIterator<QString, uint32_t> i(newChecksums);
	while (i.hasNext()) {
		i.next();
		if(!m_checksums.contains(i.key()) || m_checksums[i.key()] != i.value()) { modified << i.key(); }
	}
	
	if(modified.empty()) {
		emit(infoEvent("No modified files found"));
		return;
	}
	
	emit(infoEvent("Rezipping modified files"));

	QString gameFileBase = QFileInfo(m_gameFileName).baseName();
	QString diffFileName = m_dataPath + "/" + gameFileBase + __WHDRun__DiffSuffix;
	CZipArchive zip;
	try {
		zip.Open(diffFileName.toUtf8(), CZipArchive::zipCreate);

		// TODO: review that path finding stuff some time.
		QDir tempDir(m_tempPath); tempDir.makeAbsolute();
		foreach(QString externalPath, modified) {
			QDir externalDir(externalPath); externalDir.makeAbsolute();
			QString internalPath = tempDir.relativeFilePath(externalDir.absolutePath());
			zip.AddNewFile((LPCTSTR)externalPath.toUtf8(),
				(LPCTSTR)internalPath.toUtf8(), CZipCompressor::levelBest);
		}

		zip.Close();
	} catch(CZipException ex) {
DWORD WINAPI zipCompress(LPVOID lpParam){
	_filename = COMPRESS_PREPARING;
	sTime = time(NULL);

	CZipArchive zip;
	vector<__int64>filesize;
	_size_all = 1;

	/*char b[123];
	sprintf(b, "%d", spanSize);
	MessageBox(0, b, "", 0);*/
	
	if(spanSize == 0)
		zip.Open(archive_name, CZipArchive::OpenMode::zipCreate);
	else
		zip.Open(archive_name, CZipArchive::OpenMode::zipCreateSpan, spanSize);
	zip.SetPassword(passwd);
	//zip.SetAutoFlush();
	
	_filename = COMPRESS_GETTING_FILE_SIZES;
	for (int i=0; i<int(filename.size()); ++i) {
      FILE* f=fopen(filename[i].c_str(), "rb");
      if(f){
		_fseeki64(f, 0LL, SEEK_END);
		filesize.push_back(_ftelli64(f));
        _size_all += _ftelli64(f);
        fclose(f);
      }
    }

	for(int i=0;i<filename.size();i++){
		_filename = filename[i];
		//zip.AddNewFile(filename[i].c_str(), MEM);
		zip.AddNewFile(filename[i].c_str(), filename[i].c_str(), MEM);
		_done_all += filesize[i];
		
		CZipFileHeader fhInfo;
		zip.GetFileInfo(fhInfo, i);
		_compressed += fhInfo.GetEffComprSize() + fhInfo.GetSize() + fhInfo.GetExtraFieldSize();
		
	}
	zip.Close();

	/*FILE *f = fopen(archive_name, "rb");
	if(f){
		_fseeki64(f, 0LL, SEEK_END);
		_compressed = _ftelli64(f);
		fclose(f);
	}*/

	if(sfx_arch){ //do³¹czamy modu³ sfx
		_filename = COMPRESS_ADDING_SFX_MOD;
		
		/*archive_name[strlen(archive_name)-3] = '\0';
		sprintf(archive_name, "%sexe", archive_name);*/

		//odczytujemy œcie¿kê do modu³u
		HANDLE hProc = GetCurrentProcess();
		HMODULE hMod;
        DWORD cbNeeded;
		char processName[MAX_PATH];

        EnumProcessModules(hProc, &hMod, sizeof(hMod), &cbNeeded);
        GetModuleFileNameEx(hProc, hMod, processName, MAX_PATH);
        
		for(int i=strlen(processName)-1;i>=0;i--){
			if(processName[i] == '\\' || processName[i] == '/'){
				processName[i+1] = '\0';
				sprintf(processName, "%skgb_arch_sfx_zip.mod", processName);
				break;
			}
		}

		FILE *sfx = fopen(processName, "rb");

		//MessageBox(0, "", "", 0);
		if(sfx == NULL){
			MessageBox(0, "An internal error has occured, please reinstall KGB Archiver!", "KGB Archiver", 0);
			_fcloseall();
			DeleteFile(archive_name);
			return false;
		}

		//MessageBox(0, archive_name, "", 0);

		FILE *archive = fopen(archive_name, "rb");
		if(archive == NULL){
			_fcloseall();
			return false;
		}
		//MessageBox(0, "", "", 0);

		archive_name[strlen(archive_name)-3] = '\0';
		sprintf(archive_name, "%sexe", archive_name);

		//MessageBox(0, archive_name, "", 0);

		FILE *archive_sfx = fopen(archive_name, "wb");
		if(archive_sfx == NULL){
			_fcloseall();
			return false;
		}

		//MessageBox(0, "2", "", 0);

		int count=0;
		char buffer[65536];
		while(!feof(sfx)){
			count = fread(buffer, sizeof(char), sizeof(buffer), sfx);
			fwrite(buffer, sizeof(char), count, archive_sfx);
		}
		while(!feof(archive)){
			count = fread(buffer, sizeof(char), sizeof(buffer), archive);
			fwrite(buffer, sizeof(char), count, archive_sfx);
		}
		fclose(archive);
		fclose(sfx);
		fclose(archive_sfx);

		archive_name[strlen(archive_name)-3] = '\0';
		sprintf(archive_name, "%szip", archive_name);
		DeleteFile(archive_name);
	}

	_done_all++;

	return true;
}
Beispiel #5
0
UINT CScormEngine::CreatePackage(HWND hWndParent)
{
   // Reset progress (should be zero anyway)
   m_dwProgress = 0;
   m_dwCurrentFile = 0;
   m_bCancelRequested = false;

   // Create a temporary directory
   _TCHAR tszPath[MAX_PATH];
   _TCHAR tszDirectory[MAX_PATH];
   bool success = LIo::CreateTempDir(_T("SCO"), tszPath, tszDirectory);

   if (success)
   {
      m_csBaseTempPath = tszPath;
      m_csRelTempPath = tszDirectory;
      m_csTargetDir = m_csBaseTempPath + m_csRelTempPath + CString(_T("\\"));
   }

   //MessageBox(hWndParent, tszDirectory, tszPath, MB_OK | MB_ICONINFORMATION);

   if (success)
      DefineScormKeywords();

   CString csImsManifest;
   if (success)
      success = LoadXmlResource(csImsManifest, IDR_XML_IMSMANIFEST);

   if (success && !m_bCancelRequested)
   {
      // Let's write the imsmanifest File.
      LTextBuffer tbImsManifest(csImsManifest);
      int nKwCount = m_aGeneralKeywords.GetSize();
      for (int i=0; i<nKwCount; ++i)
         tbImsManifest.ReplaceAll(m_aGeneralKeywords[i], m_aGeneralValues[i]);

      success = tbImsManifest.SaveFile(m_csTargetDir + _T("imsmanifest.xml"), 
         LFILE_TYPE_TEXT_UTF8, false); // Do not write a UTF8 BOM.
   }

/*   CString csScoMetadata;
   if (success)
      success = LoadXmlResource(csScoMetadata, IDR_XML_SCOMETADATA);

   if (success && !m_bCancelRequested)
   {
      // And now the scometadata.xml file.
      LTextBuffer tbScoMetadata(csScoMetadata);
      int nKwCount = m_aGeneralKeywords.GetSize();
      for (int i=0; i<nKwCount; ++i)
         tbScoMetadata.ReplaceAll(m_aGeneralKeywords[i], m_aGeneralValues[i]);

      success = tbScoMetadata.SaveFile(m_csTargetDir + _T("scometadata.xml"),
         LFILE_TYPE_TEXT_UTF8, false); // No UTF8 BOM, thank you.
   }*/

   if (success && !m_bCancelRequested)
   {
      CZipArchive zip;
      CScormZipCallback zipCallback(this);
      zip.SetCallback(&zipCallback);
      zip.Open(m_csTargetDir + m_csTargetFile + _T(".zip"), CZipArchive::zipCreate);
      zip.AddNewFile(m_csTargetDir + _T("imsmanifest.xml"), _T("imsmanifest.xml"));
//      zip.AddNewFile(m_csTargetDir + _T("scometadata.xml"), _T("scometadata.xml"));
      zip.AddNewFile(m_csRealIndexFileName, m_csIndexFileName);
      int nFileCount = m_aSourceFiles.GetSize();
      for (int i=0; i<nFileCount; ++i)
         zip.AddNewFile(m_aSourceFiles[i], m_aTargetFiles[i]);
      zip.Close();
   }

   if (m_bCancelRequested)
      return ERROR_CANCELLED;

   return success ? S_OK : E_FAIL;
}
/**
	@brief	

	@author BHK	

	@date 2009-04-28 오전 11:10:50	

	@param	

	@return		
*/
void CSaveProductToRevisionDlg::OnBnClickedOk()
{
	char* pData = NULL;

	CELoadDocData& docData = CELoadDocData::GetInstance();
	
	InsertLoadItemInCableSizingResultDoc();

	const string rMDBFilePath = docData.GetProjectMDBFilePath();

	CADODB adoDB;
	const STRING_T rConnectionString = STRING_T(PROVIDER) + _T("Data Source=") + rMDBFilePath + DB_PASSWORD;
	if(TRUE == adoDB.DBConnect(rConnectionString))
	{
		CString strDesc;
		GetDlgItemText(IDC_EDIT_DESC , strDesc);

		CString strZipFilePath;
		map<CString , CString > ZipFilePathMap;
		if((_T("LOAD SUMMARY-BUS") == m_rProductName) || (_T("LOAD SUMMARY-SUBBUS") == m_rProductName))
		{
			strZipFilePath = string(docData.GetProjectFolderPath() + _T("Load Summary Result\\BUS_LoadSummary.zip")).c_str();
			ZipFilePathMap.insert(make_pair(_T("Load Summary-BUS") , strZipFilePath));
			strZipFilePath = string(docData.GetProjectFolderPath() + _T("Load Summary Result\\SubBUS_LoadSummary.zip")).c_str();
			ZipFilePathMap.insert(make_pair(_T("Load Summary-SubBUS") , strZipFilePath));
		}
		else if(_T("TRANSFORMER SIZING") == m_rProductName)
		{
			CTransformerSizingResultDoc::SaveTransformerSizingResultData();

			CZipArchive zip;
			CString strProjectPath = docData.GetProjectFolderPath().c_str();
			strZipFilePath = strProjectPath + _T("Transformer Sizing\\Transformer Sizing.zip");
			{
				if(!strZipFilePath.IsEmpty())
				{
					zip.Open(strZipFilePath , CZipArchive::create );
					zip.AddNewFile(strProjectPath + _T("Transformer Sizing\\Transformer Sizing.txt") , -1 , false);
					zip.Close();
				}
			}
			ZipFilePathMap.insert(make_pair(m_rProductName , strZipFilePath));
		}
		else if(_T("AUTO POWER CABLE") == m_rProductName)
		{
			CZipArchive zip;
			CString strProjectPath = docData.GetProjectFolderPath().c_str();
			strZipFilePath = strProjectPath + _T("Cable Sizing Result\\Cable Sizing Result.zip");
			{
				if(!strZipFilePath.IsEmpty())
				{
					zip.Open(strZipFilePath , CZipArchive::create );
					CString strDir = strProjectPath + CString(_T("Cable Sizing Result\\*.BUS"));
					CFileFind file;

					vector<string> rInterestingFileEntry;
					///! 확장자가 *.BUS 파일을 찾는다.
					BOOL bFound = file.FindFile(strDir);
					if(bFound)
					{
						while(bFound)
						{
							bFound = file.FindNextFile();
							if(file.IsDots()) continue;

							const CString rFileName = file.GetFileTitle().MakeUpper();
							zip.AddNewFile(strProjectPath + CString(_T("Cable Sizing Result\\")) + rFileName + _T(".BUS") , -1 , false);
						}
					}
					zip.Close();
				}
			}
			ZipFilePathMap.insert(make_pair(m_rProductName , strZipFilePath));
		}
		else if(_T("AUTO CONTROL CABLE") == m_rProductName)
		{
			CZipArchive zip;
			CString strProjectPath = docData.GetProjectFolderPath().c_str();
			strZipFilePath = strProjectPath + _T("Control Cable Result\\Control Cable Result.zip");
			{
				if(!strZipFilePath.IsEmpty())
				{
					zip.Open(strZipFilePath , CZipArchive::create );
					CString strDir = strProjectPath + CString(_T("Control Cable Result\\*.BUS"));
					CFileFind file;

					vector<string> rInterestingFileEntry;
					///! 확장자가 *.BUS 파일을 찾는다.
					BOOL bFound = file.FindFile(strDir);
					if(bFound)
					{
						while(bFound)
						{
							bFound = file.FindNextFile();
							if(file.IsDots()) continue;

							const CString rFileName = file.GetFileTitle().MakeUpper();
							zip.AddNewFile(strProjectPath + CString(_T("Control Cable Result\\")) + rFileName + _T(".BUS") , -1 , false);
						}
					}
					zip.Close();
				}
			}
			ZipFilePathMap.insert(make_pair(m_rProductName , strZipFilePath));
		}
		else if(_T("CABLE SIZING TABLE") == m_rProductName)
		{
			CZipArchive zip;
			CString strProjectPath = docData.GetProjectFolderPath().c_str();
			strZipFilePath = strProjectPath + _T("Cable Sizing Table\\Cable Sizing Table.zip");
			{
				if(!strZipFilePath.IsEmpty())
				{
					zip.Open(strZipFilePath , CZipArchive::create );
					
					CString strDir = strProjectPath + CString(_T("Cable Sizing Table\\*.TXT"));
					CFileFind file;

					vector<string> rInterestingFileEntry;
					///! 확장자가 *.TXT 파일을 찾는다.
					BOOL bFound = file.FindFile(strDir);
					if(bFound)
					{
						while(bFound)
						{
							bFound = file.FindNextFile();
							if(file.IsDots()) continue;

							const CString rFileName = file.GetFileTitle().MakeUpper();
							zip.AddNewFile(strProjectPath + CString(_T("Cable Sizing Table\\")) + rFileName + _T(".TXT") , -1 , false);
						}
					}

					zip.Close();
				}
			}
			ZipFilePathMap.insert(make_pair(m_rProductName , strZipFilePath));
		}
		else if((_T("CABLE SCHEDULE") == m_rProductName) || (_T("DRUM SCHEDULE") == m_rProductName))
		{
			CZipArchive zip;
			CString strProjectPath = docData.GetProjectFolderPath().c_str() , rKeyString;
			if(_T("Cable Schedule") == m_rProductName)
				rKeyString = _T("Cable Schedule Result");
			else	rKeyString = _T("Drum Schedule Result");
			strZipFilePath = strProjectPath + rKeyString + _T("\\") + rKeyString + _T(".zip");
			{
				if(!strZipFilePath.IsEmpty())
				{
					zip.Open(strZipFilePath , CZipArchive::create );
					
					CString strDir = strProjectPath + rKeyString + CString(_T("\\*.TXT"));
					CFileFind file;

					vector<string> rInterestingFileEntry;
					///! 확장자가 *.TXT 파일을 찾는다.
					BOOL bFound = file.FindFile(strDir);
					if(bFound)
					{
						while(bFound)
						{
							bFound = file.FindNextFile();
							if(file.IsDots()) continue;

							const CString rFileName = file.GetFileTitle().MakeUpper();
							zip.AddNewFile(strProjectPath + rKeyString + CString(_T("\\")) + rFileName + _T(".TXT") , -1 , false);
						}
					}

					zip.Close();
				}
			}
			ZipFilePathMap.insert(make_pair(m_rProductName , strZipFilePath));
		}

		if(!ZipFilePathMap.empty())
		{
			++m_nLastRevNo;
			for(map<CString , CString>::iterator itr = ZipFilePathMap.begin();itr != ZipFilePathMap.end();++itr)
			{
				CString strFormat = _T("INSERT INTO T_PRODUCT_REVISION(C_PRODUCT_NAME,C_REVISION_NO,C_DATE,C_DESC) VALUES('%s',%d,'%s','%s')");
				CString strSQL;

				CTime CurTime = CTime::GetCurrentTime();
				CString strTimeData = CurTime.Format(_T("%Y년 %m월 %d일 - %H시 %M분"));

				strSQL.Format(strFormat , itr->first , m_nLastRevNo , strTimeData , strDesc);
				adoDB.ExecuteQuery(strSQL.operator LPCTSTR());

				strSQL = _T("SELECT * FROM T_PRODUCT_REVISION WHERE C_PRODUCT_NAME = '") + itr->first + _T("' ORDER BY C_REVISION_NO DESC");
				adoDB.OpenQuery(strSQL.operator LPCTSTR());
				LONG lRecordCount = 0L;
				adoDB.GetRecordCount(&lRecordCount);

				CFile f(itr->second , CFile::modeRead);
				ULONGLONG fSize = f.GetLength();
				if(NULL == pData) pData = (char*)calloc(1 , sizeof(char)*fSize);
				if(pData)
				{
					f.Read(pData,fSize);
					const int nFieldCount = adoDB.GetFieldCount();
					for(int i = 0;i < nFieldCount;++i)
					{
						if(_T("C_DATA") == adoDB.GetFieldName(i))
						{
							adoDB.AppendChunk(0 , i , pData , fSize);
							break;
						}
					}
					free((void*)pData);
					pData = NULL;
				}
			}
		}
	}
	else
	{
		AfxMessageBox(_T("Fail to connect database"));
	}
	
	OnOK();
}
Beispiel #7
0
bool CSimpleZip::Add(std::string strZipFile,std::list<std::string>& lstFile,std::string strRootPath,bool bFullPath)
{
	CZipArchive zip;

	
	CZipString szArchive;
	int iVolumeSize = 0;
	int iMode = CZipArchive::zipOpen;
	
	szArchive =CZipString(strZipFile);
	if (!ZipPlatform::FileExists(szArchive))
					iMode = CZipArchive::zipCreate;


	CZipPathComponent zpc(szArchive);
	SpanCallback span;
	zip.SetSpanCallback(&span);
	try
	{
		zip.Open(szArchive, iMode, iVolumeSize);
	}
	catch(...)
	{
		return FALSE;
	}
	zip.SetRootPath(strRootPath.c_str());

	FILELIST lFiles;
	
	for(std::list<std::string>::iterator it =lstFile.begin();it!=lstFile.end();it++)
	{
		std::string strFileName;
		strFileName =*it;
		lFiles.push_back(CZipString(strFileName));
	}
	FILELISTADD rev;
	for (FILELISTIT it = lFiles.begin(); it != lFiles.end(); ++it)				
	{
		CZipString sz = zip.PredictFileNameInZip(*it, bFullPath);
		if (!sz.IsEmpty())
			rev.push_back(CZipAddFileInfo(*it, sz));
	}
	lFiles.clear();
//	rev.sort(std::greater<CZipAddFileInfo>());
	FILELISTADDIT it1;
	int iSmartLevel = CZipArchive::zipsmSafeSmart;


	for (it1 = rev.begin(); it1 != rev.end(); ++it1)
	{	
		if (zip.AddNewFile((*it1).m_szFilePath, 5, bFullPath, iSmartLevel))
		{
			
			printf ("%s added\n", (LPCTSTR)(*it1).m_szFileNameInZip);
		}
		else
			printf ("%s not added\n", (LPCTSTR)(*it1).m_szFilePath);
	}

	zip.Close();
	return TRUE;
}
Beispiel #8
0
int hb_CmpTdSpanStd( char * szFile, char * szFiletoCompress, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, char * szPassWord, int iSpanSize, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress )
{
   DWORD                dwSize;
   BOOL                 bAdded      = FALSE;
   BOOL                 bReturn     = TRUE;
   BOOL                 bFileExist  = hb_fsFile( szFile );

   CZipArchive          szZip;
   SpanCallbackc        span;
   SpanActionCallbackc  spanac;

   szZip.SetSpanCallback( &span );


   if( iSpanSize == 0 )
   {
      iSpanSize = 1457664;
   }

   try
   {
      if( ( bFileExist && bOverWrite ) || ! bFileExist )
      {
         szZip.Open( szFile, CZipArchive::zipCreateSpan, iSpanSize );
      }
      else
      {
         return ( int ) false;
      }
   }

   catch( CZipException )
   {
      bReturn = FALSE;
   }

   catch( ... )
   {
   }

   if( szPassWord != NULL )
   {
      szZip.SetPassword( szPassWord );
   }

   if( pZipI.szComment != NULL )
   {
      szZip.SetGlobalComment( pZipI.szComment );
      hb_xfree( pZipI.szComment );
   }

   if( HB_IS_BLOCK( pProgress ) )
   {
      pProgressInfo = pProgress;
      szZip.SetCallback( &spanac );
   }
   if( bReturn )
   {
      try
      {
         if( szPassWord != NULL )
         {
            szZip.SetPassword( szPassWord );
         }

         dwSize = GetCurrentFileSize( szFiletoCompress );

         if( pBlock != NULL )
         {
            PHB_ITEM FileName = hb_itemPutC( NULL, szFiletoCompress  );

            hb_vmEvalBlockV(  pBlock, 1, FileName );

            hb_itemRelease( FileName );

         }

         #if defined( __WIN32__ ) || defined( __MINGW32__ )
         if( bDrive && ! bAdded )
         {
            if( ! szZip.AddNewFileDrv( szFiletoCompress, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 ) )
            {
               bReturn = FALSE;
            }
            else
            {
               bAdded = TRUE;
            }
         }
         #endif

         if( bPath && ! bAdded )
         {
            if( ! szZip.AddNewFile( szFiletoCompress, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 ) )
            {
               bReturn = FALSE;
            }
            else
            {
               bAdded = TRUE;
            }
         }
         else if( ! bDrive && ! bPath && ! bAdded )
         {
            if( ! szZip.AddNewFile( szFiletoCompress, iCompLevel, false, CZipArchive::zipsmSafeSmart, 65536 ) )
            {
               bReturn = FALSE;
            }
         }

      }
      catch( ... )
      {
      }
   }

   try
   {
      szZip.Close();
   }

   catch( CZipException )
   {
      bReturn = FALSE;
   }

   catch( ... )
   {
   }
   if( pProgressInfo )
   {
      hb_itemRelease( pProgressInfo );
   }

   return ( int ) bReturn;
}
Beispiel #9
0
int hb_CmpTdSpan( const char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, const char * szPassWord, int iSpanSize, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress )
{
   ULONG                ulCount     = 0;
   const char *         szDummy;
   DWORD                dwSize;
   BOOL                 bAdded      = FALSE;
   BOOL                 bReturn     = TRUE;
   BOOL                 bFileExist  = hb_fsFile( szFile );

   CZipArchive          szZip;
   SpanCallbackc        span;
   SpanActionCallbackc  spanac;

   szZip.SetSpanCallback( &span );


   if( iSpanSize == 0 )
   {
      iSpanSize = 1457664;
   }

   try
   {
      if( ( bFileExist && bOverWrite ) || ! bFileExist )
      {
         szZip.Open( szFile, CZipArchive::zipCreateSpan, iSpanSize );
      }
      else
      {
         bReturn = FALSE;
         return ( int ) bReturn;
      }
   }

   catch( CZipException )
   {
      bReturn = FALSE;
   }

   catch( ... )
   {
   }

   //if (! bReturn )
   //{

   if( szPassWord != NULL )
   {
      szZip.SetPassword( szPassWord );
   }

   if( pZipI.szComment != NULL )
   {
      szZip.SetGlobalComment( pZipI.szComment );
      hb_xfree( pZipI.szComment );
   }

   if( HB_IS_BLOCK( pProgress ) )
   {
      pProgressInfo = pProgress;
      szZip.SetCallback( &spanac );
   }

   for( ulCount = 1; ( ulCount <= hb_arrayLen( pArray ) ); ulCount++ )
   {
      szDummy  = ( char * ) hb_arrayGetCPtr( pArray, ulCount );
      dwSize   = GetCurrentFileSize( szDummy );

      bAdded   = FALSE;

      if( dwSize != ( DWORD ) -1 )
      {
         if( pBlock != NULL )
         {
            PHB_ITEM FileName = hb_itemPutC( NULL, hb_arrayGetCPtr( pArray, ulCount ) ), FilePos = hb_itemPutNI( NULL, ulCount );

            hb_vmEvalBlockV( pBlock, 2, FileName, FilePos );

            hb_itemRelease( FileName );
            hb_itemRelease( FilePos );
         }

         try
         {

            if( bPath && ! bAdded )
            {
               szZip.AddNewFile( szDummy, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 );
               bAdded = TRUE;
            }
            else if( ! bDrive && ! bPath && ! bAdded )
            {
               szZip.AddNewFile( szDummy, iCompLevel, false, CZipArchive::zipsmSafeSmart, 65536 );
            }

         }
         catch( ... )
         {
         }
      }
   }
   //}

   try
   {
      szZip.Close();
   }

   catch( CZipException )
   {
      bReturn = FALSE;
   }

   catch( ... )
   {
   }


   return ( int ) bReturn;
}
Beispiel #10
0
int hb_CompressFile( const char * szFile, PHB_ITEM pArray, int iCompLevel, PHB_ITEM pBlock, BOOL bOverWrite, const char * szPassWord, BOOL bPath, BOOL bDrive, PHB_ITEM pProgress )
{
   ULONG                ulCount        = 0;
   const char *         szDummy;
   char *               szDummyLower   = NULL;
   char *               szFileLower    = hb_strdup( ( char * ) szFile );
   BOOL                 bFileExist     = hb_fsFile( szFile );
   BOOL                 bAdded         = FALSE;
   BOOL                 bReturn        = TRUE;
   DWORD                dwSize;

   CZipArchive          szZip;
   SpanCallbackc        span;
   SpanActionCallbackc  spanac;

   szZip.SetSpanCallback( &span );

   #ifdef HB_OS_WIN_32
   hb_strLower( szFileLower, strlen( szFileLower ) );
   #endif

   try
   {
      if( ( bFileExist && bOverWrite ) || ! bFileExist )
      {
         szZip.Open( szFile, CZipArchive::zipCreate, 0 );
      }
      else
      {
         szZip.Open( szFile, CZipArchive::zipOpen, 0 );
      }
   }

   catch( CZipException )
   {
      bReturn = FALSE;
   }

   catch( ... )
   {
   }

   if( bReturn )
   {

      if( szPassWord != NULL )
      {
         szZip.SetPassword( szPassWord );
      }

      if( pZipI.szComment != NULL )
      {
         szZip.SetGlobalComment( pZipI.szComment );
         hb_xfree( pZipI.szComment );
      }

      if( HB_IS_BLOCK( pProgress ) )
      {
         pProgressInfo = pProgress;
         szZip.SetCallback( &spanac );
      }

      for( ulCount = 1; ( ulCount <= hb_arrayLen( pArray ) ); ulCount++ )
      {
         szDummy        = ( char * ) hb_arrayGetCPtr( pArray, ulCount );
         dwSize         = GetCurrentFileSize( szDummy );
         bAdded         = FALSE;

         szDummyLower   = hb_strdup( ( char * ) szDummy );

         #ifdef HB_OS_WIN_32
         hb_strLower( szDummyLower, strlen( szDummyLower ) );
         #endif

// Prevent adding current archive file !
         if( strstr( szFileLower, szDummyLower ) == NULL && strstr( szDummyLower, szFileLower ) == NULL )
         {
            if( dwSize != ( DWORD ) -1 )
            {
               if( pBlock != NULL )
               {
                  PHB_ITEM FileName = hb_itemPutC( NULL, hb_arrayGetCPtr( pArray, ulCount ) ), FilePos = hb_itemPutNI( NULL, ulCount );


                  hb_vmEvalBlockV( pBlock, 2, FileName, FilePos );

                  hb_itemRelease( FileName );
                  hb_itemRelease( FilePos );
               }

               try
               {
                  if( bPath && ! bAdded )
                  {
                     szZip.AddNewFile( szDummy, iCompLevel, true, CZipArchive::zipsmSafeSmart, 65536 );
                     bAdded = TRUE;
                  }
                  else if( ! bDrive && ! bPath && ! bAdded )
                  {
                     szZip.AddNewFile( szDummy, iCompLevel, false, CZipArchive::zipsmSafeSmart, 65536 );
                  }

               }
               catch( ... )
               {
               }
            }
         }
         hb_xfree( szDummyLower );
      }
   }
   hb_xfree( szFileLower );
   try
   {
      szZip.Close();
   }

   catch( CZipException )
   {
      bReturn = FALSE;
   }

   catch( ... )
   {
   }

   return ( int ) bReturn;


}