mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-21 23:13:08 +08:00
Improve: Change zstd compression options for some dialog
This commit is contained in:
@@ -2614,11 +2614,13 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
break;
|
||||
}
|
||||
case TOKEN_DRIVE_LIST_PLUGIN: { // 文件管理【x】
|
||||
ContextObject->EnableZstdContext(6);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENFILEMGRDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
case TOKEN_BITMAPINFO_HIDE: { // 虚拟桌面【x】
|
||||
ContextObject->SetNoDelay(TRUE);
|
||||
ContextObject->EnableZstdContext(-1);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENHIDESCREENDLG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
@@ -2644,10 +2646,12 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject)
|
||||
}
|
||||
case TOKEN_BITMAPINFO: { // 远程桌面【x】
|
||||
ContextObject->SetNoDelay(TRUE);
|
||||
ContextObject->EnableZstdContext(-1);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENSCREENSPYDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
case TOKEN_DRIVE_LIST: { // 文件管理【x】
|
||||
ContextObject->EnableZstdContext(6);
|
||||
g_2015RemoteDlg->SendMessage(WM_OPENFILEMANAGERDIALOG, 0, (LPARAM)ContextObject);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ END_MESSAGE_MAP()
|
||||
// CFileManagerDlg message handlers
|
||||
|
||||
|
||||
int GetIconIndex(LPCTSTR lpFileName, DWORD dwFileAttributes)
|
||||
int GetIconIndex_(LPCTSTR lpFileName, DWORD dwFileAttributes)
|
||||
{
|
||||
SHFILEINFO sfi = {};
|
||||
if (dwFileAttributes == INVALID_FILE_ATTRIBUTES)
|
||||
@@ -160,6 +160,15 @@ int GetIconIndex(LPCTSTR lpFileName, DWORD dwFileAttributes)
|
||||
return sfi.iIcon;
|
||||
}
|
||||
|
||||
int GetIconIndex(LPCTSTR lpFileName, DWORD dwFileAttributes)
|
||||
{
|
||||
VLDGlobalDisable();
|
||||
// 代码中排除: Windows.Storage.dll 内部缓存,不是代码泄漏,是误报。
|
||||
int index = GetIconIndex_(lpFileName, dwFileAttributes);
|
||||
VLDGlobalEnable();
|
||||
return index;
|
||||
}
|
||||
|
||||
BOOL CFileManagerDlg::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
@@ -551,7 +551,7 @@ BOOL WriteContextData(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOr
|
||||
ContextObject->Encode(szBuffer, ulOriginalLength);
|
||||
if (!m_Cctx) ContextObject->Encode(szBuffer, ulOriginalLength, usingZstd);
|
||||
size_t iRet = usingZstd ?
|
||||
Mcompress(CompressedBuffer, &ulCompressedLength, (LPBYTE)szBuffer, ulOriginalLength):
|
||||
Mcompress(CompressedBuffer, &ulCompressedLength, (LPBYTE)szBuffer, ulOriginalLength, ContextObject->GetZstdLevel()):
|
||||
compress(CompressedBuffer, &ulCompressedLength, (LPBYTE)szBuffer, ulOriginalLength);
|
||||
|
||||
if (usingZstd ? C_FAILED(iRet) : (S_OK != iRet)) {
|
||||
@@ -575,7 +575,7 @@ BOOL WriteContextData(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOr
|
||||
|
||||
BOOL IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffer, size_t ulOriginalLength)
|
||||
{
|
||||
if (WriteContextData(ContextObject, szBuffer, ulOriginalLength)) {
|
||||
if (WriteContextData(ContextObject, szBuffer, ulOriginalLength, ContextObject->Zcctx)) {
|
||||
OVERLAPPEDPLUS* OverlappedPlus = new OVERLAPPEDPLUS(IOWrite);
|
||||
BOOL bOk = PostQueuedCompletionStatus(m_hCompletionPort, 0, (ULONG_PTR)ContextObject, &OverlappedPlus->m_ol);
|
||||
if ( (!bOk && GetLastError() != ERROR_IO_PENDING) ) { //如果投递失败
|
||||
|
||||
@@ -30,23 +30,6 @@ inline int z_uncompress(z_stream* strm, Bytef* dest, uLongf* destLen, const Byte
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ZSTD
|
||||
#include "zstd/zstd.h"
|
||||
#ifdef _WIN64
|
||||
#pragma comment(lib, "zstd/zstd_x64.lib")
|
||||
#else
|
||||
#pragma comment(lib, "zstd/zstd.lib")
|
||||
#endif
|
||||
#define C_FAILED(p) ZSTD_isError(p)
|
||||
#define C_SUCCESS(p) (!C_FAILED(p))
|
||||
#define ZSTD_CLEVEL 5
|
||||
|
||||
#define Mcompress(dest, destLen, source, sourceLen) m_Cctx ? ZSTD_compress2(m_Cctx, dest, *(destLen), source, sourceLen):\
|
||||
ZSTD_compress(dest, *(destLen), source, sourceLen, ZSTD_CLEVEL_DEFAULT)
|
||||
|
||||
#define Muncompress(dest, destLen, source, sourceLen) m_Dctx ? ZSTD_decompressDCtx(m_Dctx, dest, *(destLen), source, sourceLen):\
|
||||
ZSTD_decompress(dest, *(destLen), source, sourceLen)
|
||||
|
||||
class IOCPServer : public Server
|
||||
{
|
||||
protected:
|
||||
|
||||
@@ -16,6 +16,22 @@
|
||||
std::string GetPeerName(SOCKET sock);
|
||||
std::string GetRemoteIP(SOCKET sock);
|
||||
|
||||
// ZSTD
|
||||
#include "zstd/zstd.h"
|
||||
#ifdef _WIN64
|
||||
#pragma comment(lib, "zstd/zstd_x64.lib")
|
||||
#else
|
||||
#pragma comment(lib, "zstd/zstd.lib")
|
||||
#endif
|
||||
#define C_FAILED(p) ZSTD_isError(p)
|
||||
#define C_SUCCESS(p) (!C_FAILED(p))
|
||||
|
||||
#define Mcompress(dest, destLen, source, sourceLen, level) m_Cctx ? ZSTD_compress2(m_Cctx, dest, *(destLen), source, sourceLen):\
|
||||
ZSTD_compress(dest, *(destLen), source, sourceLen, level)
|
||||
|
||||
#define Muncompress(dest, destLen, source, sourceLen) m_Dctx ? ZSTD_decompressDCtx(m_Dctx, dest, *(destLen), source, sourceLen):\
|
||||
ZSTD_decompress(dest, *(destLen), source, sourceLen)
|
||||
|
||||
enum {
|
||||
ONLINELIST_IP = 0, // IP的列顺序
|
||||
ONLINELIST_ADDR, // 地址
|
||||
@@ -364,6 +380,10 @@ public:
|
||||
FreeDecompressBuffer();
|
||||
FreeCompressBuffer();
|
||||
FreeSendCompressBuffer();
|
||||
if (Zcctx) {
|
||||
ZSTD_freeCCtx(Zcctx);
|
||||
Zcctx = nullptr;
|
||||
}
|
||||
}
|
||||
CString sClientInfo[ONLINELIST_MAX];
|
||||
CString additonalInfo[RES_MAX];
|
||||
@@ -398,7 +418,27 @@ public:
|
||||
// 预分配的发送压缩缓冲区(发送时压缩后)
|
||||
PBYTE SendCompressBuffer = nullptr;
|
||||
ULONG SendCompressBufferSize = 0;
|
||||
int CompressLevel = ZSTD_CLEVEL_DEFAULT;
|
||||
ZSTD_CCtx* Zcctx = nullptr;
|
||||
|
||||
void EnableZstdContext(int level = ZSTD_CLEVEL_DEFAULT) {
|
||||
CAutoCLock L(SendLock);
|
||||
CompressLevel = level;
|
||||
if (Zcctx == nullptr) {
|
||||
Zcctx = ZSTD_createCCtx();
|
||||
ZSTD_CCtx_setParameter(Zcctx, ZSTD_c_compressionLevel, level);
|
||||
}
|
||||
}
|
||||
void SetCompressionLevel(int level) {
|
||||
CAutoCLock L(SendLock);
|
||||
CompressLevel = level;
|
||||
if (Zcctx) {
|
||||
ZSTD_CCtx_setParameter(Zcctx, ZSTD_c_compressionLevel, level);
|
||||
}
|
||||
}
|
||||
int GetZstdLevel() const {
|
||||
return CompressLevel;
|
||||
}
|
||||
// 获取或分配解压缩缓冲区
|
||||
PBYTE GetDecompressBuffer(ULONG requiredSize)
|
||||
{
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
#ifndef VLD_RPTHOOK_REMOVE
|
||||
#error 检测内存泄漏,需安装VLD;否则请注释#include "vld.h",或使用Release编译
|
||||
#endif
|
||||
#else
|
||||
#define VLDGlobalDisable()
|
||||
#define VLDGlobalEnable()
|
||||
#endif
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
Reference in New Issue
Block a user