Exemplo n.º 1
0
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;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
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;


}