소스 검색

升级按钮:改用线程触发,因为升级时间长,会卡界面。

sat23 4 년 전
부모
커밋
bf6bd2f60d
2개의 변경된 파일37개의 추가작업 그리고 30개의 파일을 삭제
  1. 36 28
      SATHelper/SATHelper/UpgradeWnd.cpp
  2. 1 2
      SATHelper/SATHelper/UpgradeWnd.h

+ 36 - 28
SATHelper/SATHelper/UpgradeWnd.cpp

@@ -150,7 +150,7 @@ int CUpgradeWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
 	}
 
 	m_text_password.Create(_T("FTP密码:"), SS_CENTER | SS_CENTERIMAGE | WS_CHILD | WS_VISIBLE, rectDummy, this, IDC_STATIC);
-	if (!m_ftp_password.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL | WS_TABSTOP, rectDummy, this, ID_EDIT_FTP_PASSWORD))
+	if (!m_ftp_password.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | ES_PASSWORD | ES_AUTOHSCROLL | WS_TABSTOP, rectDummy, this, ID_EDIT_FTP_PASSWORD))
 	{
 		//m_ftp_password.SetPasswordChar(‘*');
 		return -1;
@@ -200,33 +200,41 @@ void CUpgradeWnd::OnSize(UINT nType, int cx, int cy)
 
 void CUpgradeWnd::OnUpgradeBtnClick()
 {
-	CString strPath = _T(""), strFtpUser = _T(""), strFtpPassword = _T("");
-	m_edit_path.GetWindowText(strPath);
-	m_ftp_user.GetWindowText(strFtpUser);
-	m_ftp_password.GetWindowText(strFtpPassword);
-	if ( _bIsFtpPath ) {
-		Global::g_Config.strFtpUser = strFtpUser.GetString();
-		Global::g_Config.strFtpPassword = strFtpPassword.GetString();
-		WritePrivateProfileString("SATHelper", "ftp_user", strFtpUser.GetString(), Global::g_szConfig);
-		WritePrivateProfileString("SATHelper", "ftp_password", strFtpPassword.GetString(), Global::g_szConfig);
-	}
-
-	CCallPython pycall;
-	TCHAR szPath[MAX_PATH] = {0};
-	_stprintf_s(szPath, _T("%sscripts\\TVUpgrade.py"), Global::g_szCurModuleDir);
-	PyObject *pRet = pycall.CallPython(szPath, _T("API_TVUpgrade"), 3, _variant_t(strPath.GetString()), _variant_t(strFtpUser.GetString()), _variant_t(strFtpPassword.GetString()));
-	if (pRet == NULL)
-	{
-		AfxMessageBox(_T("运行失败"));
-	}
-	else
-	{		
-		AfxMessageBox(pycall.GetUTF8String(pRet).c_str());
-
-		if (pRet)
-			Py_DECREF(pRet);
-	}
-
+	std::thread t([](CUpgradeWnd* p) {
+		CString strPath = _T(""), strFtpUser = _T(""), strFtpPassword = _T("");
+		p->m_edit_path.GetWindowText(strPath);
+		p->m_ftp_user.GetWindowText(strFtpUser);
+		p->m_ftp_password.GetWindowText(strFtpPassword);
+		if (p->_bIsFtpPath) {
+			Global::g_Config.strFtpUser = strFtpUser.GetString();
+			Global::g_Config.strFtpPassword = strFtpPassword.GetString();
+			WritePrivateProfileString("SATHelper", "ftp_user", strFtpUser.GetString(), Global::g_szConfig);
+			WritePrivateProfileString("SATHelper", "ftp_password", strFtpPassword.GetString(), Global::g_szConfig);
+		}
+
+		p->m_btnUpgrade.EnableWindow(FALSE);
+		p->m_text_notify.SetWindowText("升级中,请稍等……!");
+		Sleep(1000);
+		
+		CCallPython pycall;
+		TCHAR szPath[MAX_PATH] = { 0 };
+		_stprintf_s(szPath, _T("%sscripts\\TVUpgrade.py"), Global::g_szCurModuleDir);
+		PyObject* pRet = pycall.CallPython(szPath, _T("API_TVUpgrade"), 3, _variant_t(strPath.GetString()), _variant_t(strFtpUser.GetString()), _variant_t(strFtpPassword.GetString()));
+		if (pRet == NULL)
+		{
+			p->m_text_notify.SetWindowText("运行出错,请检查脚本!");
+		}
+		else
+		{
+			p->m_text_notify.SetWindowText(pycall.GetUTF8String(pRet).c_str());
+
+			if (pRet)
+				Py_DECREF(pRet);
+		}
+
+		p->m_btnUpgrade.EnableWindow();
+	}, this);
+	t.detach();
 }
 
 void CUpgradeWnd::OnUpdateBtnUpgrade(CCmdUI* pCmdUI)

+ 1 - 2
SATHelper/SATHelper/UpgradeWnd.h

@@ -34,7 +34,6 @@ public:
 
 		CFileDialog dlg(TRUE, NULL, NULL, NULL, m_strFileFilter, NULL, 0, TRUE);
 		(dlg.m_ofn).lpstrTitle = _T("打开文件");
-		//dlg.m_ofn.Flags
 		dlg.DoModal();
 		/*if (dlg.DoModal() == IDOK)
 		{
@@ -68,7 +67,7 @@ protected:
 	CFont m_fntPropList;
 	// 路径编辑框;
 	CStatic m_text_path;
-	CMyEditBrowseCtrl m_edit_path;
+	CMFCEditBrowseCtrl m_edit_path;
 	//CEdit m_edit_path;
 	// 升级按钮;
 	CMFCButton m_btnUpgrade;