📄 queuectrl.cpp
字号:
{
if (iter->priority==2 && !iter->bActive)
iter->priority = 1;
}
if (m_nProcessQueue && m_QueueItems.size())
{
for (iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
{
if (iter->bActive)
iter->priority = 2;
else
break;
}
if (!m_nActiveCount)
if (((CFtpListCtrl *)pMainFrame->GetFtpPane()->GetListCtrl())->HasUnsureEntries())
pMainFrame->m_pCommandQueue->List(FZ_LIST_USECACHE|FZ_LIST_EXACT);
}
else
{
if (((CFtpListCtrl *)pMainFrame->GetFtpPane()->GetListCtrl())->HasUnsureEntries())
pMainFrame->m_pCommandQueue->List(FZ_LIST_USECACHE|FZ_LIST_EXACT);
}
RedrawItems(0, m_QueueItems.size() + m_nActiveCount);
m_nProcessQueue = 0;
if (bCancelMainTransfer)
pMainFrame->m_pCommandQueue->Cancel();
}
void CQueueCtrl::Export()
{
CFileDialog dlg(FALSE, _T("xml"), _T("Transfer Queue"), OFN_OVERWRITEPROMPT, _T("XML files (*.xml)|*.xml||"), this);
if (dlg.DoModal()!=IDOK)
return;
CMarkupSTL markup;
markup.AddElem( _T("FileZilla") );
markup.AddChildElem( _T("TransferQueue") );
markup.IntoElem();
for (t_QueueVector::const_iterator iter = m_QueueItems.begin(); iter != m_QueueItems.end(); iter++)
{
if (!iter->priority && !iter->bPaused)
break;
markup.AddChildElem( _T("QueueItem") );
markup.IntoElem();
markup.AddChildElem( _T("File") );
markup.AddChildAttrib( _T("Localfile"), iter->transferFile.localfile);
markup.AddChildAttrib( _T("Size"), iter->transferFile.size);
markup.AddChildAttrib( _T("Remotefile"), iter->transferFile.remotefile);
markup.AddChildAttrib( _T("Remotepath"), iter->transferFile.remotepath.GetSafePath());
markup.AddChildElem( _T("Data") );
markup.AddChildAttrib( _T("Transfermode"), iter->transferFile.nType);
markup.AddChildAttrib( _T("Get"), iter->transferFile.get?1:0);
markup.AddChildAttrib( _T("RetryCount"), iter->retrycount);
markup.AddChildAttrib( _T("Open"), iter->nOpen);
COptions::SaveServer(&markup, iter->transferFile.server);
markup.OutOfElem();
}
if (!markup.Save(dlg.GetPathName()))
{
CString str;
str.Format(IDS_ERRORMSG_FILEOPENFAILED,dlg.GetPathName());
AfxMessageBox(str,MB_ICONEXCLAMATION);
return;
}
}
void CQueueCtrl::Import()
{
CFileDialog dlg(TRUE, _T("xml"), _T("Transfer Queue"), OFN_FILEMUSTEXIST, _T("XML files (*.xml)|*.xml|Text files (*.txt)|*.txt||"), this);
if (dlg.DoModal()!=IDOK)
return;
//First try to load the file as XML file
CMarkupSTL markup;
if (markup.Load(dlg.GetPathName()))
{
if (markup.FindChildElem( _T("TransferQueue") ))
{
markup.IntoElem();
while (markup.FindChildElem( _T("QueueItem") ))
{
markup.IntoElem();
t_transferfile transferfile;
if (!markup.FindChildElem( _T("File") ))
{
markup.OutOfElem();
continue;
}
transferfile.localfile=markup.GetChildAttrib( _T("Localfile") );
transferfile.remotefile=markup.GetChildAttrib( _T("Remotefile") );
transferfile.remotepath.SetSafePath(markup.GetChildAttrib( _T("Remotepath") ));
transferfile.size=_ttoi64(markup.GetChildAttrib( _T("Size") ));
markup.ResetChildPos();
if (!markup.FindChildElem( _T("Data") ))
{
markup.OutOfElem();
continue;
}
CQueueData queueData;
queueData.retrycount=_ttoi(markup.GetChildAttrib( _T("RetryCount") ));
transferfile.nType=_ttoi(markup.GetChildAttrib( _T("Transfermode") ));
transferfile.get=_ttoi(markup.GetChildAttrib( _T("Get") ));
queueData.nOpen=_ttoi(markup.GetChildAttrib( _T("Open") ));
markup.ResetChildPos();
if (!COptions::LoadServer(&markup, transferfile.server))
{
markup.OutOfElem();
continue;
}
markup.OutOfElem();
if (transferfile.localfile=="" || transferfile.remotefile=="" || transferfile.remotepath.IsEmpty())
{
AfxMessageBox( _T("Error, can't reload queue item!") );
}
else
{
queueData.transferFile = transferfile;
int index2=AddItem(queueData);
}
}
markup.OutOfElem();
markup.RemoveChildElem();
}
else
{
CString str;
str.Format(IDS_ERRORMSG_FILEOPENFAILED,dlg.GetPathName());
AfxMessageBox(str,MB_ICONEXCLAMATION);
return;
}
return;
}
//Loading file as XML file failed, now try to load it as text file
CFile file;
if (!file.Open(dlg.GetPathName(), CFile::modeRead|CFile::shareDenyWrite))
{
CString str;
str.Format(IDS_ERRORMSG_FILEOPENFAILED,dlg.GetPathName());
AfxMessageBox(str,MB_ICONEXCLAMATION);
return;
}
CArchive ar(&file,CArchive::load);
CString str;
while (ar.ReadString(str))
{
if (str=="")
continue;
CString name, folder="\\";
t_transferfile transferfile;
CQueueData queueData;
transferfile.get = TRUE;
do
{
if (str=="")
break;
if (str.Left(15)=="Transfer type: ")
{
str=str.Mid(15);
if (str=="Upload")
transferfile.get=FALSE;
else if (str=="Download")
transferfile.get=TRUE;
else
{
AfxMessageBox(IDS_ERRORMSG_CANTIMPORTFILE, MB_ICONSTOP);
file.Close();
return;
}
}
else if (str.Left(12)=="Local file: ")
{
str=str.Mid(12);
transferfile.localfile=str;
}
else if (str.Left(6)=="Size: ")
{
str=str.Mid(6);
transferfile.size=_ttoi64(str);
}
else if (str.Left(13)=="Remote file: ")
{
str=str.Mid(13);
transferfile.remotefile=str;
}
else if (str.Left(13)=="Remote path: ")
{
str=str.Mid(13);
if (!transferfile.remotepath.SetSafePath(str))
{
AfxMessageBox(IDS_ERRORMSG_CANTIMPORTFILE,MB_ICONSTOP);
file.Close();
return;
}
}
else if (str.Left(15)=="Transfer mode: ")
{
str=str.Mid(15);
transferfile.nType=_ttoi(str);
}
else if (str.Left(13)=="Server Type: ")
{
str=str.Mid(13);
transferfile.server.nServerType=_ttoi(str);
}
else if (str.Left(6)=="Host: ")
{
str=str.Mid(6);
transferfile.server.host=str;
}
else if (str.Left(6)=="Port: ")
{
str=str.Mid(6);
transferfile.server.port=_ttoi(str);
}
else if (str.Left(6)=="User: ")
{
str=str.Mid(6);
transferfile.server.user=str;
}
else if (str.Left(6)=="Pass: ")
{
str=str.Mid(6);
transferfile.server.pass=CCrypt::decrypt(str);
}
else if (str.Left(17)=="Firewall Bypass: ")
{
str=str.Mid(17);
transferfile.server.fwbypass=_ttoi(str);
}
else if (str.Left(21)=="Open after transfer: ")
{
str=str.Mid(21);
queueData.nOpen=_ttoi(str);
}
} while (ar.ReadString(str));
if (transferfile.localfile=="" || transferfile.remotefile=="" || transferfile.remotepath.IsEmpty() ||
transferfile.server.host=="" || transferfile.server.port<1 || transferfile.server.port>65535 || transferfile.server.user=="")
{
file.Close();
AfxMessageBox(IDS_ERRORMSG_CANTIMPORTFILE,MB_ICONSTOP);
return;
}
queueData.transferFile = transferfile;
AddItem(queueData);
}
CString msg;
msg.Format(IDS_STATUSMSG_FILEIMPORTED,dlg.GetPathName());
AfxMessageBox(msg,MB_ICONINFORMATION);
}
void CQueueCtrl::EditFile(const CQueueData &queueData)
{
if (queueData.nOpen==3)
{
//Delete file
DeleteFile(queueData.transferFile.localfile);
}
else if (queueData.nOpen==1 || queueData.nOpen==2)
{
DWORD ThreadID;
CQueueData *pQueueData = new CQueueData;
*pQueueData = queueData;
pQueueData->pTransferStatus = 0;
pQueueData->pProgressControl = 0;
HANDLE hThreadHandle;
DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &hThreadHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
pQueueData->retrycount = (int)hThreadHandle;
CreateThread(0, 0, ViewEditThreadProc, pQueueData, 0, &ThreadID);
}
}
DWORD CQueueCtrl::ViewEditThreadProc(LPVOID lpParameter)
{
ASSERT(lpParameter);
CQueueData *pQueueData = reinterpret_cast<CQueueData *>(lpParameter);
CString file = pQueueData->transferFile.localfile;
CFileStatus64 status;
if (!GetStatus64(pQueueData->transferFile.localfile, status))
{
CloseHandle((HANDLE)pQueueData->retrycount);
delete pQueueData;
AfxMessageBox(_T("Internal error, unable to find downloaded file"), MB_ICONEXCLAMATION);
return 0;
}
LPTSTR str;
if (pQueueData->nOpen==1)
{
/* CString cmdLine;
if (file.Find( _T(" ") )!=-1)
file=_T("\"") + file + _T("\"");
PROCESS_INFORMATION ProcessInformation;
STARTUPINFO startupinfo={0};
startupinfo.cb=sizeof(startupinfo);
str=new TCHAR[file.GetLength()+1];
_tcscpy(str, file);
if (CreateProcess(0, str, 0, 0, 0, 0, 0, 0, &startupinfo, &ProcessInformation))
{
CloseHandle(ProcessInformation.hThread);
HANDLE handles[2];
handles[0]=(HANDLE)reinterpret_cast<CQueueData *>(pTransferFile->lpParam)->retrycount;
handles[1]=ProcessInformation.hProcess;
int res=WaitForMultipleObjects(2, handles, FALSE, INFINITE);
if (res==(WAIT_OBJECT_0+1) || res==(WAIT_ABANDONED_0+1))
{
CFileStatus64 statusnew;
if (GetStatus64(pTransferFile->localfile, statusnew))
{
if (statusnew.m_mtime!=status.m_mtime || statusnew.m_size!=status.m_size || statusnew.m_attribute!=status.m_attribute)
{
delete [] str;
CloseHandle((HANDLE)reinterpret_cast<CQueueData *>(pTransferFile->lpParam)->retrycount);
if (!AfxGetMainWnd()->PostMessage(WM_APP + 10, reinterpret_cast<WPARAM>(pTransferFile), 0))
{
delete reinterpret_cast<CQueueData*>(pTransferFile->lpParam);
delete pTransferFile;
DeleteFile(pTransferFile->localfile);
}
return 0;
}
else
DeleteFile(pTransferFile->localfile);
}
else
DeleteFile(pTransferFile->localfile);
}
}
else
{
CString str;
str.Format(IDS_ERRORMSG_VIEWEDIT_CANTOPENFILE, pTransferFile->localfile);
AfxMessageBox(str, MB_ICONEXCLAMATION, 0);
DeleteFile(pTransferFile->localfile);
}*/
}
else if (pQueueData->nOpen == 2)
{
int pos=file.ReverseFind('.');
if (pos!=-1)
{
CString fext=file.Mid(pos+1);
fext.MakeLower();
//Parse the file associations
CString CustomAssociations = COptions::GetOption(OPTION_VIEWEDITCUSTOM);
CString ext;
CString prog;
BOOL bDoExt=TRUE;
while (CustomAssociations!="")
{
int pos=CustomAssociations.Find( _T(";") );
if (bDoExt)
{
if (!pos || pos==-1 || pos==CustomAssociations.GetLength()-1)
break;
ext+=CustomAssociations.Left(pos);
CustomAssociations=CustomAssociations.Mid(pos+1);
if (CustomAssociations.Left(1)== _T(" "))
{
ext+=_T(";");
CustomAssociations=CustomAssociations.Mid(1);
}
else
bDoExt=FALSE;
}
else
{
if (!pos || pos==CustomAssociations.GetLength()-1)
break;
if (pos!=-1)
{
prog += CustomAssociations.Left(pos);
CustomAssociations=CustomAssociations.Mid(pos+1);
}
else
{
prog = CustomAssociations;
CustomAssociations="";
}
if (CustomAssociations.Left(1)== _T(" "))
{
prog+=_T(";");
CustomAssociations=CustomAssociations.Mid(1);
if (CustomAssociations!="")
continue;
}
ext.MakeLower();
if (fext==ext)
{ //We've found a file aassociation for this extension
CString cmdLine;
if (file.Find( _T(" ") )!=-1)
file=_T("\"") + file + _T("\"");
cmdLine=prog + _T(" ") + file;
PROCESS_INFORMATION ProcessInformation;
STARTUPINFO startupinfo={0};
startupinfo.cb=sizeof(startupinfo);
LPTSTR str=new TCHAR[cmdLine.GetLength()+1];
_tcscpy(str, cmdLine);
if (CreateProcess(0, str, 0, 0, 0, 0, 0, 0, &startupinfo, &ProcessInformation))
{
CloseHandle(ProcessInformation.hThread);
HANDLE handles[2];
handles[0] = (HANDLE)pQueueData->retrycount;
handles[1] = ProcessInformation.hProcess;
int res = WaitForMultipleObjects(2, handles, FALSE, INFINITE);
if (res==(WAIT_OBJECT_0+1) || res==(WAIT_ABANDONED_0+1))
{
CFileStatus64 statusnew;
if (GetStatus64(pQueueData->transferFile.localfile, statusnew))
{
if ((statusnew.m_has_mtime && status.m_has_mtime && statusnew.m_mtime != status.m_mtime) || statusnew.m_size!=status.m_size || statusnew.m_attribute!=status.m_attribute)
{
delete [] str;
CloseHandle((HANDLE)pQueueData->retrycount);
CWnd *pWnd = AfxGetMainWnd();
if (!pWnd || !pWnd->PostMessage(WM_APP + 10, (WPARAM)pQueueData, 0))
{
DeleteFile(pQueueData->transferFile.localfile);
delete pQueueData;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -