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

📄 copyfiledlg.cpp

📁 VIPSHELL2007客户端代码
💻 CPP
字号:
// CopyFileDlg.cpp : implementation file
//

#include "stdafx.h"
#include "VipShellClient.h"
#include "CopyFileDlg.h"

#include ".\copyfiledlg.h"
#include <atlbase.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

bool CFileHandle::InitInstance()
{
	return true;
}
CFileHandle::~CFileHandle()
{
}


CCopyFileDlg::CCopyFileDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCopyFileDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCopyFileDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_nDataVecItemLen = 1400;
}


void CCopyFileDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCopyFileDlg)
	DDX_Control(pDX, IDC_EDIT_COPY, m_wndEditCopy);
	DDX_Control(pDX, IDC_EDIT_STAT, m_wndStat);
	DDX_Control(pDX, IDC_PROGRESS, m_wndProgress);
	DDX_Control(pDX, IDC_ANIMATE, m_wndAviPlay);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCopyFileDlg, CDialog)
	//{{AFX_MSG_MAP(CCopyFileDlg)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
	ON_WM_TIMER()
END_MESSAGE_MAP()

///////////////////
BOOL CCopyFileDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	m_wndAviPlay.Open(IDR_AVI_COPY);
	m_wndAviPlay.Play(0, -1,-1);

	CString strText;
	strText.Format(L"%s\r\n%s", m_strFile, m_strNew);
	m_wndEditCopy.SetWindowText(strText);
	m_wndStat.SetWindowText(L"");


	SetTimer(0x1, 100, NULL);
	return TRUE;
}
void CCopyFileDlg::AddVipShellClientGetFileTransfersInfoVec(I_VipShellClientGetFileTransfersInfo* p)
{
	CPinboardPtr<I_VipShellClientGetFileTransfersInfo> spVipShellClientGetFileTransfersInfo = p;
	m_hVipShellClientGetFileTransfersInfoVec.push_back(spVipShellClientGetFileTransfersInfo);
}
void CCopyFileDlg::DelVipShellClientGetFileTransfersInfoVec(I_VipShellClientGetFileTransfersInfo* p)
{
	for( UINT32 i= 0; i < m_hVipShellClientGetFileTransfersInfoVec.size(); i++ )
	{
		if( m_hVipShellClientGetFileTransfersInfoVec[i] == p )
		{
			m_hVipShellClientGetFileTransfersInfoVec.erase(m_hVipShellClientGetFileTransfersInfoVec.begin() + i);
			return ;
		}
	}
}

void CCopyFileDlg::AddVipShellClientPutFileTransfersInfoVec(I_VipShellClientPutFileTransfersInfo* p)
{
	m_hVipShellClientPutFileTransfersInfoVec.push_back(p);
}
void CCopyFileDlg::DelVipShellClientPutFileTransfersInfoVec(I_VipShellClientPutFileTransfersInfo* p)
{
	for( UINT32 i= 0; i < m_hVipShellClientPutFileTransfersInfoVec.size(); i++ )
	{
		if( m_hVipShellClientPutFileTransfersInfoVec[i] == p )
		{
			m_hVipShellClientPutFileTransfersInfoVec.erase(m_hVipShellClientPutFileTransfersInfoVec.begin() + i);
			return ;
		}
	}
}

void CCopyFileDlg::SetVipShellClientFileManageHandle(I_VipShellClientFileManageHandle* p)
{
	m_spVipShellClientFileManageHandle = p;
}
void CCopyFileDlg::SetCopy(LPCWSTR szFile, LPCWSTR szNew,bool fIsGet, size_t nSize)
{
	UINT32 i = 0;
	for( i =0 ; i * m_nDataVecItemLen < nSize; i++)
	{
		m_DataVec.push_back( i * m_nDataVecItemLen );
	}
	if( i * m_nDataVecItemLen < nSize )
		m_DataVec.push_back( i * m_nDataVecItemLen );
	
	m_filesize = nSize;
	m_strFile = szFile;
	m_strNew = szNew;
	m_fIsGet = fIsGet;
}
void CCopyFileDlg::OnBnClickedCancel()
{
	// TODO: 在此添加控件通知处理程序代码

	OnCancel();
}
void CCopyFileDlg::VipShellClientPutFile()
{
		if( m_hVipShellClientPutFileTransfersInfoVec.size() > 40 )
			return ;
		CPinboardPtr<I_VipShellClientPutFileTransfersInfo> spVipShellClientPutFileTransfersInfo = NULL;
		m_spVipShellClientFileManageHandle->CreatePutFileTransfersInfo(&spVipShellClientPutFileTransfersInfo);
		spVipShellClientPutFileTransfersInfo->SetFilePath(m_strNew);
		spVipShellClientPutFileTransfersInfo->SetFilePointer(m_DataVec[0]);
		BYTE* pData = new BYTE[m_nDataVecItemLen];
		bool fEnd = false;
		UINT32 nLen = m_hFileVec.ReadFile(m_strNew, m_DataVec[0], pData, m_nDataVecItemLen, &fEnd);
		spVipShellClientPutFileTransfersInfo->SetData(pData, nLen);
		if( m_spVipShellClientFileManageHandle->PutFile(spVipShellClientPutFileTransfersInfo, fEnd) )
			m_DataVec.erase(m_DataVec.begin() + 0 );
}
void CCopyFileDlg::OnTimer(UINT nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
//	if( MCIWndGetPosition(m_VideoWnd) == MCIWndGetLength(m_VideoWnd) )
//		MCIWndPlay(m_VideoWnd);
	CDialog::OnTimer(nIDEvent);
	if( m_fIsGet )
	{
		for( UINT32 i= 0; i < m_hVipShellClientGetFileTransfersInfoVec.size(); i++ )
		{
			enumFileTransfersBuffState stat;
			m_hVipShellClientGetFileTransfersInfoVec[i]->GetStat(&stat);
			if( stat == FileTransfersBuffState_Ok || stat == FileTransfersBuffState_Ok_end)
			{
				
				m_hFileVec.WriteFile(m_strNew, m_hVipShellClientGetFileTransfersInfoVec[i]->GetFilePointer(), m_hVipShellClientGetFileTransfersInfoVec[i]->GetBuff(), m_hVipShellClientGetFileTransfersInfoVec[i]->GetBufflen());
				if(  stat == FileTransfersBuffState_Ok_end )
					m_hFileVec.CloseFile(m_strNew);
				m_hVipShellClientGetFileTransfersInfoVec.erase(m_hVipShellClientGetFileTransfersInfoVec.begin() + i );
				i--;
				continue;
			}
		}
		if( m_DataVec.size() == 0 )
			return ;
		if( m_hVipShellClientGetFileTransfersInfoVec.size() > 40 )
			return ;
		CPinboardPtr<I_VipShellClientGetFileTransfersInfo> spVipShellClientGetFileTransfersInfo = NULL;
		m_spVipShellClientFileManageHandle->CretaeGetFileTransfersInfo(&spVipShellClientGetFileTransfersInfo);
		spVipShellClientGetFileTransfersInfo->SetFilePath(m_strFile);
		spVipShellClientGetFileTransfersInfo->SetFilePointer(m_DataVec[0]);
		spVipShellClientGetFileTransfersInfo->SetReadLen(m_nDataVecItemLen);
		if( !m_spVipShellClientFileManageHandle->GetFile(spVipShellClientGetFileTransfersInfo) )
			return ;
		m_hVipShellClientGetFileTransfersInfoVec.push_back( spVipShellClientGetFileTransfersInfo );
		m_DataVec.erase(m_DataVec.begin() + 0 );
	}
	else
		VipShellClientPutFile();
		
	
}
UINT32 GeiFileSize(LPCWSTR szPath)
{
	WIN32_FIND_DATA info;
	HANDLE hFile = FindFirstFile(szPath, &info);
	if( hFile == INVALID_HANDLE_VALUE )
		return -1;
	FindClose(hFile);
	return info.nFileSizeLow;
}
bool PutFile(I_VipShellClientFileManageHandle* pFileManage, LPCWSTR szPath, LPCWSTR szPathNew , CGetFileCallBack* pE)
{
	CPinboardPtr<I_VipShellClientFileManageHandle> spVipShellClientFileManageHandle = pFileManage;
	CPinboardPtr<I_VipShellClientPutFileTransfersInfo> spVipShellClientPutFileTransfersInfo;

	UINT32 nFileSize = GeiFileSize(szPath);
	BYTE nDate[500000];
	UINT32 nReadSize = 500000;
	FILE* fp = _wfopen(szPath, L"rb");
	if( !fp )
		return false;
	UINT32 nStartTime = GetTickCount();
	UINT32	nReadLen;
	DWORD dwPutLen = 0;
	for( UINT32 i = 0 ; true ; i++ )
	{
		nReadLen = fread(nDate, 1, nReadSize, fp);
		spVipShellClientPutFileTransfersInfo = NULL;
		spVipShellClientFileManageHandle->CreatePutFileTransfersInfo(&spVipShellClientPutFileTransfersInfo);
		spVipShellClientPutFileTransfersInfo->SetFilePath(szPathNew);
		spVipShellClientPutFileTransfersInfo->SetFilePointer(i * nReadSize);
		spVipShellClientPutFileTransfersInfo->SetData(nDate, nReadLen);
		bool fIsEnd = !!feof(fp);
		if( !spVipShellClientFileManageHandle->PutFile(spVipShellClientPutFileTransfersInfo, fIsEnd ) )
		{
			fclose(fp);
			return false;
		}
		dwPutLen += nReadLen;

		while(true)
		{
			enumFileTransfersBuffState stat;
			spVipShellClientPutFileTransfersInfo->GetStat(&stat);
			if( stat == FileTransfersBuffState_Ok || stat == FileTransfersBuffState_Ok_end)
				break;
			if( stat == FileTransfersBuffState_error )
			{
				fclose(fp);
				return false;
			}
			Sleep(1);
		}
		if( pE )
			pE->OnPutFileIng(szPath, szPathNew, nFileSize, dwPutLen, nStartTime);
		if( fIsEnd )
			break;
	}
	fclose(fp);
	return true;
}
bool PutDir(I_VipShellClientFileManageHandle* pFileManage, LPCWSTR szPath, LPCWSTR szPathNew , CGetFileCallBack* pE)
{
	CPinboardPtr<I_VipShellClientFileManageHandle> spVipShellClientFileManageHandle = pFileManage;
	typedef std::vector<WIN32_FIND_DATA>  WIN32_FIND_DATAVEC;
	std::wstring strPath;
	std::wstring strPathNew;
	WIN32_FIND_DATAVEC vec;
	WCHAR szFilePath[MAX_PATH] = {0};
	lstrcpy(szFilePath,szPath);
	if(szFilePath[lstrlen(szFilePath) - 1] != _T('\\'))
		wcscat(szFilePath, L"\\");
	strPath = szFilePath;

	WCHAR szFilePathNew[MAX_PATH] = {0};
	lstrcpy(szFilePathNew,szPathNew);
	if(szFilePathNew[lstrlen(szFilePathNew) - 1] != _T('\\'))
		wcscat(szFilePathNew, L"\\");
	strPathNew = szFilePathNew;

	bool fret;
	if( !spVipShellClientFileManageHandle->CreateDirectory( szPathNew, &fret ) )
		return false;
	lstrcat(szFilePath, _T("*.*"));
	WIN32_FIND_DATA fileinfo;
	memset(&fileinfo, 0, sizeof(WIN32_FIND_DATA));
	HANDLE hFile = FindFirstFile( szFilePath, &fileinfo );
	if(hFile == INVALID_HANDLE_VALUE )
		return false;
	do 
	{
		vec.push_back(fileinfo);
		memset(&fileinfo, 0, sizeof(WIN32_FIND_DATA));
	} while(FindNextFile(hFile, &fileinfo));
	FindClose(hFile);
	for(UINT32 i = 0; i < vec.size(); i++ )
	{
		if( wcscmp(L".", vec[i].cFileName) == 0 )
			continue;
		if( wcscmp(L"..", vec[i].cFileName) == 0 )
			continue;
		if(vec[i].dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
		{
			std::wstring strPath1 = strPath + vec[i].cFileName ;
			strPath1 += L"\\" ;
			std::wstring strPathNew1  = strPathNew + vec[i].cFileName ;
			strPathNew1 += L"\\" ;
			if( !PutDir(pFileManage, strPath1.c_str(), strPathNew1.c_str(), pE) )
				return false;
		}
		else
		{
			std::wstring strPath1 = strPath + vec[i].cFileName ;
			std::wstring strPathNew1  = strPathNew + vec[i].cFileName ;
			if( !PutFile(pFileManage, strPath1.c_str(), strPathNew1.c_str(), pE) )
				return false;
		}
	}
	return true;
}
bool GetFile(I_VipShellClientFileManageHandle* pFileManage, LPCWSTR szPath, LPCWSTR szPathNew, CGetFileCallBack* pE)
{
	CPinboardPtr<I_VipShellClientFileManageHandle> spVipShellClientFileManageHandle = pFileManage;
	CPinboardPtr<I_VipShellClientGetFileTransfersInfo> spVipShellClientGetFileTransfersInfo;

	UINT32 nReadSize = 500000;
	FILE* fp = _wfopen(szPathNew, L"wb");
	if( !fp )
		return false;
	UINT32 nStartTime = GetTickCount();
	for( UINT32 i = 0 ; true ; i++ )
	{
		spVipShellClientGetFileTransfersInfo = NULL;
		spVipShellClientFileManageHandle->CretaeGetFileTransfersInfo(&spVipShellClientGetFileTransfersInfo);
		spVipShellClientGetFileTransfersInfo->SetFilePath(szPath);
		spVipShellClientGetFileTransfersInfo->SetFilePointer(i * nReadSize);
		spVipShellClientGetFileTransfersInfo->SetReadLen(nReadSize);
		if( !spVipShellClientFileManageHandle->GetFile(spVipShellClientGetFileTransfersInfo) )
			return false;

		while(true)
		{
			enumFileTransfersBuffState stat;
			spVipShellClientGetFileTransfersInfo->GetStat(&stat);
			if( stat == FileTransfersBuffState_Ok || stat == FileTransfersBuffState_Ok_end)
			{
				fwrite(spVipShellClientGetFileTransfersInfo->GetBuff(), 1, spVipShellClientGetFileTransfersInfo->GetBufflen(), fp);
				if( stat == FileTransfersBuffState_Ok_end )
				{
					fclose(fp);
					return true;
				}
				break;
			}
			Sleep(1);
		}
		if( pE )
			pE->OnGetFileIng(szPath, szPathNew, spVipShellClientGetFileTransfersInfo->GetFileSize(),( i ) * nReadSize + spVipShellClientGetFileTransfersInfo->GetBufflen(),  nStartTime);
					
	}

}

bool GetDir(I_VipShellClientFileManageHandle* pFileManage, LPCWSTR szPath, LPCWSTR szPathNew, CGetFileCallBack* pE)
{
	CPinboardPtr<I_VipShellClientFileManageHandle> spVipShellClientFileManageHandle = pFileManage;
	
	std::wstring strPath = szPath;
	
	if( szPath[lstrlen(szPath) -1] != _T('\\') )
		strPath +=  _T("\\");
	{{
		std::wstring strPath = szPathNew;
		if( szPath[lstrlen(szPath) -1] != _T('\\') )
			strPath +=  _T("\\");
		BOOL bOK = CreateDirectory(strPath.c_str(), NULL);
		if(!bOK)
			return false;
	}}
	CComBSTR bstr;
	if( !spVipShellClientFileManageHandle->GetPath(szPath, &bstr) )
		return false;
	UINT32 nCount = bstr.Length() * sizeof(WCHAR) / sizeof( WIN32_FIND_DATA );
	
	for( UINT32 i = 0; i < nCount; i++)
	{
	//	PWIN32_FIND_DATA pFileData;
	//	pFileData =(PWIN32_FIND_DATA)( p  + ( i * sizeof(WIN32_FIND_DATA)));

		PWIN32_FIND_DATA pInfo = (PWIN32_FIND_DATA)( (	((BYTE*)(LPCWSTR)bstr)) + (i * sizeof( WIN32_FIND_DATA )) );

		if(lstrcmp(pInfo->cFileName, _T(".")) == 0)
			continue;
		if(lstrcmp(pInfo->cFileName, _T("..")) == 0)
			continue;


		std::wstring strPath = szPathNew;
		if( szPathNew[lstrlen(szPathNew) -1] != _T('\\') )
			strPath +=  _T("\\");

		std::wstring strRemote = szPath;
		if( szPath[lstrlen(szPath) -1] != _T('\\') )
			strRemote +=  _T("\\");

		if(pInfo->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
		{
			strPath +=  pInfo->cFileName;
			strPath +=  L"\\";
			strRemote += pInfo->cFileName;
			strRemote +=  L"\\";
			bool f =  GetDir( pFileManage, strRemote.c_str(), strPath.c_str(), pE);
			if( !f )
				return f;
		}
		else
		{
			strPath +=  pInfo->cFileName;
			strRemote += pInfo->cFileName;
			bool f =  GetFile(pFileManage, strRemote.c_str(), strPath.c_str(), pE);
			if( !f )
				return f;
		}

	}
	return true;

}

⌨️ 快捷键说明

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