Browse Source

新增打开log文件夹统计功能,并修复数组过小导致统计不准的问题。

Jeff Wang 3 năm trước cách đây
mục cha
commit
dc43b93b74

+ 1 - 0
FATP_FQC/FATP_FQC/FATP_FQC.rc

@@ -98,6 +98,7 @@ BEGIN
     PUSHBUTTON      "Shop Init",BTN_SHOP_INIT,74,19,50,14
     CONTROL         "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,43,305,221
     GROUPBOX        "Operation",IDC_STATIC,7,7,305,31
+    PUSHBUTTON      "´ò¿ªLogĿ¼",IDC_BUTTON1,128,19,50,14
 END
 
 

+ 26 - 7
FATP_FQC/FATP_FQC/FATP_FQCDlg.cpp

@@ -13,18 +13,20 @@
 
 // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
 
+//CFATP_FQCDlg::m_filePath = {0};
+
 class CAboutDlg : public CDialog
 {
 public:
 	CAboutDlg();
 
-// 对话框数据
+	// 对话框数据
 	enum { IDD = IDD_ABOUTBOX };
 
-	protected:
+protected:
 	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
 
-// 实现
+	// 实现
 protected:
 	DECLARE_MESSAGE_MAP()
 };
@@ -48,7 +50,7 @@ END_MESSAGE_MAP()
 
 
 CFATP_FQCDlg::CFATP_FQCDlg(CWnd* pParent /*=NULL*/)
-	: CDialog(CFATP_FQCDlg::IDD, pParent)
+: CDialog(CFATP_FQCDlg::IDD, pParent)
 {
 	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
 }
@@ -66,6 +68,7 @@ BEGIN_MESSAGE_MAP(CFATP_FQCDlg, CDialog)
 	//}}AFX_MSG_MAP
 	ON_BN_CLICKED(BTN_GET_LOG, &CFATP_FQCDlg::OnBnClickedGetLog)
 	ON_BN_CLICKED(BTN_SHOP_INIT, &CFATP_FQCDlg::OnBnClickedShopInit)
+	ON_BN_CLICKED(IDC_BUTTON1, &CFATP_FQCDlg::OnBnClickedButton1)
 END_MESSAGE_MAP()
 
 
@@ -113,7 +116,7 @@ BOOL CFATP_FQCDlg::OnInitDialog()
 
 #ifdef _DEBUG
 	TCHAR szLogDir[MAX_PATH] = {0};
-	_stprintf_s(szLogDir, _T("%s%s"), GLOBAL::g_szModulePath, _T("G9V287002073047H"));
+	_stprintf_s(szLogDir, _T("%s%s"), GLOBAL::g_szModulePath, _T("G9V28801216702RR"));
 	CheckLog(szLogDir);
 #endif
 
@@ -180,7 +183,7 @@ BOOL CFATP_FQCDlg::CheckLog(CString strLogDir)
 			strLogFile.Format(_T("%s\\radar_data_fan_dmesg_%d.log"), strLogDir, i);
 			if ( !PathFileExists(strLogFile) )
 				return FALSE;
-			
+
 			CStringList listStr;
 			CString strData = GLOBAL::ReadFileContent(strLogFile);
 			GLOBAL::GetStringList(strData, _T("\n"), listStr);
@@ -196,7 +199,7 @@ BOOL CFATP_FQCDlg::CheckLog(CString strLogDir)
 				fPercent, 
 				(90.0 < fPercent) ? _T("PASS") : _T("FAIL"));
 			m_listResult.AddTail(strResult);
-			
+
 			INT nItemCount = m_list.GetItemCount();
 			m_list.InsertItem(nItemCount, m_strDSN);
 
@@ -304,3 +307,19 @@ void CFATP_FQCDlg::OnBnClickedShopInit()
 		MessageBox(_T("运行BAT失败"), _T("提示"), MB_ICONERROR);
 	}
 }
