📄 cmd_file.cpp
字号:
} while(dwLen-6==dwBytes);
// IssueAuthCommandReply(cas_from,comid,0,"<<EOF>>");
free(pData);
free(svLine);
CloseHandle(hFile);
return 0;
}
int CmdProc_FileRename(char *strResFile, char *strTagFile)
{
CMainFrame *pMainWnd = (CMainFrame *)AfxGetApp ()->m_pMainWnd;
if(GetFileAttributes(strResFile)&FILE_ATTRIBUTE_DIRECTORY)
{
char svSrc[260];
lstrcpyn(svSrc,strResFile,259);
svSrc[lstrlen(svSrc)+1]='\0';
char svDst[260];
lstrcpyn(svDst,strTagFile,259);
svDst[lstrlen(svDst)+1]='\0';
SHFILEOPSTRUCT shfos;
memset(&shfos,0,sizeof(SHFILEOPSTRUCT));
shfos.hwnd=NULL;
shfos.wFunc=FO_MOVE;
shfos.pFrom=svSrc;
shfos.pTo=svDst;
shfos.fFlags=FOF_NOCONFIRMATION|FOF_NOCONFIRMMKDIR|FOF_NOERRORUI|FOF_RENAMEONCOLLISION|FOF_SILENT;
if(SHFileOperation(&shfos)!=0)
{
pMainWnd->SendStringMsg ("Could not move/rename directory.");
// IssueAuthCommandReply(cas_from,comid,0,"Could not move/rename directory.");
return 1;
}
}
else
{
if(MoveFile(strResFile,strTagFile)==0)
{
pMainWnd->SendStringMsg ("Could not move/rename file.");
// IssueAuthCommandReply(cas_from,comid,0,"Could not move/rename file.");
return 1;
}
}
pMainWnd->SendStringMsg ("File moved/renamed.");
// IssueAuthCommandReply(cas_from,comid,0,"File moved/renamed.");
return 0;
}
int CmdProc_FileCopy(char *strResFile, char *strTagFile)
{
CMainFrame *pMainWnd = (CMainFrame *)AfxGetApp ()->m_pMainWnd;
if(GetFileAttributes(strResFile)&FILE_ATTRIBUTE_DIRECTORY)
{
char svSrc[260];
lstrcpyn(svSrc,strResFile,259);
svSrc[lstrlen(svSrc)+1]='\0';
char svDst[260];
lstrcpyn(svDst,strTagFile,259);
svDst[lstrlen(svDst)+1]='\0';
SHFILEOPSTRUCT shfos;
memset(&shfos,0,sizeof(SHFILEOPSTRUCT));
shfos.hwnd=NULL;
shfos.wFunc=FO_COPY;
shfos.pFrom=svSrc;
shfos.pTo=svDst;
shfos.fFlags=FOF_NOCONFIRMATION|FOF_NOCONFIRMMKDIR|FOF_NOERRORUI|FOF_RENAMEONCOLLISION|FOF_SILENT;
if(SHFileOperation(&shfos)!=0)
{
// IssueAuthCommandReply(cas_from,comid,0,"Could not copy directory.");
return 1;
}
}
else
{
if(CopyFile(strResFile,strTagFile,FALSE)==0)
{
// IssueAuthCommandReply(cas_from,comid,0,"Could not copy file.");
return 1;
}
}
// IssueAuthCommandReply(cas_from,comid,0,"File copied.");
return 0;
}
int CmdProc_DirectoryMake(char *strPath)
{
if(CreateDirectory(strPath,NULL)==0)
{
// IssueAuthCommandReply(cas_from,comid,0,"Could not create directory.");
return 1;
}
// IssueAuthCommandReply(cas_from,comid,0,"Directory created.");
return 0;
}
int CmdProc_DirectoryDelete(char *strPath)
{
if(GetFileAttributes(strPath)&FILE_ATTRIBUTE_DIRECTORY)
{
char svSrc[260];
lstrcpyn(svSrc,strPath,259);
svSrc[lstrlen(svSrc)+1]='\0';
SHFILEOPSTRUCT shfos;
memset(&shfos,0,sizeof(SHFILEOPSTRUCT));
shfos.hwnd=GetDesktopWindow();
shfos.wFunc=FO_DELETE;
shfos.pFrom=svSrc;
shfos.fFlags=FOF_NOCONFIRMATION|FOF_NOCONFIRMMKDIR|FOF_NOERRORUI|FOF_RENAMEONCOLLISION|FOF_SILENT;
if(SHFileOperation(&shfos)!=0)
{
// IssueAuthCommandReply(cas_from,comid,0,"Could not delete directory.");
return 1;
}
}
else
{
// IssueAuthCommandReply(cas_from,comid,0,"Could not delete. Not a directory.");
return 1;
}
// IssueAuthCommandReply(cas_from,comid,0,"Directory removed.");
return 0;
}
int CmdProc_SetFileAttr(char *strFile, char *strAttr)
{
DWORD dwAttr;
int i,count;
if(strAttr==NULL || strFile==NULL)
{
// IssueAuthCommandReply(cas_from,comid,0,"Could not change attributes. Invalid parameters.");
return -1;
}
dwAttr=0;
count=lstrlen(strAttr);
for(i=0;i<count;i++) {
if(strAttr[i]=='A' || strAttr[i]=='a') dwAttr|=FILE_ATTRIBUTE_ARCHIVE;
if(strAttr[i]=='H' || strAttr[i]=='h') dwAttr|=FILE_ATTRIBUTE_HIDDEN;
if(strAttr[i]=='S' || strAttr[i]=='s') dwAttr|=FILE_ATTRIBUTE_SYSTEM;
if(strAttr[i]=='R' || strAttr[i]=='r') dwAttr|=FILE_ATTRIBUTE_READONLY;
if(strAttr[i]=='T' || strAttr[i]=='t') dwAttr|=FILE_ATTRIBUTE_TEMPORARY;
}
if(SetFileAttributes(strFile,dwAttr)==0)
{
// IssueAuthCommandReply(cas_from,comid,0,"Could not change attributes.");
return -1;
}
// IssueAuthCommandReply(cas_from,comid,0,"Attributes changed.");
return 0;
}
*/
int CmdProc_ReceiveFile(char *strFile, CWSocket *lpWSK)
{
CFile fp;
char *lpFileData;
DWORD dwFileSize, nCell = 64*1024, nCell2;
CFileException e;
SENDMSG tagSendMsg;
int nRC = fp.Open (strFile,CFile::modeRead,&e);
if (nRC == 0) return -1;
/* dwFileSize = fp.GetLength ();
lpFileData = GlobalAlloc (GMEM_FIXED,dwFileSize);
if (lpFileData == NULL)
return NULL;
fp.ReadHuge (lpFileData,dwFileSize);
fp.Close ();
return lpFileData;
*/
dwFileSize = fp.GetLength ();
//lpFileData = GlobalAlloc (GMEM_FIXED,dwFileSize);
lpFileData = new char[nCell];
if (lpFileData == NULL) return FALSE;
tagSendMsg.wCmd = CMD_FILE_RECEIVE;
tagSendMsg.dwFileSize = dwFileSize;
tagSendMsg.dwBmpSize = nCell;
//图象头信息
if(lpWSK->SendData((char *)&tagSendMsg, sizeof(SENDMSG), 60) < 0)
goto err01;
while (dwFileSize > 0 )
{
if(dwFileSize >(DWORD) nCell)
nCell2 = nCell;
else
nCell2 = dwFileSize;
fp.ReadHuge (lpFileData,nCell2);
if(lpWSK->SendData((char *)lpFileData, nCell2, 60) < 0)
goto err01;
dwFileSize -= nCell2;
}//end for
if(lpFileData) delete lpFileData;
fp.Close ();
return 0;
err01:
if(lpFileData) delete lpFileData;
fp.Close ();
return -1;
}
int CmdProc_SendFile(char *strFile, CWSocket *lpWSK)
{
CFile fp;
DWORD dwFileSize, nCell, nCell2;
CFileException e;
char *lpFileData;
SENDMSG tagSendMsg;
int nRC = fp.Open (strFile,CFile::modeCreate | CFile::modeWrite,&e);
if (nRC == 0) return -1;
if( ReadSafe(lpWSK, (char *)&tagSendMsg, sizeof(SENDMSG)) < 0)
goto err01;
if (tagSendMsg.wCmd != CMD_FILE_RECEIVE)
goto err01;
dwFileSize = tagSendMsg.dwFileSize;
nCell = tagSendMsg.dwBmpSize ;
lpFileData = new char[dwFileSize];
if (lpFileData == NULL) return -1;
while (dwFileSize > 0 )
{
if(dwFileSize >(DWORD) nCell)
nCell2 = nCell;
else
nCell2 = dwFileSize;
if(ReadSafe(lpWSK,(char *)lpFileData, nCell2) < 0)
goto err01;
fp.WriteHuge (lpFileData,nCell2);
dwFileSize -= nCell2;
}//end for
if(lpFileData) delete lpFileData;
fp.Close ();
return 0;
err01:
if(lpFileData) delete lpFileData;
fp.Close ();
return -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -