⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logsdlg.cpp

📁 DES算法实现
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		csaLogLines.Add(csaLogInfo.GetAt(n));
	}

	csaLogInfo.RemoveAll();

	InsertItems(csaLogLines);

	csaLogLines.RemoveAll();
	
	m_cListLogs.SetRedraw(TRUE);

	EndWaitCursor();
}


void CLogsDlg::LoadUsers(HTREEITEM hSelectedLog, CString csFilePath)
{

	CLogsApp* pcLogger = (CLogsApp*) AfxGetApp();

	FILE*	fLog;
	fLog = fopen(csFilePath, "r");
	if (fLog != NULL) {
		CStdioFile sfLog(fLog);
		
		CStringArray csaLoggedUser;
		CStringArray csaLoggedUserAdded;

		CString csLine;
		BOOL bLine = sfLog.ReadString(csLine);
		do {
			if (!csLine.IsEmpty()) {
				CString szRet = pcLogger->clLogs.DecryptString(csLine, pcLogger->clLogs.m_csAppsPPhrase);
				csLine = szRet;
				pcLogger->clLogs.Split(csLine, "~", csaLoggedUser, FALSE);
				CString csUser = csaLoggedUser.GetAt(0);

				BOOL bFound = FALSE;

				int nUBound = csaLoggedUserAdded.GetUpperBound();
				for (int n = 0; n<=nUBound; n++) {

					CString csAdded = csaLoggedUserAdded.GetAt(n);
					if (csUser == csAdded) {
						bFound = TRUE;
						break;
					}
				}

				if (!bFound) {
					csaLoggedUserAdded.Add(csUser);
					m_cTreeLogs.InsertItem(csUser, 7, 7, hSelectedLog);
				}
			}
			bLine = sfLog.ReadString(csLine);
		} while (bLine);

		csaLoggedUserAdded.RemoveAll();
		csaLoggedUser.RemoveAll();

	}
	fclose(fLog);

}


void CLogsDlg::LoadTree(void)
{

	CLogsApp* pcLogger = (CLogsApp*) AfxGetApp();

	m_hTRoot = m_cTreeLogs.InsertItem(pcLogger->clLogs.GetLogDir(), 3, 3, NULL);
	LogSearch(pcLogger->clLogs.GetLogDir());

	int nDirUBound = csaDirs.GetUpperBound();
	int nFileUBound = csaFiles.GetUpperBound();

	HTREEITEM hDirName = NULL;


	CStringArray csaCurFiles;
	int nDCtr = nDirUBound;
	for (; nDCtr>=0; nDCtr--) {

		CString csDir = csaDirs.GetAt(nDCtr);
		
		if (csDir.IsEmpty()) {
			csaCurFiles.Add(csaFiles.GetAt(nDCtr));
		}
		else {

			hDirName = m_cTreeLogs.InsertItem(csDir, 4, 4, m_hTRoot);
			CString csFPath = pcLogger->clLogs.GetLogDir() + csDir;
			csFPath += "\\";

			int nCFUBound = csaCurFiles.GetUpperBound();
			for (int nCFCtr = 0; nCFCtr<=nCFUBound; nCFCtr++) {
				HTREEITEM hLogFile = m_cTreeLogs.InsertItem(csaCurFiles.GetAt(nCFCtr), 6, 6, hDirName);
				CString csTmp = csFPath + csaCurFiles.GetAt(nCFCtr);
				LoadUsers(hLogFile, csTmp);
			}
			csaCurFiles.RemoveAll();
		}
	}
	// then expand the root item and 
	// make it visible
	m_cTreeLogs.Expand(m_hTRoot,TVE_EXPAND);
	m_cTreeLogs.EnsureVisible(m_hTRoot);

}


/////////////////////////////////////////////////////////////////////////////
//
// FUNCTION:   LogSearch
//
// PURPOSE:    To search a given directory (recursively) for logfiles
//
// PARAMETERS:
//	 @param1 - CString csDirName - Path of the file/directory search
//
// RETURN:     Nothing.
//
/////////////////////////////////////////////////////////////////////////////
void CLogsDlg::LogSearch(CString csDirName)
{

	WIN32_FIND_DATA wfd, wffd;
	HANDLE hFind, hFFind;

	CString csDirIn = _T("");

	// Check if the last char is a back-slash
	// (If not, put it there)
	if (csDirName.Right(1) != "\\")
		csDirName += _T("\\");

	// set the variable and add an astrix for 
	// the beginning of the directory search.
	csDirIn = csDirName + _T("*");

	// Iterate through dirs
	hFind = FindFirstFile(csDirIn, &wfd);
	if (hFind != INVALID_HANDLE_VALUE) {

		HTREEITEM hDirName = NULL;

		csaDirs.RemoveAll();
		csaFiles.RemoveAll();
		do {

			// Check if "." or "..", if not...
			// Check if its a directory.
			if ((strcmp(wfd.cFileName,_T("."))) && (strcmp(wfd.cFileName,_T(".."))) && 
				(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {

				CString csDir = wfd.cFileName;
				csaDirs.Add(csDir);
				csaFiles.Add("");
				
				// Set to the directory found.
				csDirIn = csDirName + csDir;
				csDirIn += _T("\\");
				csDirIn += _T("*.*");//strMask;

				hFFind = FindFirstFile(csDirIn, &wffd);
				if (hFFind != INVALID_HANDLE_VALUE) {

					int nDirUBound = csaDirs.GetUpperBound();
					do {
						// If NOT a directory...
						if ((wffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
							
							// Set to the file found.
							CString csFile = wffd.cFileName;
							csaDirs.Add("");
							csaFiles.Add(csFile);

						}

					} while (FindNextFile(hFFind, &wffd));

					// This is a MUST
					FindClose(hFFind);
				}
			}
		} while (FindNextFile(hFind, &wfd));

		// This is a MUST
		FindClose(hFind);
	}
}


/****************************************************************************
**	Function:	OnSelchangedTree1
****************************************************************************/
void CLogsDlg::OnSelchangedTreeLog(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;

	CLogsApp* pcLogger = (CLogsApp*) AfxGetApp();

	// Delete All Items
	m_cListLogs.DeleteAllItems();

	BeginWaitCursor();

	CString csCurSel = m_cTreeLogs.GetItemText(pNMTreeView->itemNew.hItem);
	if (csCurSel.Right(4) == ".log") {

		// Get the path from the App
		CString csText = pcLogger->clLogs.GetLogDir();

		// Get Parent Item
		HTREEITEM hParent = m_cTreeLogs.GetParentItem(pNMTreeView->itemNew.hItem);

		// Append data to the variable
		csText += m_cTreeLogs.GetItemText(hParent) + "\\";
		csText += csCurSel;

		m_bSpecUser = FALSE;

		// Load the log into the ListCtrl
		LoadLog(csText);

	}
	else if (!m_cTreeLogs.ItemHasChildren(pNMTreeView->itemNew.hItem)) {

		// Get the path from the App
		CString csText = pcLogger->clLogs.GetLogDir();

		// Get Parent Item
		HTREEITEM hParent = m_cTreeLogs.GetParentItem(pNMTreeView->itemNew.hItem);
		HTREEITEM hParent1 = m_cTreeLogs.GetParentItem(hParent);

		// Append data to the variable
		csText += m_cTreeLogs.GetItemText(hParent1) + "\\";
		csText += m_cTreeLogs.GetItemText(hParent);

		m_bSpecUser = TRUE;

		// Load the log into the ListCtrl
		LoadLog(csText);

	}
	else {

		// Turn off redraw so we can make changes
		m_cListLogs.SetRedraw(FALSE);

		CRect rect;
		m_cListLogs.GetClientRect(&rect);

		for (; m_nNumOfColumns >= 0; m_nNumOfColumns--) { 
			m_cListLogs.DeleteColumn(m_nNumOfColumns); 
		} 
		m_nNumOfColumns = 0;


		LVITEM lvi;

		// Get the first child item of the currently selected item
		HTREEITEM hChild = m_cTreeLogs.GetNextItem(pNMTreeView->itemNew.hItem, TVGN_CHILD);

		// Get the image so we know what the new images will be.
		int nSel = -1, nImg = -1;
		m_cTreeLogs.GetItemImage(pNMTreeView->itemNew.hItem, nImg, nSel);
		if (nImg == 3) {
			nSel = 4;
			m_cListLogs.InsertColumn(0, _T("Log Directories"), LVCFMT_LEFT, rect.Width());
			m_nNumOfColumns = 0;
		}
		else if ((nImg == 4) || (nImg == 5)) {
			nSel = 6;
			m_cListLogs.InsertColumn(0, _T("Log Files"), LVCFMT_LEFT, rect.Width());
			m_nNumOfColumns = 0;
		}

		// Start the counter
		int nLineCtr = 0;
		while (hChild) {

			// Get the text of the current item
			CString csItem = m_cTreeLogs.GetItemText(hChild);
	
			// Insert item
			lvi.mask =  LVIF_IMAGE | LVIF_TEXT;
			lvi.iItem = nLineCtr;
			lvi.iSubItem = 0;
			lvi.pszText = (LPTSTR)(LPCTSTR)(csItem);

			// we set the image before the 'while loop'
			lvi.iImage = nSel;

			m_cListLogs.InsertItem(&lvi);

			// add one to the counter
			nLineCtr++;

			// get the handle of the next item
			hChild = m_cTreeLogs.GetNextItem(hChild, TVGN_NEXT);
		}

		// done with our changes, so turn back on redraw
		m_cListLogs.SetRedraw(TRUE);
	}
	EndWaitCursor();

	*pResult = 0;
}

void CLogsDlg::OnItemexpandingTreeLog(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;

	if ((m_cTreeLogs.GetParentItem(pNMTreeView->itemNew.hItem)) == m_hTRoot) {
		
		int nSel = -1, nImg = 0;
		if (m_cTreeLogs.GetItemImage(pNMTreeView->itemNew.hItem, nImg, nSel)) {
			if (nImg == 4) {
				m_cTreeLogs.SetItemImage(pNMTreeView->itemNew.hItem, 5, 5);
			}
			else if (nImg == 5) {
				m_cTreeLogs.SetItemImage(pNMTreeView->itemNew.hItem, 4, 4);
			}
		}
	}

	*pResult = 0;
}

//**********************************************************

void CLogsDlg::OnPwdChange() 
{

	//Show dlg
	CDlgChangePwd dlgCP;
	dlgCP.DoModal ();
	delete dlgCP;
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -