Add an Open item atop the remote file list context menu: a single file is pulled back and previewed through the existing flow, a single folder navigates into its subdirectory, and multi-selection disables it. Files over the 8 MiB preview limit ask for confirmation; once confirmed the explicit-open path caps the first-packet size gate at the confirmed size and relaxes the hash query, total timeout and cache eviction so even very large files transfer and open. When preview is disabled the explicit Open shows a message instead of doing nothing. Double-click preview behavior is unchanged. Localize the new menu item and dialogs in en_US/zh_TW/de_DE. Co-Authored-By: Qoder
338 lines
13 KiB
C++
338 lines
13 KiB
C++
#if !defined(AFX_FILEMANAGERDLG_H__4918F922_13A4_4389_8027_5D4993A6DB91__INCLUDED_)
|
||
#define AFX_FILEMANAGERDLG_H__4918F922_13A4_4389_8027_5D4993A6DB91__INCLUDED_
|
||
#include "TrueColorToolBar.h" // Added by ClassView
|
||
#if _MSC_VER > 1000
|
||
#pragma once
|
||
#endif // _MSC_VER > 1000
|
||
|
||
#include "IOCPServer.h"
|
||
#include "SortListCtrl.h"
|
||
#include "../../common/locker.h"
|
||
#include <map>
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
#define CIOCPServer IOCPServer
|
||
|
||
#define ClientContext CONTEXT_OBJECT
|
||
|
||
typedef struct {
|
||
DWORD dwSizeHigh;
|
||
DWORD dwSizeLow;
|
||
} FILESIZE;
|
||
|
||
#define m_DeCompressionBuffer InDeCompressedBuffer
|
||
|
||
#define GetBufferLen GetBufferLength
|
||
|
||
#define m_Dialog hDlg
|
||
|
||
#define m_Socket sClientSocket
|
||
|
||
#define MAKEINT64(low, high) ((unsigned __int64)(((DWORD)(low)) | ((unsigned __int64)((DWORD)(high))) << 32))
|
||
|
||
#define MAX_WRITE_RETRY 15 // 重试写入文件次数
|
||
|
||
#define WM_MY_MESSAGE (WM_USER+300)
|
||
#define WM_LOCAL_SEARCH_DONE (WM_USER+302)
|
||
#define WM_LOCAL_SEARCH_PROGRESS (WM_USER+303)
|
||
#define WM_RECVFILEV2_CHUNK (WM_USER+304)
|
||
#define WM_RECVFILEV2_COMPLETE (WM_USER+305)
|
||
|
||
// FileManagerDlg.h : header file
|
||
//
|
||
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
// CFileManagerDlg dialog
|
||
typedef CList<CString, CString&> strList;
|
||
|
||
class CFileManagerDlg : public DialogBase
|
||
{
|
||
protected:
|
||
// 更新状态栏信息
|
||
afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam)
|
||
{
|
||
char *buff = (char*)lParam;
|
||
m_wndStatusBar.SetPaneText(0, buff);
|
||
delete[]buff;
|
||
return S_OK;
|
||
}
|
||
|
||
// Construction
|
||
public:
|
||
bool m_bIsStop;
|
||
CString m_strReceiveLocalFile;
|
||
HANDLE m_hRecvFile; // 接收文件的句柄,保持打开直到传输完成
|
||
CString m_strUploadRemoteFile;
|
||
void ShowProgress();
|
||
void SendStop();
|
||
int m_nTransferMode;
|
||
CString m_hCopyDestFolder;
|
||
void SendContinue();
|
||
void SendException();
|
||
void EndLocalRecvFile();
|
||
void EndRemoteDeleteFile();
|
||
CString m_strOperatingFile; // 文件名
|
||
__int64 m_nOperatingFileLength; // 文件总大小
|
||
__int64 m_nCounter;// 计数器
|
||
void WriteLocalRecvFile();
|
||
void CreateLocalRecvFile();
|
||
BOOL SendDownloadJob();
|
||
BOOL SendUploadJob();
|
||
BOOL SendDeleteJob();
|
||
void UpdateWindowsPos();
|
||
|
||
strList m_Remote_Download_Job;
|
||
strList m_Remote_Upload_Job;
|
||
strList m_Remote_Delete_Job;
|
||
CTrueColorToolBar m_wndToolBar_Local;
|
||
CTrueColorToolBar m_wndToolBar_Remote;
|
||
void ShowMessage(const char *lpFmt, ...);
|
||
CString m_Remote_Path;
|
||
BYTE m_bRemoteDriveList[1024];
|
||
CString GetParentDirectory(CString strPath);
|
||
void OnReceiveComplete();
|
||
|
||
int m_nNewIconBaseIndex; // 新加的ICON
|
||
|
||
CProgressCtrl* m_ProgressCtrl;
|
||
HCURSOR m_hCursor;
|
||
CString m_Local_Path;
|
||
bool FixedUploadDirectory(LPCTSTR lpPathName);
|
||
void FixedLocalDriveList();
|
||
void FixedRemoteDriveList();
|
||
void FixedLocalFileList(CString directory = "");
|
||
void GetRemoteFileList(CString directory = "");
|
||
void FixedRemoteFileList(BYTE *pbBuffer, DWORD dwBufferLen);
|
||
void FixedRemoteSearchFileList(BYTE *pbBuffer, DWORD dwBufferLen);
|
||
bool m_bSearching;
|
||
bool m_bSearchStopped;
|
||
int m_nSearchResultCount;
|
||
DWORD m_dwSearchStartTime;
|
||
CString m_strSearchPath;
|
||
CString m_strSearchName;
|
||
std::map<std::string, int> m_IconCache;
|
||
|
||
// 本地搜索
|
||
bool m_bLocalSearching;
|
||
bool m_bLocalSearchStopped;
|
||
int m_nLocalSearchResultCount;
|
||
DWORD m_dwLocalSearchStartTime;
|
||
CString m_strLocalSearchPath;
|
||
CString m_strLocalSearchName;
|
||
std::map<std::string, int> m_LocalIconCache;
|
||
HANDLE m_hLocalSearchThread;
|
||
|
||
// ---- 双击预览 ----
|
||
// 搜索结果列表与普通列表的列含义不同:普通列表第 3 列是修改日期,搜索结果是路径。
|
||
bool m_bLocalSearchResults = false;
|
||
bool m_bRemoteSearchResults = false;
|
||
struct RemoteMeta { uint64_t size = 0; uint64_t mtimeMs = 0; };
|
||
std::map<std::string, RemoteMeta> m_RemoteMeta; // key = 完整远程路径(GBK)
|
||
struct PendingHashPreview {
|
||
CString fullPath; // 空 = 没有待响应的哈希请求
|
||
uint64_t clientID = 0;
|
||
uint64_t size = 0;
|
||
uint64_t mtimeMs = 0;
|
||
};
|
||
PendingHashPreview m_pendingHash;
|
||
enum { kPreviewHashTimer = 0x51 };
|
||
afx_msg LRESULT OnPreviewResult(WPARAM wParam, LPARAM lParam);
|
||
afx_msg LRESULT OnPreviewHashResult(WPARAM wParam, LPARAM lParam);
|
||
#ifdef _DEBUG
|
||
// E2E 测试钩子:WM_APP+0x123,wParam=行号,lParam!=0 表示远程列表。
|
||
afx_msg LRESULT OnPreviewTest(WPARAM wParam, LPARAM lParam);
|
||
#endif
|
||
void BeginRemotePreview(const CString& fullPath, bool allowLarge = false);
|
||
void ContinueRemotePreview(const CString& fullPath, uint64_t size, uint64_t mtimeMs,
|
||
const std::string& sha256, bool allowLarge = false);
|
||
void OpenLocalPath(const CString& path);
|
||
bool GetRemoteFileMeta(const CString& fullPath, RemoteMeta& meta);
|
||
std::string GetPreviewClientKey(uint64_t clientID);
|
||
static DWORD WINAPI LocalSearchThreadProc(LPVOID lpParam);
|
||
void LocalSearchWorker();
|
||
static bool WildcardMatch(LPCTSTR pattern, LPCTSTR str);
|
||
|
||
struct LocalSearchItem {
|
||
CString fileName;
|
||
CString dir;
|
||
CString ext;
|
||
BOOL bIsDir;
|
||
DWORD sizeHigh, sizeLow;
|
||
FILETIME ftWrite;
|
||
};
|
||
afx_msg LRESULT OnLocalSearchDone(WPARAM wParam, LPARAM lParam);
|
||
afx_msg LRESULT OnLocalSearchProgress(WPARAM wParam, LPARAM lParam);
|
||
|
||
CStatusBar m_wndStatusBar;
|
||
CFileManagerDlg(CWnd* pParent = NULL, Server* pIOCPServer = NULL, ClientContext *pContext = NULL); // standard constructor
|
||
|
||
~CFileManagerDlg()
|
||
{
|
||
m_bLocalSearching = false;
|
||
m_bLocalSearchStopped = true;
|
||
if (m_hLocalSearchThread) {
|
||
// 处理消息避免SendMessage死锁
|
||
while (MsgWaitForMultipleObjects(1, &m_hLocalSearchThread, FALSE, 5000, QS_ALLINPUT) == WAIT_OBJECT_0 + 1) {
|
||
MSG msg;
|
||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
|
||
TranslateMessage(&msg);
|
||
DispatchMessage(&msg);
|
||
}
|
||
}
|
||
CloseHandle(m_hLocalSearchThread);
|
||
}
|
||
if (m_hRecvFile != INVALID_HANDLE_VALUE) {
|
||
CloseHandle(m_hRecvFile);
|
||
}
|
||
if(m_ProgressCtrl) delete m_ProgressCtrl;
|
||
}
|
||
// Dialog Data
|
||
//{{AFX_DATA(CFileManagerDlg)
|
||
enum { IDD = IDD_FILE };
|
||
CComboBox m_Remote_Directory_ComboBox;
|
||
CComboBox m_Local_Directory_ComboBox;
|
||
CSortListCtrl m_list_remote;
|
||
CSortListCtrl m_list_local;
|
||
//}}AFX_DATA
|
||
|
||
|
||
// Overrides
|
||
// ClassWizard generated virtual function overrides
|
||
//{{AFX_VIRTUAL(CFileManagerDlg)
|
||
public:
|
||
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
||
protected:
|
||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
|
||
virtual void PostNcDestroy();
|
||
//}}AFX_VIRTUAL
|
||
|
||
// Implementation
|
||
protected:
|
||
|
||
// Generated message map functions
|
||
//{{AFX_MSG(CFileManagerDlg)
|
||
virtual BOOL OnInitDialog();
|
||
afx_msg HCURSOR OnQueryDragIcon();
|
||
afx_msg void OnSize(UINT nType, int cx, int cy);
|
||
afx_msg void OnDblclkListLocal(NMHDR* pNMHDR, LRESULT* pResult);
|
||
afx_msg void OnBegindragListLocal(NMHDR* pNMHDR, LRESULT* pResult);
|
||
afx_msg void OnBegindragListRemote(NMHDR* pNMHDR, LRESULT* pResult);
|
||
afx_msg BOOL OnToolTipNotify(UINT id, NMHDR* pNMHDR, LRESULT* pResult);
|
||
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
|
||
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
|
||
afx_msg void OnTimer(UINT_PTR nIDEvent);
|
||
afx_msg void OnClose();
|
||
afx_msg void OnDblclkListRemote(NMHDR* pNMHDR, LRESULT* pResult);
|
||
afx_msg void OnLocalPrev();
|
||
afx_msg void OnRemotePrev();
|
||
afx_msg void OnLocalView();
|
||
afx_msg void OnLocalList();
|
||
afx_msg void OnLocalReport();
|
||
afx_msg void OnLocalBigicon();
|
||
afx_msg void OnLocalSmallicon();
|
||
afx_msg void OnRemoteBigicon();
|
||
afx_msg void OnRemoteList();
|
||
afx_msg void OnRemoteReport();
|
||
afx_msg void OnRemoteSmallicon();
|
||
afx_msg void OnRemoteView();
|
||
afx_msg void OnUpdateLocalStop(CCmdUI* pCmdUI);
|
||
afx_msg void OnUpdateRemoteStop(CCmdUI* pCmdUI);
|
||
afx_msg void OnUpdateLocalPrev(CCmdUI* pCmdUI);
|
||
afx_msg void OnUpdateRemotePrev(CCmdUI* pCmdUI);
|
||
afx_msg void OnUpdateLocalCopy(CCmdUI* pCmdUI);
|
||
afx_msg void OnUpdateRemoteCopy(CCmdUI* pCmdUI);
|
||
afx_msg void OnUpdateRemoteDelete(CCmdUI* pCmdUI);
|
||
afx_msg void OnUpdateRemoteNewfolder(CCmdUI* pCmdUI);
|
||
afx_msg void OnUpdateLocalDelete(CCmdUI* pCmdUI);
|
||
afx_msg void OnUpdateLocalNewfolder(CCmdUI* pCmdUI);
|
||
afx_msg void OnUpdateLocalSearch(CCmdUI* pCmdUI);
|
||
afx_msg void OnUpdateRemoteSearch(CCmdUI* pCmdUI);
|
||
afx_msg void OnRemoteCopy();
|
||
afx_msg void OnLocalCopy();
|
||
afx_msg void OnRemoteCompress();
|
||
afx_msg void OnLocalCompress();
|
||
afx_msg void OnRemoteUnCompress();
|
||
afx_msg void OnLocalUnCompress();
|
||
afx_msg void OnLocalDelete();
|
||
afx_msg void OnRemoteDelete();
|
||
afx_msg void OnRemoteStop();
|
||
afx_msg void OnLocalStop();
|
||
afx_msg void OnLocalNewfolder();
|
||
afx_msg void OnRemoteNewfolder();
|
||
afx_msg void OnTransfer();
|
||
afx_msg void OnRename();
|
||
afx_msg void OnEndlabeleditListLocal(NMHDR* pNMHDR, LRESULT* pResult);
|
||
afx_msg void OnEndlabeleditListRemote(NMHDR* pNMHDR, LRESULT* pResult);
|
||
afx_msg void OnDelete();
|
||
afx_msg void OnNewfolder();
|
||
afx_msg void OnRefresh();
|
||
afx_msg void OnLocalOpen();
|
||
afx_msg void OnRemoteOpenShow();
|
||
afx_msg void OnRemoteOpenHide();
|
||
afx_msg void OnRemoteOpenPreview();
|
||
afx_msg void OnRclickListLocal(NMHDR* pNMHDR, LRESULT* pResult);
|
||
afx_msg void OnRclickListRemote(NMHDR* pNMHDR, LRESULT* pResult);
|
||
afx_msg void OnLocalDesktop();
|
||
afx_msg void OnLocalDownloads();
|
||
afx_msg void OnLocalHome();
|
||
afx_msg void OnLocalSearch();
|
||
afx_msg void OnLocalHistory();
|
||
afx_msg void OnRemoteDesktop();
|
||
afx_msg void OnRemoteDownloads();
|
||
afx_msg void OnRemoteHome();
|
||
afx_msg void OnRemoteSearch();
|
||
afx_msg void OnRemoteHistory();
|
||
afx_msg void OnTransferV2ToRemote(); // V2: 本地文件传输到远程
|
||
afx_msg void OnTransferV2ToLocal(); // V2: 远程文件传输到本地
|
||
//}}AFX_MSG
|
||
DECLARE_MESSAGE_MAP()
|
||
|
||
protected:
|
||
CListCtrl* m_pDragList; //Which ListCtrl we are dragging FROM
|
||
CListCtrl* m_pDropList; //Which ListCtrl we are dropping ON
|
||
BOOL m_bDragging; //T during a drag operation
|
||
int m_nDragIndex; //Index of selected item in the List we are dragging FROM
|
||
int m_nDropIndex; //Index at which to drop item in the List we are dropping ON
|
||
CWnd* m_pDropWnd; //Pointer to window we are dropping on (will be cast to CListCtrl* type)
|
||
|
||
void DropItemOnList(CListCtrl* pDragList, CListCtrl* pDropList);
|
||
private:
|
||
bool m_bIsUpload; // 是否是把本地主机传到远程上,标志方向位
|
||
|
||
// V2 下载(远程→本地):FileManager 子连接的 NotifyProc 在 worker 线程上
|
||
// 直接调 OnReceiveComplete,不能在那里 new 进度框(窗口创建在 worker 线程
|
||
// 没有消息泵,PostMessage 投不出去)。把 chunk 数据拷贝出来 PostMessage 回
|
||
// 自己(UI 线程)处理,参考 ScreenSpyDlg 同样的模式。按 transferID 维护进度框。
|
||
std::map<uint64_t, std::pair<HWND, class CDlgFileSend*>> m_FileRecvDlgs;
|
||
afx_msg LRESULT OnRecvFileV2Chunk(WPARAM wParam, LPARAM lParam);
|
||
afx_msg LRESULT OnRecvFileV2Complete(WPARAM wParam, LPARAM lParam);
|
||
|
||
bool MakeSureDirectoryPathExists(LPCTSTR pszDirPath);
|
||
void SendTransferMode();
|
||
void SendFileData();
|
||
void EndLocalUploadFile();
|
||
bool DeleteDirectory(LPCTSTR lpszDirectory);
|
||
void EnableControl(BOOL bEnable = TRUE);
|
||
void CollectFilesRecursive(const std::string& dirPath, std::vector<std::string>& files);
|
||
float m_fScalingFactor;
|
||
|
||
// 传输目录历史:持久化在 THIS_CFG 的 [file_history] 节,MRU 列表最多 kTransferHistoryMax 条。
|
||
// 只有真正发起过文件传输的目录才记录(单纯浏览目录不算),见 RecordTransferHistory。
|
||
enum { kTransferHistoryMax = 10 };
|
||
static std::vector<CString> LoadTransferHistory(bool bLocal, uint64_t clientID);
|
||
static void PushTransferHistory(bool bLocal, uint64_t clientID, const CString& path);
|
||
void RecordTransferHistory();
|
||
|
||
// 获取有效的客户端ID(优先用 m_ClientID,否则通过 IP 找主连接)
|
||
uint64_t GetClientID() const;
|
||
public:
|
||
afx_msg void OnFilemangerCompress();
|
||
afx_msg void OnFilemangerUncompress();
|
||
};
|
||
|
||
//{{AFX_INSERT_LOCATION}}
|
||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
||
|
||
#endif // !defined(AFX_FILEMANAGERDLG_H__4918F922_13A4_4389_8027_5D4993A6DB91__INCLUDED_)
|