+
+void CFATP_FQCDlg::OnBnClickedButton1()
+{
+	m_list.DeleteAllItems();
+	TCHAR szFolderPath[MAX_PATH] = {0};
+	GLOBAL::GetFilePath(szFolderPath, m_hWnd, _T("请选择Log文件夹!"), BIF_USENEWUI | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS);
+	if ( CheckLog(szFolderPath) )
+	{
+		OnBnClickedShopInit();
+	}
+	else
+	{
+		MessageBox(_T("日志统计失败"), _T("提示"), MB_ICONERROR);
+	}
+
+}

+ 1 - 0
FATP_FQC/FATP_FQC/FATP_FQCDlg.h

@@ -37,4 +37,5 @@ public:
 	CString m_strDSN;
 	CStringList m_listResult;
 	BOOL CheckLog(CString strLogDir);
+	afx_msg void OnBnClickedButton1();
 };

+ 81 - 8
FATP_FQC/FATP_FQC/Global.cpp

@@ -1,6 +1,8 @@
 #include "StdAfx.h"
 #include "Global.h"
 
+#define VLEN 10
+
 namespace GLOBAL
 {
 	TCHAR g_szModulePath[MAX_PATH] = _T("");			// 软件目录;
@@ -145,12 +147,12 @@ namespace GLOBAL
 				return nPassCount;
 			strLevel = listStr.GetNext(pos);
 
-			TCHAR szDist[5][5] = {0};
-			TCHAR szLevel[5][5] = {0};
+			TCHAR szDist[5][VLEN] = {0};
+			TCHAR szLevel[5][VLEN] = {0};
 
-			if (_stscanf_s(strDist.GetString(), _T("%*[^=]=%[^,],%[^,],%[^,],%[^,],%s"), szDist[0], 5, szDist[1], 5, szDist[2], 5, szDist[3], 5, szDist[4], 5) == 5 )
+			if (_stscanf_s(strDist.GetString(), _T("%*[^=]=%[^,],%[^,],%[^,],%[^,],%s"), szDist[0], VLEN, szDist[1], VLEN, szDist[2], VLEN, szDist[3], VLEN, szDist[4], VLEN) == 5 )
 			{
-				if (_stscanf_s(strLevel.GetString(), _T("%*[^=]=%[^,],%[^,],%[^,],%[^,],%s"), szLevel[0], 5, szLevel[1], 5, szLevel[2], 5, szLevel[3], 5, szLevel[4], 5) == 5 )
+				if (_stscanf_s(strLevel.GetString(), _T("%*[^=]=%[^,],%[^,],%[^,],%[^,],%s"), szLevel[0], VLEN, szLevel[1], VLEN, szLevel[2], VLEN, szLevel[3], VLEN, szLevel[4], VLEN) == 5 )
 				{
 					std::bitset<5> bitDist(0);
 					std::bitset<5> bitLevel(0);
@@ -165,9 +167,7 @@ namespace GLOBAL
 						bitLevel[i] = (nValue > 25) ? 1 : 0;
 					}
 
-					dprintf(_T("dist=[%s][%s][%s][%s][%s],[%s],[%ld]"), szDist[0],szDist[1],szDist[2],szDist[3],szDist[4], bitDist.to_string().c_str(), bitDist.to_ulong());
-					dprintf(_T("level=[%s][%s][%s][%s][%s],[%s],[%ld]"), szLevel[0],szLevel[1],szLevel[2],szLevel[3],szLevel[4], bitLevel.to_string().c_str(), bitLevel.to_ulong());
-
+					
 					int nDistValue = bitDist.to_ulong();
 					int nLevelValue = bitLevel.to_ulong();
 					if ( (nDistValue & nLevelValue) > 0 )
@@ -177,9 +177,20 @@ namespace GLOBAL
 					}
 					else
 					{
-						dprintf("FAIL");
+						dprintf(_T("dist=[%s][%s][%s][%s][%s],[%s],[%ld]"), szDist[0],szDist[1],szDist[2],szDist[3],szDist[4], bitDist.to_string().c_str(), bitDist.to_ulong());
+						dprintf(_T("level=[%s][%s][%s][%s][%s],[%s],[%ld]"), szLevel[0],szLevel[1],szLevel[2],szLevel[3],szLevel[4], bitLevel.to_string().c_str(), bitLevel.to_ulong());
+
+						dprintf("FAIL,%s,%s", bitDist.to_string().c_str(), bitLevel.to_string().c_str());
 					}
 				}
+				else
+				{
+					dprintf("失败:%s", strLevel.GetString());
+				}
+			}
+			else
+			{
+				dprintf("失败:%s", strDist.GetString());
 			}
 		}
 
@@ -215,4 +226,66 @@ namespace GLOBAL
 
 		return FALSE;
 	}
+
+	static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
+	{
+		switch (uMsg)
+		{
+		case BFFM_INITIALIZED:
+			SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)GLOBAL::g_szModulePath);
+			break;
+		case BFFM_SELCHANGED:
+			{
+				TCHAR szFileName[MAX_PATH];
+				LPITEMIDLIST pidlCurrent = (LPITEMIDLIST)lp;
+				SHGetPathFromIDList(pidlCurrent, szFileName);
+				SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szFileName);
+			}
+			break;
+			// 这个不能让默认目录为桌面;
+			// 	case BFFM_INITIALIZED:
+			// 		{
+			// 			// WParam is TRUE since you are passing a path.
+			// 			// It would be FALSE if you were passing a pidl.
+			// 			TCHAR szDir[MAX_PATH] = { 0 };
+			// 			GetCurrentDirectory(sizeof(szDir) / sizeof(TCHAR), szDir);
+			// 			SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDir);
+			// 		}
+			// 		break;
+		}
+		return 0;
+	}
+
+	BOOL GetFilePath(OUT TCHAR *FilePath, IN HWND hParentWnd, IN TCHAR* InstructionString, IN UINT ulFlags)
+	{
+		BROWSEINFO bInfo;
+		LPITEMIDLIST pidl, pidlDesktop;
+		ZeroMemory((PVOID)&bInfo, sizeof(BROWSEINFO));
+
+		HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidlDesktop);
+		if ( hr != S_OK )
+		{
+			return FALSE;
+		}
+
+		bInfo.pidlRoot = pidlDesktop;
+		bInfo.hwndOwner = hParentWnd;
+		bInfo.pszDisplayName = FilePath;
+		bInfo.lpszTitle = InstructionString;
+		bInfo.ulFlags = ulFlags;
+		bInfo.lpfn = BrowseCallbackProc;
+		bInfo.lParam = 0;
+
+		if ((pidl = ::SHBrowseForFolder(&bInfo)) == NULL)    
+		{
+			return FALSE;
+		}
+
+		if (::SHGetPathFromIDList(pidl, FilePath) == FALSE)   
+		{
+			return FALSE;
+		}
+
+		return TRUE;
+	}
 };

+ 2 - 0
FATP_FQC/FATP_FQC/Global.h

@@ -13,4 +13,6 @@ namespace GLOBAL
 	BOOL FindString(CStringList &ListStr, CString strFind, CString &strResult);
 	INT CheckListData(CStringList &listStr);
 	BOOL SaveList(CStringList &ListStr);
+
+	BOOL GetFilePath(OUT TCHAR *FilePath, IN HWND hParentWnd, IN TCHAR* InstructionString, IN UINT ulFlags);
 };

+ 2 - 1
FATP_FQC/FATP_FQC/resource.h

@@ -12,6 +12,7 @@
 #define IDC_LIST1                       1002
 #define IDC_RICHEDIT21                  1003
 #define IDC_EDIT1                       1004
+#define IDC_BUTTON1                     1005
 
 // Next default values for new objects
 // 
@@ -19,7 +20,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        129
 #define _APS_NEXT_COMMAND_VALUE         32771
-#define _APS_NEXT_CONTROL_VALUE         1005
+#define _APS_NEXT_CONTROL_VALUE         1006
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif