?? main.cpp
字號:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString strUpdateFile = ExtractFilePath( Application->ExeName ) + "\\temp\\123.rar" ;
//AnsiString strUpdateFile = ExtractFilePath( Application->ExeName ) + "\\temp\\Msg.txt" ;
pUnRar = new CUnRar(strUpdateFile.c_str());
__int64 nTotalSize = pUnRar->GetUnpackSize();
FILESIZEINFO *pFileListInfo = pUnRar->GetFileList();
while (pFileListInfo)
{
Application->ProcessMessages();
int nResult = pUnRar->UnpackFile(pFileListInfo->szPath, ".\\");
//ShowMessage(pFileListInfo->szPath);
if (nResult == UNRAR_SUCCESS)
{
pFileListInfo = pFileListInfo->pNext;
continue;
}
if (nResult == UNRAR_ERROR_FILEINUSE)
{
int i = 0;
while ( i < 50 ) //給5秒鐘的時間等待某些文件的完全釋放
{
Application->ProcessMessages();
nResult = pUnRar->UnpackFile(pFileListInfo->szPath, ".\\");
if ( nResult == UNRAR_SUCCESS )
{
pFileListInfo = pFileListInfo->pNext;
break;
}
Sleep( 600 );
i++;
}
if ( nResult == UNRAR_SUCCESS )
{
continue;
}
return;
}
return;
}
delete pUnRar;
//CopyUpFile(ExtractFilePath(Application->ExeName)+"temp\\",ExtractFilePath(Application->ExeName));
//DeleteUpFile(ExtractFilePath(Application->ExeName)+"temp\\");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
//int nResult = pUnRar->UnpackFile(pFileListInfo->szPath, ".\\");
}
//---------------------------------------------------------------------------
void GetFileList( AnsiString PathName, TStringList *pFileList )
{
TSearchRec sr;
AnsiString FullPath;
if(FindFirst( PathName+"*.*", faAnyFile, sr) == 0 )
{
do
{
Application->ProcessMessages();
if( sr.Name!="." && sr.Name!=".." )
{
if( FileExists( PathName+sr.Name ) )
{
pFileList->Add(PathName+sr.Name);
}
if( DirectoryExists( PathName+sr.Name ) )
{
FullPath=PathName+sr.Name;
if( FullPath.SubString( FullPath.Length(), 1 )!="\\" )
{
FullPath=FullPath+"\\";
GetFileList( FullPath, pFileList );
Application->ProcessMessages();
}
}
}
}while (FindNext(sr) == 0);
FindClose(sr);
}
}
//---------------------------------------------------------------------------------
void GetPathFile( AnsiString PathName, TStringList *FileList )
{
TSearchRec sr;
AnsiString FullPath;
if(FindFirst( PathName+"*.*", faAnyFile, sr) == 0 )
{
do
{
Application->ProcessMessages();
if( sr.Name!="." && sr.Name!=".." )
{
if( FileExists( PathName+sr.Name ) )
{
FileList->Add(PathName+sr.Name);
}
if( DirectoryExists( PathName+sr.Name ) )
{
FullPath=PathName+sr.Name;
if( FullPath.SubString( FullPath.Length(), 1 )!="\\" )
{
FullPath=FullPath+"\\";
GetFileList( FullPath, FileList );
Application->ProcessMessages();
}
}
}
}while (FindNext(sr) == 0);
FindClose(sr);
}
}
//------------------------------------------------------------------------------
void __fastcall TForm1::CopyUpFile( AnsiString SourcePath, AnsiString DestPath )
{
TStringList *FileList=new TStringList;
AnsiString AppPath=ExtractFilePath( Application->ExeName );
FileList->Clear();
GetPathFile( SourcePath, FileList );
AnsiString SourceFile, DestFile, SourceF;
int iPos;
if( FileList->Count>0 )
{
for( int i=0; i<FileList->Count; i++ )
{
SourceFile=FileList->Strings[i];
iPos=SourcePath.Length();
SourceF=SourceFile.SubString( iPos+1, SourceFile.Length() );
DestFile=DestPath+SourceF;
if( !DirectoryExists( ExtractFileDir( DestFile ) ) )
{
ForceDirectories( ExtractFileDir( DestFile ) );
}
Application->ProcessMessages();
CopyFile( SourceFile.c_str(), DestFile.c_str(), false );
Application->ProcessMessages();
}
}
FileList->Clear();
delete FileList;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DeleteUpFile( AnsiString Path )
{
TStringList *FileList=new TStringList;
AnsiString AppPath=ExtractFilePath( Application->ExeName );
FileList->Clear();
GetPathFile( Path, FileList );
if( FileList->Count>0 )
{
for( int i=0; i<FileList->Count; i++ )
{
if( FileExists( FileList->Strings[i] ) )
DeleteFile( FileList->Strings[i] );
Application->ProcessMessages();
}
}
delete FileList;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -