⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 zip算法的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			break;

		case EndOfBatch:
			// Reset the progress bar and filename.
			// ZipBuilder1Message( this, 0, "in OnProgress type EndOfBatch" );
			MsgForm->FileBeingZipped->Caption = "";
			MsgForm->ProgressBar1->Position = 1;
			MsgForm->StatusBar1->Panels->Items[0]->Text = "";
			MsgForm->StatusBar1->Panels->Items[1]->Text = "";
			MsgForm->ProgressBar2->Position = 1;
	}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SetZipFName(String aCaption)
{
	ZipFName->Caption = MinimizeName( aCaption, ZipFName->Canvas, ZipFName->Width );
	if ( ZipFName->Caption == "" ) ZipFName->Caption = "<none>";
	if(ZipFName->Canvas->TextWidth(aCaption) > ZipFName->Width)
  {
		ZipFName->Hint = aCaption;
		ZipFName->ShowHint = true;
	} else ZipFName->ShowHint = false;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::WriteBttnClick( TObject *Sender )
{
	static String FirstDir = "";
	String InFile, OutFile;

	ZipOpenDir = FirstDir;
	if(!ZipOpenArchive()) return;
	FirstDir = ZipOpenDir;

	InFile = ZipBuilder1->ZipFilename;
	if(InFile == "") return;

	if(AskDirDialog(MainForm->Handle, OutFile))
  {
		OutFile += ExtractFileName( InFile );
		MsgForm->RichEdit1->Clear();
		MsgForm->Show();
 		ZipBuilder1->WriteSpan( InFile, OutFile );
		MsgForm->Hide();
	}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ReadBttnClick( TObject *Sender )
{
	String InFile, OutPath;

	OpenDialog1->Options << ofHideReadOnly << ofShareAware << ofPathMustExist;
	OpenDialog1->Title      = "Open spanned ZIP archive on last disk";
	OpenDialog1->Filter     = "ZIP Files (*.ZIP)|*.zip";
	OpenDialog1->FileName   = "";
	OpenDialog1->InitialDir = "A:\\";
	OpenDialog1->DefaultExt = "zip";
	if(OpenDialog1->Execute())
  {
		if(AskDirDialog( MainForm->Handle, OutPath))
    {
      OutPath += ExtractFileName( InFile );
			MsgForm->RichEdit1->Clear();
			MsgForm->Show();
			if(!ZipBuilder1->ReadSpan(InFile, OutPath))
      {
				ZipBuilder1->ZipFilename = OutPath;
			  SetZipFName( ZipBuilder1->ZipFilename );
			}
 			MsgForm->Hide();
		}
	}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Showlasterror1Click( TObject *Sender )
{
	if ( ZipBuilder1->ErrCode )
		ShowMessage( IntToStr( ZipBuilder1->ErrCode ) + " " + ZipBuilder1->Message );
	else
		ShowMessage( "No last error present" );
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Exit1Click(TObject *Sender )
{
	Close();
}
//---------------------------------------------------------------------------
bool __fastcall TMainForm::AskDirDialog( const HWND FormHandle, String &DirPath )
{
	BROWSEINFO  bi;
	LPSTR		   lpBuffer;
	ITEMIDLIST *pidl;          // PIDL selected by user
	LPMALLOC    g_pMalloc;
	bool			Result = false;

	// Get the shell's allocator.
	if ( (SHGetMalloc( &g_pMalloc ) )== E_FAIL ) return false;

	// Allocate a buffer to receive browse information.
	if((lpBuffer = (LPSTR)g_pMalloc->Alloc(MAX_PATH)) != 0)
  {
		bi.hwndOwner		= FormHandle;
		bi.pidlRoot			= NULL;
		bi.pszDisplayName	= lpBuffer;
		bi.lpszTitle		= "";
		bi.ulFlags			= 0;
		bi.lpfn				= NULL;
		bi.lParam			= 0;

		// if pidl = 0 then cancel is used.
		if((pidl = SHBrowseForFolder(&bi)) != 0)
    {
			// if 0 then pidl not part of namespace
			if(SHGetPathFromIDList(pidl, lpBuffer))
      {
				DirPath = lpBuffer;
				if ( DirPath[DirPath.Length()] != '\\' ) DirPath += '\\';
				Result  = true;
			}
			// Free the PIDL returned by SHBrowseForFolder.
			g_pMalloc->Free( pidl );
		}
		// Free the string buffer used for the name
		g_pMalloc->Free( lpBuffer );
	}
	// Release the shell's allocator.
	g_pMalloc->Release();
	return Result;
}
//---------------------------------------------------------------------------
/* Folder types are a.o.
 *	CSIDL_DESKTOPDIRECTORY, CSIDL_STARTMENU, CSIDL_SENDTO,
 * CSIDL_PROGRAMS, CSIDL_STARTUP
 */
long __fastcall TMainForm::GetSpecialFolder( int aFolder, String &Location )
{
	long		   FolderErr = 0;   // No error.
	char		  *RealPath;
	ITEMIDLIST *pidl;
	LPMALLOC    g_pMalloc;

	// Get the shell's allocator.
	if(::SHGetMalloc( &g_pMalloc ) == E_FAIL ) return E_FAIL;

	// Allocate a buffer to receive the path information.
	if ( (RealPath = (char *)g_pMalloc->Alloc( MAX_PATH )) != NULL )
  {
		HRESULT hRes = ::SHGetSpecialFolderLocation( Handle, aFolder, &pidl );
		if(hRes == NOERROR)
    {
			bool Success = ::SHGetPathFromIDList( pidl, RealPath );
			if(Success)
      {
				Location = RealPath;
				Location += "\\";
			} else FolderErr = E_UNEXPECTED;
			// Free the PIDL allocated by SHGetSpecialFolderLocation.
			g_pMalloc->Free( pidl );
		}
    else FolderErr = hRes;
		// Free the string buffer used for the name
		g_pMalloc->Free( RealPath );
	}
  else FolderErr = E_OUTOFMEMORY;
	// Release the shell's allocator.
	g_pMalloc->Release();
	return FolderErr;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::DLLversioninfo1Click( TObject *Sender )
{
  ShowMessage(ZipBuilder1->FullVersionString());
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormResize( TObject *Sender )
 {
	ZipFName->Width = Width - 291;
	SetZipFName( ZipBuilder1->ZipFilename );
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SetZipTotals( void )
{
	StringGrid1->Cells[0][ZipBuilder1->Count + 1] = "Total";
	StringGrid1->Cells[1][ZipBuilder1->Count + 1] = IntToStr( TotComp );
	StringGrid1->Cells[2][ZipBuilder1->Count + 1] = IntToStr( TotUncomp );
	unsigned long cs = TotComp, us = TotUncomp;
	if(us)
		StringGrid1->Cells[4][ZipBuilder1->Count + 1] = IntToStr( 100 - cs * 100 / us - ((cs * 100 % us) >= us / 2) ) + " % ";
	else
		StringGrid1->Cells[4][ZipBuilder1->Count + 1] = "0 % ";
	StringGrid1->Cells[5][ZipBuilder1->Count + 1] = "";
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Messages1Click( TObject *Sender )
{
	MsgForm->Show();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MaxVolSizeEditChange( TObject *Sender )
{
	ZipBuilder1->MaxVolumeSize = StrToIntDef(  MaxVolSizeEdit->Text, 0 );
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FreeDisk1EditChange( TObject *Sender )
{
	ZipBuilder1->KeepFreeOnDisk1 = StrToIntDef( FreeDisk1Edit->Text, 0 );
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MinFreeVolEditChange( TObject *Sender )
{
 ZipBuilder1->MinFreeVolumeSize = StrToIntDef( MinFreeVolEdit->Text, 65536 );
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SortGrid(void)
{
  TStringList* List = new TStringList();
  List->Sorted = true;
  for(int i = 1; i < StringGrid1->RowCount - 1; ++i)
                List->Add(StringGrid1->Rows[i]->Text);
  for(int i = 1; i < StringGrid1->RowCount; ++i)
       StringGrid1->Rows[i]->Clear();
  for(int i = 0; i < List->Count; ++i)
    StringGrid1->Rows[i+1]->Text = List->Strings[i];
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::StringGrid1DrawCell(TObject *Sender, int ACol,
      int ARow, TRect &Rect, TGridDrawState State)
{
  UINT Format;
  if (State.Contains(gdFixed))  // for fixed cells
  {
    StringGrid1->Canvas->Brush->Color = clBtnFace;
    StringGrid1->Canvas->Font->Name = "Arial Black";
    StringGrid1->Canvas->Font->Size = 9;
    StringGrid1->Canvas->Font->Color = clBlack;
    StringGrid1->Canvas->FillRect(Rect);
    Frame3D(StringGrid1->Canvas, Rect, clBtnHighlight, clBtnShadow,1);
  }
  else // for normal cells
  {
  if(StringGrid1->Cells[0][ARow] != "Total")
    {
      StringGrid1->Canvas->Brush->Color = (StringGrid1->Cells[6][ARow] == "Y") ? clHighlight : clWindow;
      StringGrid1->Canvas->Font = StringGrid1->Font;
      StringGrid1->Canvas->Font->Color = (StringGrid1->Cells[6][ARow] == "Y") ? clHighlightText :clBlack;
      StringGrid1->Canvas->FillRect(Rect);
    }
    else //total row
    {
      StringGrid1->Canvas->Brush->Color = clAqua;
      StringGrid1->Canvas->Font = StringGrid1->Font;
      StringGrid1->Canvas->Font->Color = clRed;
      StringGrid1->Canvas->FillRect(Rect);
    }
  }
  switch(ACol)
  {
    case 0:
    case 5:
      Format = DT_LEFT;
    break;
    default:
      Format = DT_RIGHT;
    break;
  }
  RECT R = RECT(Rect);
  char* text = StringGrid1->Cells[ACol][ARow].c_str();
  DrawText(StringGrid1->Canvas->Handle, text, StrLen(text), &R, Format);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::StringGrid1SelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
  if((ARow != 0) && (ARow != StringGrid1->RowCount)) //1st and total not allowed
  {    //  Select or deselect cell
    StringGrid1->Cells[6][ARow] = (StringGrid1->Cells[6][ARow]== "N") ? "Y" : "N";
  }
  for(int i = 0; i < StringGrid1->ColCount; ++i) //forces repaint of whole row
    StringGrid1->Cells[i][ARow]= StringGrid1->Cells[i][ARow];
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
	ZipBuilder1->Unload_Zip_Dll();
	ZipBuilder1->Unload_Unz_Dll();
  Action = caFree;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -