📄 vmcopytree.cpp
字号:
dwRC = GetCurrentDirectory( BUFSIZE, m_achSource );
// make sure the getcurrentdirectory worked correctly
//
if (dwRC == 0)
{
m_iStatus = false;
return;
}
hSearch=FindFirstFile( "*",&w32FindBuf );
if ( hSearch == (HANDLE) -1 )
{
if ( wLevel )
{
UpDir( m_achDest );
// MJS: added support for previous install dir
UpDir( m_achPrevInstDir );
bRC = ( TRUE == SetCurrentDirectory("..") );
if ( bRC == false )
{
m_iStatus = false;
}
}
return;
}
for (;;)
{
// if this file is ".." or "." then get next and continue
//
if ( strcmp( w32FindBuf.cFileName,"." ) == 0
|| strcmp( w32FindBuf.cFileName,".." ) == 0 )
{
if ( FindNextFile( hSearch, &w32FindBuf ) == false )
{
bRC = ( TRUE == SetCurrentDirectory( ".." ) );
if ( bRC == false )
{
m_iStatus = false;
}
UpDir( m_achDest );
// MJS: added support for previous install dir
UpDir( m_achPrevInstDir );
return;
}
continue;
}
// if this is a directory walk it
//
if ( w32FindBuf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
bRC = ( TRUE == SetCurrentDirectory( w32FindBuf.cFileName ) );
if ( bRC == false )
{
m_iStatus = false;
return;
}
AddBackSlash( m_achDest );
strcat( m_achDest, w32FindBuf.cFileName );
GetCurrentDirectory( BUFSIZE, m_achBuffer );
if ( SetCurrentDirectory( m_achDest ) == false )
{
bRC = ( TRUE == CheckForOrMakeDir( (const char*)m_achDest, &m_oDirsMade ) );
if ( bRC != true )
{
m_iStatus = false;
return;
}
// add this directory to list of created dirs
//
if ( ( nReturn = m_oDirsMade.Add( m_achDest ) ) != VMStringList::success )
{
m_iStatus = nReturn;
return;
}
}
// MJS: Added support to add to a list of source dirs
//
if ( ( nReturn = m_oSourceDirs.Add( m_achBuffer ) ) != VMStringList::success )
{
m_iStatus = nReturn;
return;
}
// MJS: added support for previous install dir
//
AddBackSlash( m_achPrevInstDir );
strcat( m_achPrevInstDir, w32FindBuf.cFileName );
if ( SetCurrentDirectory( m_achPrevInstDir ) == false )
{
bRC = ( TRUE == CheckForOrMakeDir( (const char*)m_achPrevInstDir, &m_oDirsMade ) );
if ( bRC != true )
{
m_iStatus = false;
return;
}
// add this directory to list of created dirs
//
if ( ( nReturn = m_oDirsMade.Add( m_achPrevInstDir ) ) != VMStringList::success )
{
m_iStatus = nReturn;
return;
}
}
SetCurrentDirectory( m_achBuffer );
Walk( ++wLevel );
// if anything failed then walk back up the tree
//
if ( !m_iStatus )
{
return;
}
UpDir( m_achSource );
}
else
{
// else it is a file copy it
//
strcpy( m_achCopySource, m_achSource );
// add a \ if needed
//
AddBackSlash( m_achCopySource );
strcat( m_achCopySource, w32FindBuf.cFileName );
strcpy( m_achCopyDest, m_achDest );
AddBackSlash( m_achCopyDest );
strcat( m_achCopyDest, w32FindBuf.cFileName );
// MJS: Added support for moving any previous
// instance of a file about to be written to (over)
// to the previous instance directory
//
strcpy( m_achPrevCopyDest, m_achPrevInstDir );
AddBackSlash( m_achPrevCopyDest );
strcat( m_achPrevCopyDest, w32FindBuf.cFileName );
// MJS: ignore error checking, either works or it doesn't
//
if ( FILE_ATTRIBUTE_NORMAL != GetFileAttributes( m_achCopyDest ) )
SetFileAttributes( m_achCopyDest, FILE_ATTRIBUTE_NORMAL );
if ( FILE_ATTRIBUTE_NORMAL != GetFileAttributes( m_achPrevCopyDest ) )
SetFileAttributes( m_achPrevCopyDest, FILE_ATTRIBUTE_NORMAL );
MoveFile( m_achCopyDest, m_achPrevCopyDest );
bRC = MyCopyFile( m_achCopySource, m_achCopyDest, false );
if ( bRC == false )
{
m_iStatus = false;
return;
}
// add this file to list of created files
//
if ( (nReturn = m_oFilesMade.Add( m_achCopyDest ) ) != VMStringList::success )
{
m_iStatus = nReturn;
return;
}
// MJS: Added support to keep a list of copied files
//
if ( (nReturn = m_oSourceFiles.Add( m_achCopySource ) ) != VMStringList::success )
{
m_iStatus = nReturn;
return;
}
}
if ( FindNextFile( hSearch, &w32FindBuf ) == false )
{
bRC = ( TRUE == SetCurrentDirectory( ".." ) );
if ( bRC == false )
{
m_iStatus = false;
}
UpDir( m_achDest );
// MJS: added support for previous install dir
UpDir( m_achPrevInstDir );
return;
}
}
}
/* end of function "Walk" */
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: CleanUp
DESCRIPTION: clean up the dirs and files double list and check for
required removal of files based on status.
INPUT: void
RETURNS: void
*/
void VMCopyTree::CleanUp()
{
LPSTR lpsz;
short nLen;
if ( m_oDirsMade.GetCount() || m_oFilesMade.GetCount() )
{
// iterate the files
//
for ( lpsz = m_oFilesMade.GetFirstString(); lpsz; lpsz = m_oFilesMade.GetNextString() )
{
if ( DeleteFile( lpsz ) == false )
{
// remove dirs and files for double list
m_oDirsMade.RemoveAll();
m_oFilesMade.RemoveAll();
return;
}
}
// iterate the dirs backwards
//
for ( lpsz = m_oDirsMade.GetLastString(); lpsz; lpsz = m_oDirsMade.GetPrevString())
{
// blow away any ending back slashes
//
nLen = strlen( lpsz ) - 1;
if ( nLen >= 0 && lpsz[nLen] == '\\' )
lpsz[nLen] = '\0';
if ( RemoveDirectory(lpsz) == false )
{
m_oDirsMade.RemoveAll();
m_oFilesMade.RemoveAll();
return;
}
}
}
// remove dirs and files for double list
m_oDirsMade.RemoveAll();
m_oFilesMade.RemoveAll();
return;
}
/* end of function "CleanUp" */
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: DeleteSourceTree
DESCRIPTION: clean up the dirs and files double list and check for
required removal of files based on status.
INPUT: void
RETURNS: void
*/
void VMCopyTree::DeleteSourceTree()
{
LPSTR lpsz;
short nLen;
if ( m_oSourceDirs.GetCount() || m_oSourceFiles.GetCount() )
{
// iterate the files
//
for (lpsz = m_oSourceFiles.GetFirstString(); lpsz; lpsz = m_oSourceFiles.GetNextString() )
{
if ( FILE_ATTRIBUTE_NORMAL != GetFileAttributes( lpsz ) )
SetFileAttributes( lpsz, FILE_ATTRIBUTE_NORMAL );
if ( DeleteFile(lpsz) == false )
{
// remove dirs and files for double list
m_oSourceDirs.RemoveAll();
m_oSourceFiles.RemoveAll();
return;
}
}
// iterate the dirs backwards
//
for ( lpsz = m_oSourceDirs.GetLastString(); lpsz; lpsz = m_oSourceDirs.GetPrevString() )
{
// blow away any ending back slashes
//
nLen = strlen(lpsz) - 1;
if ( nLen >= 0 && lpsz[nLen] == '\\' )
lpsz[nLen] = '\0';
if ( RemoveDirectory( lpsz ) == false )
{
// remove dirs and files for double list
//
m_oSourceDirs.RemoveAll();
m_oSourceFiles.RemoveAll();
return;
}
}
}
// remove dirs and files for double list
m_oDirsMade.RemoveAll();
m_oFilesMade.RemoveAll();
return;
}
/* end of function "DeleteSourceTree" */
/*****************************************************************************/
/*****************************************************************************/
/* Check-in history */
/*
*$Log: $
*/
/*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -