fix transfer status.

This commit is contained in:
floyd 2015-07-05 13:55:18 +08:00
parent 975a288507
commit 5f622c4008
11 changed files with 156 additions and 247 deletions

View File

@ -31,6 +31,9 @@ void CTransferDlg::DoDataExchange(CDataExchange* pDX)
BEGIN_MESSAGE_MAP(CTransferDlg, CDialogEx)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON_STARTTRANS, &CTransferDlg::OnBnClickedButtonStart)
ON_BN_CLICKED(IDC_BUTTON_STOP, &CTransferDlg::OnBnClickedButtonStop)
ON_BN_CLICKED(IDC_BUTTON_DELETE, &CTransferDlg::OnBnClickedButtonDelete)
END_MESSAGE_MAP()
void CTransferDlg::InitView()
@ -82,18 +85,27 @@ void CTransferDlg::ModifyStatusProc(LPCTSTR clientid,TRANS_STATUS status,LPVOID
DWORD dwTotalBytes = info.nTotal;
//×Ö½Ú½ø¶È
CString donebytes;
donebytes.Format(_T("%u"), dwDoneBytes);
donebytes.Format(_T("%u MB"), dwDoneBytes);
CString totalbytes;
totalbytes.Format(_T("%u"), dwTotalBytes);
totalbytes.Format(_T("%u MB"), dwTotalBytes);
float fProcess = ((float)dwDoneBytes)/((float)dwTotalBytes);
int nProcess = (int)(fProcess * (float)100);
//°Ù·ÖÖ®½ø¶È
CString process;
process.Format(_T("%d / %d"),dwDoneBytes,dwTotalBytes);
CString sstatus = !info.isDown ? _T("Uploading") : _T("Downloading");
if (IsHasStop(m_clientid,status))
{
sstatus = _T("Stopped");
}
CString progress;
progress.Format(_T("%d%%"),nProcess);
if (nProcess == 100)
@ -108,6 +120,12 @@ void CTransferDlg::ModifyStatusProc(LPCTSTR clientid,TRANS_STATUS status,LPVOID
nTmp = 0;
int nImage = m_ImageList.Add(CIconLoader::GetInstanceRef().LoadIcon(info.strSPath));
m_transList.InsertItem(nTmp,info.strSPath,nImage);
TRANS_STATUS *myStatus = new TRANS_STATUS;
memcpy(myStatus,&status,sizeof(TRANS_STATUS));
m_transList.SetItemData(nTmp,(DWORD_PTR)myStatus);
m_transList.SetItemText(nTmp,1,info.strCPath);
}
m_transList.SetItemText(nTmp,2,process);
@ -143,3 +161,37 @@ void CTransferDlg::OnDestroy()
__super::OnDestroy();
m_checkTask.Stop();
}
void CTransferDlg::OnBnClickedButtonStart()
{
POSITION pos = m_transList.GetFirstSelectedItemPosition();
int index = m_transList.GetNextSelectedItem(pos);
TRANS_STATUS* pData = (TRANS_STATUS*)m_transList.GetItemData(index);
StartFileTransfer(m_clientid,*pData);
}
void CTransferDlg::OnBnClickedButtonStop()
{
POSITION pos = m_transList.GetFirstSelectedItemPosition();
int index = m_transList.GetNextSelectedItem(pos);
TRANS_STATUS* pData = (TRANS_STATUS*)m_transList.GetItemData(index);
StopFileTransfer(m_clientid,*pData);
}
void CTransferDlg::OnBnClickedButtonDelete()
{
POSITION pos = m_transList.GetFirstSelectedItemPosition();
int index = m_transList.GetNextSelectedItem(pos);
TRANS_STATUS* pData = (TRANS_STATUS*)m_transList.GetItemData(index);
DeleteFileTransfer(m_clientid,*pData);
}

View File

@ -45,4 +45,7 @@ public:
//ÏìÓ¦´°¿ÚÏú»ÙÏûÏ¢
afx_msg void OnDestroy();
afx_msg void OnBnClickedButtonStart();
afx_msg void OnBnClickedButtonStop();
afx_msg void OnBnClickedButtonDelete();
};

View File

@ -225,6 +225,30 @@ BOOL CFileTransfer::DeleteStopList( LPCTSTR serverpath )
m_csStopMap.Leave();
return TRUE;
}
BOOL CFileTransfer::DeleteTransferInfo(LPCTSTR clientid, TRANS_STATUS& status )
{
m_csProcessMap.Enter();
{
ProcessMap::iterator it = m_processMap.find(clientid);
if ( it == m_processMap.end() )
{
TransStatusVector::iterator it2 = it->second.begin();
for ( ; it2 != it->second.end(); it2++ )
{
if (it2->second.strSPath == status.strSPath)
{
DeleteStopList(status.strSPath);
it->second.erase(it2);
break;
}
}
}
}
m_csProcessMap.Leave();
return TRUE;
}
BOOL CFileTransfer::IsHasStop(LPCTSTR serverpath)
{
@ -247,17 +271,17 @@ BOOL CFileTransfer::IsHasStop(LPCTSTR serverpath)
return ret;
}
void CFileTransfer::GetTransferList( LPCTSTR clientid,TransStatusVector* list )
void CFileTransfer::GetTransferList( LPCTSTR clientid,TransStatusVector& list )
{
m_csProcessMap.Enter();
{
ProcessMap::iterator it = m_processMap.find(clientid);
if (it != m_processMap.end())
{
TransStatusVector::iterator it2 = it->second->begin();
for (; it2 != it->second->end();it2++)
TransStatusVector::iterator it2 = it->second.begin();
for (; it2 != it->second.end();it2++)
{
list->push_back(*it2);
list[it2->first] = it2->second;
}
}
}
@ -268,15 +292,15 @@ BOOL CFileTransfer::GetStatusByPath(LPCTSTR clientid,CString strSPath,TRANS_STAT
{
TransStatusVector list;
GetTransferList(clientid,&list);;
GetTransferList(clientid,list);;
TransStatusVector::iterator it = list.begin();
for(; it != list.end(); it++)
{
if (CString(it->strSPath) == strSPath)
if (CString(it->second.strSPath) == strSPath)
{
status = *it;
status = it->second;
return TRUE;
}
}
@ -290,37 +314,46 @@ void CFileTransfer::UpdateTransferList( LPCTSTR clientid,TRANS_STATUS& status )
do
{
ProcessMap::iterator it1 = m_processMap.find(clientid);
TransStatusVector *list;
//查找是否存在对应ID的list
//查找是否存在对应clientid的list
if (it1 != m_processMap.end())
{
list = m_processMap[clientid];
TransStatusVector &list = m_processMap[clientid];
//迭代查找符合条件的
TransStatusVector::iterator it2 = list.begin();
for (; it2 != list.end(); it2++)
{
if (CString(it2->second.strSPath) == CString(status.strSPath))
{
list[it2->first] = status;
break;
}
}
//没有符合条件的就添加
if (it2 == list.end())
{
for(int i = 0 ; i <= 10000 ; i++)
{
if (list.find(i) == list.end())
{
list[i] = status;
break;
}
}
}
}
//Èç¹ûlist²»´æÔÚ£¬ÔòÌí¼Ó
else
{
TransStatusVector *newlist = new TransStatusVector;
TransStatusVector newlist;
newlist[0] = status;
m_processMap[clientid] = newlist;
m_processMap[clientid]->push_back(status);
break;
}
//迭代查找符合条件的
TransStatusVector::iterator it2 = list->begin();
for (; it2 != list->end(); it2++)
{
if (CString(it2->strSPath) == CString(status.strSPath))
{
*it2 = status;
break;
}
}
if (it2 == list->end())
{
list->push_back(status);
}
} while (FALSE);
}
m_csProcessMap.Leave();

View File

@ -18,9 +18,9 @@ public:
BOOL AddStopList(LPCTSTR serverpath);
BOOL DeleteStopList(LPCTSTR serverpath);
void GetTransferList(LPCTSTR clientid,TransStatusVector* list);
void GetTransferList(LPCTSTR clientid,TransStatusVector& list);
void UpdateTransferList(LPCTSTR clientid,TRANS_STATUS& status);
void DeleteTransferInfo(LPCTSTR clientid,TRANS_STATUS& status);
BOOL DeleteTransferInfo(LPCTSTR clientid,TRANS_STATUS& status);
BOOL RequestGetFile(LPCTSTR clientid,LPCTSTR clientpath,LPCTSTR serverpath);
BOOL RequestPutFile(LPCTSTR clientid,LPCTSTR clientpath,LPCTSTR serverpath);
@ -33,7 +33,7 @@ private:
TransStopList m_stopList;
CriticalSection m_csProcessMap;
typedef std::map<CString,TransStatusVector*> ProcessMap;
typedef std::map<CString,TransStatusVector> ProcessMap;
ProcessMap m_processMap;
};

View File

@ -1,5 +1,5 @@
#pragma once
#include <vector>
#include <map>
typedef struct _TRANS_STATUS
{
@ -10,4 +10,4 @@ typedef struct _TRANS_STATUS
BOOL isDown;
}TRANS_STATUS,*PTRANS_STATUS;
typedef std::vector<TRANS_STATUS> TransStatusVector;
typedef std::map<int,TRANS_STATUS> TransStatusVector;

View File

@ -301,134 +301,6 @@ MASTER2_API void CloseShell(LPCTSTR clientid)
ShellManager::GetInstanceRef().CloseShell(clientid);
}
MASTER2_API BOOL ListDisks( LPCTSTR clientid, MDiskInfoList* pDiskInfoList )
{
if (NULL == clientid || NULL == pDiskInfoList) return FALSE;
CommData sendData;
sendData.SetMsgID(MSGID_DISKS);
MSGSERIALID serialID = CommManager::GetInstanceRef().AddToSendMessage(clientid, sendData);
if (INVALID_MSGSERIALID == serialID)
{
errorLog(_T("add to send msg failed"));
return FALSE;
}
CommData commData;
if (! WaitForReply(clientid, serialID, commData))
{
return FALSE;
}
std::list<MDISK_INFO> diskList;
DECLARE_STR_PARAM_API(result);
TStringVector partitionList;
splitByChar(result.c_str(), partitionList, ':');
TStringVector::iterator partitionIter = partitionList.begin();
for (; partitionIter != partitionList.end(); partitionIter++)
{
const tstring& line = *partitionIter;
TStringVector dataList;
splitByChar(line.c_str(), dataList, '|');
if (dataList.size() != 4) continue;
tstring& partition = dataList[0];
if (partition.size() == 0) continue;
UINT driverType;
if (0 == _stscanf_s(dataList[1].c_str(), _T("%u"), &driverType)) continue;
UINT64 totalBytes = 0;
UINT64 freeBytes = 0;
if (0 == _stscanf_s(dataList[2].c_str(), _T("%I64u"), &totalBytes)) continue;
if (0 == _stscanf_s(dataList[3].c_str(), _T("%I64u"), &freeBytes)) continue;
MDISK_INFO info;
info.partition = ws2s(partition)[0];
info.freeBytes = freeBytes;
info.totalBytes = totalBytes;
info.driverType = driverType;
diskList.push_back(info);
}
if (diskList.size() > 0)
{
pDiskInfoList->Alloc(diskList.size());
std::list<MDISK_INFO>::iterator iter = diskList.begin();
for (int i = 0; iter != diskList.end(); iter++, i++)
{
pDiskInfoList->At(i) = *iter;
}
}
return TRUE;
}
MASTER2_API BOOL ListFiles( LPCTSTR clientid, LPCTSTR findstr, MFileInfoList* pFileInfoList )
{
if (NULL == clientid || NULL == findstr || NULL == pFileInfoList) return FALSE;
CommData sendData;
sendData.SetMsgID(MSGID_LIST_FILES);
sendData.SetData(_T("findstr"), findstr);
MSGSERIALID serialID = CommManager::GetInstanceRef().AddToSendMessage(clientid, sendData);
if (INVALID_MSGSERIALID == serialID)
{
errorLog(_T("add to send msg failed"));
return FALSE;
}
CommData commData;
if (! WaitForReply(clientid, serialID, commData))
{
return FALSE;
}
std::vector<MFILE_INFO> fileList;
DECLARE_STR_PARAM_API(result);
TStringVector partitionList;
splitByChar(result.c_str(), partitionList, ':');
TStringVector::iterator partitionIter = partitionList.begin();
for (; partitionIter != partitionList.end(); partitionIter++)
{
const tstring& line = *partitionIter;
TStringVector dataList;
splitByChar(line.c_str(), dataList, '|');
if (dataList.size() != 4) continue;
DWORD dwAttributes;
if (0 == _stscanf_s(dataList[1].c_str(), _T("%u"), &dwAttributes)) continue;
UINT64 filesize = 0;
ULARGE_INTEGER lastWritetime = {0};
if (0 == _stscanf_s(dataList[2].c_str(), _T("%I64u"), &filesize)) continue;
if (0 == _stscanf_s(dataList[3].c_str(), _T("%I64u"), &lastWritetime.QuadPart)) continue;
MFILE_INFO info = {0};
_tcscpy_s(info.filename, dataList[0].c_str());
info.dwAttributes = dwAttributes;
info.filesize = filesize;
info.lastWriteTime.dwHighDateTime = lastWritetime.HighPart;
info.lastWriteTime.dwLowDateTime = lastWritetime.LowPart;
fileList.push_back(info);
}
if (fileList.size() > 0)
{
sort(fileList.begin(), fileList.end());
pFileInfoList->Alloc(fileList.size());
std::vector<MFILE_INFO>::iterator iter = fileList.begin();
for (int i = 0; iter != fileList.end(); iter++, i++)
{
pFileInfoList->At(i) = *iter;
}
}
return TRUE;
}
MASTER2_API void AsynListFiles( LPCTSTR clientid, LPCTSTR findstr,BOOL isClient, LPVOID lpParameter )
{
LIST_FILE_PARAMETER* pData = new LIST_FILE_PARAMETER;
@ -642,7 +514,7 @@ MASTER2_API BOOL ModifyPacketStatus(ULONG serial,LPCTSTR clientid,BOOL status)
}
/***********************Îļþ´«ÊäAPI***********************************/
/***********************Îļþ¹ÜÀíAPI***********************************/
MASTER2_API BOOL PutFileToClient( LPCTSTR clientid,LPCTSTR serverpath,LPCTSTR clientpath )
{
@ -654,31 +526,10 @@ MASTER2_API BOOL GetFileToServer( LPCTSTR clientid,LPCTSTR clientpath,LPCTSTR se
return CFileTransfer::GetInstanceRef().RequestGetFile(clientid,clientpath,serverpath);
}
MASTER2_API void QueryFileTransferStatus( LPCTSTR clientid,TransferInfoList* list )
{
TransStatusVector vec;
CFileTransfer::GetInstanceRef().GetTransferList(clientid,&vec);
if (vec.size() > 0)
{
list->Alloc(vec.size());
TransStatusVector::iterator iter = vec.begin();
for (int i = 0; iter != vec.end(); iter++, i++)
{
TRANS_STATUS& info = *iter;
TRANS_STATUS& myinfo = list->At(i);
memcpy(&myinfo,&info,sizeof(TRANS_STATUS));
}
}
}
MASTER2_API void QueryTransferStatus(LPCTSTR clientid,FnQueryTrans fn,LPVOID lpParameter)
{
TransStatusVector vec;
CFileTransfer::GetInstanceRef().GetTransferList(clientid,&vec);
CFileTransfer::GetInstanceRef().GetTransferList(clientid,vec);
TransStatusVector::iterator iter = vec.begin();
@ -686,20 +537,39 @@ MASTER2_API void QueryTransferStatus(LPCTSTR clientid,FnQueryTrans fn,LPVOID lpP
{
if (fn)
{
fn(clientid,*iter,lpParameter);
fn(clientid,iter->second,lpParameter);
}
}
}
MASTER2_API BOOL StartFileTransfer(LPCTSTR clientid,LPCTSTR serverpath)
MASTER2_API BOOL StartFileTransfer( LPCTSTR clientid ,TRANS_STATUS& status )
{
return CFileTransfer::GetInstanceRef().DeleteStopList(serverpath);
CFileTransfer::GetInstanceRef().DeleteStopList(status.strSPath);
if (status.isDown)
{
return CFileTransfer::GetInstanceRef().RequestGetFile(clientid,status.strCPath,status.strSPath);
}
else
{
return CFileTransfer::GetInstanceRef().RequestPutFile(clientid,status.strCPath,status.strSPath);
}
}
MASTER2_API BOOL StopFileTransfer(LPCTSTR clientid,LPCTSTR serverpath)
MASTER2_API BOOL StopFileTransfer( LPCTSTR clientid ,TRANS_STATUS& status )
{
return CFileTransfer::GetInstanceRef().AddStopList(serverpath);
return CFileTransfer::GetInstanceRef().AddStopList(status.strSPath);
}
MASTER2_API BOOL DeleteFileTransfer( LPCTSTR clientid ,TRANS_STATUS& status )
{
return CFileTransfer::GetInstanceRef().DeleteTransferInfo(clientid,status);
}
MASTER2_API BOOL IsHasStop ( LPCTSTR clientid ,TRANS_STATUS& status )
{
return CFileTransfer::GetInstanceRef().IsHasStop(status.strSPath);
}
MASTER2_API void DeleteRemoteFile(LPCTSTR clientid,LPCTSTR clientpath)
@ -730,6 +600,7 @@ MASTER2_API void RunRemoteFile(LPCTSTR clientid,LPCTSTR clientpath)
}
}
/***********************Ä£¿é¹¦ÄÜAPI***********************************/
MASTER2_API void SetModuleCallBack(FnModuleNotifyProc func)
{
ClientInfoManager::GetInstanceRef().SetModuleCallBack(func);

View File

@ -21,8 +21,6 @@ EXPORTS
QueryModuleInstallStatus @17
StopMasterWorking @18
ListDisks @19
ListFiles @20
AsynListFiles @21
AsynListDisks @22

View File

@ -21,52 +21,6 @@
#include "FileTransferData.h"
typedef struct
{
CHAR partition;
UINT driverType;
UINT64 freeBytes;
UINT64 totalBytes;
} MDISK_INFO;
typedef ItemList<MDISK_INFO, NO_UNINIT> MDiskInfoList;
typedef struct MFILE_INFO
{
WCHAR filename[MAX_PATH];
DWORD dwAttributes;
UINT64 filesize;
FILETIME lastWriteTime;
BOOL IsDir() const
{
return (FILE_ATTRIBUTE_DIRECTORY & dwAttributes);
}
bool operator<(const MFILE_INFO& another) const
{
if (! IsDir() && another.IsDir()) return false;
else if (IsDir() && ! another.IsDir()) return true;
else
{
int iCmp = _wcsicmp(filename, another.filename);
if (iCmp < 0) return true;
else return false;
}
}
} MFILE_INFO;
typedef ItemList<MFILE_INFO, NO_UNINIT> MFileInfoList;
typedef std::map<std::string,int> PORT_MAP;
//ÏûÏ¢´«ÊäÐÅÏ¢
typedef struct
{
MSGSERIALID serial;
BOOL bToClient;
TCHAR desc[1024];
} RC_MSG_INFO;
typedef ItemList<RC_MSG_INFO, NO_UNINIT> RcMsgInfoList;
typedef ItemList<TRANS_STATUS, NO_UNINIT> TransferInfoList;
//Shell相关接口
MASTER2_API BOOL OpenShell(LPCWSTR clientid, FnRemoteCmdOutput fnRemoteCmdOutput, LPVOID lpParameter);
@ -80,13 +34,16 @@ MASTER2_API BOOL PutFileToClient(LPCTSTR clientid,LPCTSTR serverpath,LPCTSTR cli
MASTER2_API BOOL GetFileToServer(LPCTSTR clientid,LPCTSTR clientpath,LPCTSTR serverpath);
MASTER2_API BOOL StopFileTransfer(LPCTSTR clientid,LPCTSTR serverpath);
MASTER2_API BOOL StopFileTransfer( LPCTSTR clientid ,TRANS_STATUS& status );
MASTER2_API BOOL StartFileTransfer(LPCTSTR clientid,LPCTSTR serverpath);
MASTER2_API BOOL StartFileTransfer( LPCTSTR clientid ,TRANS_STATUS& status );
MASTER2_API BOOL DeleteFileTransfer( LPCTSTR clientid ,TRANS_STATUS& status );
MASTER2_API BOOL IsHasStop ( LPCTSTR clientid ,TRANS_STATUS& status );
typedef void (*FnQueryTrans)(LPCTSTR clientid,TRANS_STATUS status,LPVOID lpParameter);
MASTER2_API void QueryFileTransferStatus(LPCTSTR clientid,TransferInfoList* list);
MASTER2_API void QueryTransferStatus(LPCTSTR clientid,FnQueryTrans fn,LPVOID lpParameter);
MASTER2_API void DeleteRemoteFile(LPCTSTR clientid,LPCTSTR clientpath);
@ -94,11 +51,6 @@ MASTER2_API void DeleteRemoteFile(LPCTSTR clientid,LPCTSTR clientpath);
MASTER2_API void RunRemoteFile(LPCTSTR clientid,LPCTSTR clientpath);
//文件浏览相关接口
MASTER2_API BOOL ListDisks(LPCWSTR clientid, MDiskInfoList* pDiskInfoList);
MASTER2_API BOOL ListFiles(LPCWSTR clientid, LPCWSTR findstr, MFileInfoList* pFileInfoList);
MASTER2_API void AsynListFiles( LPCTSTR clientid, LPCTSTR findstr,BOOL isClient, LPVOID lpParameter);
MASTER2_API void AsynListDisks( LPCWSTR clientid,BOOL isClient, LPVOID lpParameter );