mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-21 23:13:08 +08:00
Fix #281: Check if CPU has SSE2 to avoid client crash
This commit is contained in:
@@ -17,6 +17,15 @@
|
||||
#include "X264Encoder.h"
|
||||
#include "common/file_upload.h"
|
||||
|
||||
inline bool HasSSE2() {
|
||||
#ifdef _DEBUG
|
||||
return false;
|
||||
#else
|
||||
auto static has = IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE);
|
||||
return has;
|
||||
#endif
|
||||
}
|
||||
|
||||
class ThreadPool
|
||||
{
|
||||
public:
|
||||
@@ -304,7 +313,7 @@ public:
|
||||
virtual ULONG CompareBitmap(LPBYTE CompareSourData, LPBYTE CompareDestData, LPBYTE szBuffer,
|
||||
DWORD ulCompareLength, BYTE algo, int startPostion = 0)
|
||||
{
|
||||
if (UsingDXGI())
|
||||
if (UsingDXGI() || !HasSSE2())
|
||||
return CompareBitmapDXGI(CompareSourData, CompareDestData, szBuffer, ulCompareLength, algo, startPostion);
|
||||
|
||||
LPBYTE p = szBuffer;
|
||||
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
// 9. 初始化 BITMAPINFO
|
||||
m_BitmapInfor_Full = ConstructBitmapInfo(32, m_ulFullWidth, m_ulFullHeight);
|
||||
iniFile cfg(CLIENT_PATH);
|
||||
int strategy = cfg.GetInt("settings", "ScreenStrategy", 0);
|
||||
int strategy = HasSSE2() ? cfg.GetInt("settings", "ScreenStrategy", 0) : 1;
|
||||
switch (strategy) {
|
||||
case 1:
|
||||
break;
|
||||
|
||||
@@ -332,6 +332,11 @@ BOOL IsRunningAsSystem()
|
||||
|
||||
BOOL CScreenManager::OnReconnect()
|
||||
{
|
||||
auto duration = GetTickCount64() - m_nReconnectTime;
|
||||
if (duration <= 3000)
|
||||
Sleep(3000 - duration);
|
||||
m_nReconnectTime = GetTickCount64();
|
||||
|
||||
m_SendFirst = FALSE;
|
||||
BOOL r = m_ClientObject ? m_ClientObject->Reconnect(this) : FALSE;
|
||||
Mprintf("CScreenManager OnReconnect '%s'\n", r ? "succeed" : "failed");
|
||||
|
||||
@@ -75,6 +75,7 @@ public:
|
||||
bool SwitchScreen();
|
||||
bool RestartScreen();
|
||||
virtual BOOL OnReconnect();
|
||||
uint64_t m_nReconnectTime = 0; // 重连开始时间
|
||||
uint64_t m_DlgID = 0;
|
||||
BOOL m_SendFirst = FALSE;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ CScreenSpy::CScreenSpy(ULONG ulbiBitCount, BYTE algo, BOOL vDesk, int gop, BOOL
|
||||
m_BitmapInfor_Full = ConstructBitmapInfo(ulbiBitCount, m_ulFullWidth, m_ulFullHeight);
|
||||
|
||||
iniFile cfg(CLIENT_PATH);
|
||||
int strategy = cfg.GetInt("settings", "ScreenStrategy", 0);
|
||||
int strategy = HasSSE2() ? cfg.GetInt("settings", "ScreenStrategy", 0) : 1;
|
||||
m_BitmapInfor_Send = new BITMAPINFO(*m_BitmapInfor_Full);
|
||||
switch (strategy) {
|
||||
case 1: // 1 - Original size
|
||||
|
||||
@@ -2350,7 +2350,8 @@ void delay_cancel(CONTEXT_OBJECT* ctx, int sec)
|
||||
CDlgFileSend* dlg = (CDlgFileSend*)ctx->hDlg;
|
||||
dlg->FinishFileSend(TRUE);
|
||||
Sleep(sec*1000);
|
||||
dlg->PostMessageA(WM_CLOSE);
|
||||
if (::IsWindow(dlg->GetSafeHwnd()))
|
||||
dlg->PostMessageA(WM_CLOSE);
|
||||
ctx->hDlg = NULL;
|
||||
ctx->CancelIO();
|
||||
}
|
||||
|
||||
@@ -304,8 +304,8 @@ BOOL CScreenSpyDlg::OnInitDialog()
|
||||
// 设置合理的"正常"窗口大小(屏幕的 80%),否则还原时窗口极小
|
||||
int cxScreen = GetSystemMetrics(SM_CXSCREEN);
|
||||
int cyScreen = GetSystemMetrics(SM_CYSCREEN);
|
||||
int normalWidth = cxScreen * 80 / 100;
|
||||
int normalHeight = cyScreen * 80 / 100;
|
||||
int normalWidth = cxScreen * 0.382;
|
||||
int normalHeight = cyScreen * 0.382;
|
||||
int normalX = (cxScreen - normalWidth) / 2;
|
||||
int normalY = (cyScreen - normalHeight) / 2;
|
||||
|
||||
@@ -332,6 +332,7 @@ VOID CScreenSpyDlg::OnClose()
|
||||
{
|
||||
KillTimer(1);
|
||||
KillTimer(2);
|
||||
KillTimer(3);
|
||||
if (!m_aviFile.IsEmpty()) {
|
||||
KillTimer(TIMER_ID);
|
||||
m_aviFile = "";
|
||||
@@ -365,6 +366,7 @@ afx_msg LRESULT CScreenSpyDlg::OnDisconnect(WPARAM wParam, LPARAM lParam)
|
||||
m_nDisconnectTime = GetTickCount64();
|
||||
// Close the dialog if reconnect not succeed in 15 seconds
|
||||
SetTimer(2, 15000, NULL);
|
||||
SetTimer(3, 3000, NULL);
|
||||
PostMessage(WM_PAINT);
|
||||
return S_OK;
|
||||
}
|
||||
@@ -615,7 +617,7 @@ void CScreenSpyDlg::OnPaint()
|
||||
NULL,
|
||||
DI_NORMAL | DI_COMPAT
|
||||
);
|
||||
if (!m_bConnected && GetTickCount64()-m_nDisconnectTime>2000) {
|
||||
if (!m_bConnected && GetTickCount64() - m_nDisconnectTime>2000) {
|
||||
DrawTipString("正在重连......", 2);
|
||||
}
|
||||
}
|
||||
@@ -863,6 +865,10 @@ void CScreenSpyDlg::OnTimer(UINT_PTR nIDEvent)
|
||||
this->PostMessageA(WM_CLOSE, 0, 0);
|
||||
return;
|
||||
}
|
||||
if (nIDEvent == 3) {
|
||||
KillTimer(3);
|
||||
PostMessageA(WM_PAINT);
|
||||
}
|
||||
CDialog::OnTimer(nIDEvent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user