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

📄 logsdlg.cpp

📁 DES算法实现
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// LogsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Logs.h"
#include "LogsDlg.h"

#include "PassPhrase.h"
#include "DlgChangePwd.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLogsDlg dialog


CLogsDlg::CLogsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLogsDlg::IDD, pParent)
{
	m_nLine = 0;
	m_nNumOfColumns = 0;
	m_csCurLogFile = _T("");

	m_bSpecUser = FALSE;

	//{{AFX_DATA_INIT(CLogsDlg)
	m_csLoading = _T("");
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

void CLogsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLogsDlg)
	DDX_Control(pDX, IDC_LIST_LOG, m_cListLogs);
	DDX_Control(pDX, IDC_TREE_LOG, m_cTreeLogs);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLogsDlg, CDialog)
	//{{AFX_MSG_MAP(CLogsDlg)
	ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_LOG, OnSelchangedTreeLog)
	ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE_LOG, OnItemexpandingTreeLog)
	ON_BN_CLICKED(BTN_PWD_CHANGE, OnPwdChange)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLogsDlg message handlers


BOOL CLogsDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	//--------------------------------------------------------------
	// Start Log information
	//--------------------------------------------------------------

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

	//*********************************************************************
	// You can call this if you don't want the...
	// default log path (C:\Logs).
	//
	// NOTE:  You can use UNC Names (see examples below)
	//
	//pcLogger->clLogs.CreateLogPath(_T("C:\\DDLogs\\"));
	//pcLogger->clLogs.CreateLogPath(_T("\\\\SERVER\\Share\\DDLogs\\"));
	//*********************************************************************


	// puts the Domain\username in a variable
	pcLogger->clLogs.GetSystemDomainUserName();

	int nType = 0;
	CString csOSVer = _T("");
	if (pcLogger->clLogs.GetOSType(csOSVer, nType)) {
		if (nType < 4) {
			CString csMsg;
			csMsg.Format("This Application requires WinNT 4.0 or higher: [using %s]", csOSVer);
			pcLogger->clLogs.WriteLog(csMsg, 2);
			MessageBox(csMsg, "Error: OS", MB_OK | MB_ICONSTOP);
			EndDialog (0);
			return 0;
		}
	}

	//Show dlg password
	CPassPhrase dlgPP;
	int result = dlgPP.DoModal ();
	if (result == 0) {
		EndDialog (0);
		return 0;
	}
	delete dlgPP;//delete dlg passphrase

	// Make a log entry to show Iv'e logged in!
	pcLogger->clLogs.WriteLog("Successfully Logged in ...", 2);

	// Setup the list control
	ListView_SetExtendedListViewStyle(m_cListLogs.m_hWnd, LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
	
	SetOurImageList(IDB_LOG_IMAGES);

	// Create the image list that is attached to the list control
	//Loadup the image list
	VERIFY(m_cImageListSmall.Create(m_unImgResID, 16, 1, RGB(255, 0, 255)));

	//Hook it up to the tree control
	m_cListLogs.SetImageList(&m_cImageListSmall, LVSIL_SMALL);
	m_cTreeLogs.SetImageList(&m_cImageListSmall, TVSIL_NORMAL);

	// Delete the current contents
	m_cListLogs.DeleteAllItems();

	LoadTree();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

/////////////////////////////////////////////////////////////////////////////
/*
	OnOK

	Params
		None
  
	Returns 
		void
*/
/////////////////////////////////////////////////////////////////////////////
void CLogsDlg::OnOK() 
{
	CLogsApp* pcLogger = (CLogsApp*) AfxGetApp();

	pcLogger->clLogs.WriteLog("Logged out ...", 2);

	CDialog::OnOK();
}


/////////////////////////////////////////////////////////////////////////////
/*
	InsertItems

	Insert the items into the list control.   
	
	Params
		None

	Returns 
		void
*/
/////////////////////////////////////////////////////////////////////////////
void CLogsDlg::InsertItems(CStringArray& csaItemInfo)
{

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

	// Use the LV_ITEM structure to insert the items
	LVITEM lvi;
	CString csItem = _T("");
	CString csItemInfo = _T("");
	CStringArray csaLineInfo;

	// Below code is used only when you read a 
	// file into the Array

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

		csItemInfo = csaItemInfo.GetAt(n);
		pcLogger->clLogs.Split(csItemInfo, "~", csaLineInfo, FALSE);

		if (!m_bSpecUser) {

			// Insert the first item
			lvi.mask =  LVIF_IMAGE | LVIF_TEXT;
			csItem = csaLineInfo.GetAt(0);

			lvi.iItem = n;
			lvi.iSubItem = 0;
			lvi.pszText = (LPTSTR)(LPCTSTR)(csItem);
			csItem = csaLineInfo.GetAt(1);
			lvi.iImage = atoi(csItem);
			m_cListLogs.InsertItem(&lvi);

			lvi.iSubItem = 1;
			csItem = csaLineInfo.GetAt(2);
			lvi.pszText = (LPTSTR)(LPCTSTR)(csItem);
			m_cListLogs.SetItem(&lvi);

			lvi.iSubItem = 2;
			csItem = csaLineInfo.GetAt(3);
			lvi.pszText = (LPTSTR)(LPCTSTR)(csItem);
			m_cListLogs.SetItem(&lvi);
		}
		else {
			// Insert the first item
			lvi.mask =  LVIF_IMAGE | LVIF_TEXT;
			csItem = csaLineInfo.GetAt(2);

			lvi.iItem = n;
			lvi.iSubItem = 0;
			lvi.pszText = (LPTSTR)(LPCTSTR)(csItem);
			csItem = csaLineInfo.GetAt(1);
			lvi.iImage = atoi(csItem);
			m_cListLogs.InsertItem(&lvi);

			lvi.iSubItem = 1;
			csItem = csaLineInfo.GetAt(3);
			lvi.pszText = (LPTSTR)(LPCTSTR)(csItem);
			m_cListLogs.SetItem(&lvi);

		}
	}

}

void CLogsDlg::LoadLog(CString csFilePathName)
{

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

	CStringArray csaLogInfo;
	CStringArray csaLogLines;

	m_cListLogs.DeleteAllItems();

	BeginWaitCursor();

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

	m_cListLogs.SetRedraw(FALSE);

	// Setup the column headings
	CRect rect;
	m_cListLogs.GetClientRect(&rect);

	if (m_bSpecUser) {
		m_cListLogs.InsertColumn(0, _T("Time"), LVCFMT_LEFT, (rect.Width() / 3) / 2);
		m_cListLogs.InsertColumn(1, _T("Log Entry"), LVCFMT_LEFT, ((rect.Width() / 3) * 2) + ((rect.Width() / 3) / 2));
		m_nNumOfColumns = 1;
	}
	else {
		m_cListLogs.InsertColumn(0, _T("User"), LVCFMT_LEFT, (rect.Width() / 3));
		m_cListLogs.InsertColumn(1, _T("Time"), LVCFMT_LEFT, (rect.Width() / 3) / 2);
		m_cListLogs.InsertColumn(2, _T("Log Entry"), LVCFMT_LEFT, ((rect.Width() / 3) * 2) - ((rect.Width() / 3) / 2));
		m_nNumOfColumns = 2;
	}

	CStringArray csaCurLogFile;
	pcLogger->clLogs.Split(csFilePathName, "\\", csaCurLogFile, FALSE);

	m_csCurLogFile = csaCurLogFile.GetAt(csaCurLogFile.GetUpperBound());
	
	FILE*	fLog;
	fLog = fopen(csFilePathName, "r");
	if (fLog != NULL) {
		CStdioFile sfLog(fLog);
		
		HTREEITEM hSel = m_cTreeLogs.GetSelectedItem();
		CString csSel = m_cTreeLogs.GetItemText(hSel);

		CString csLine;
		BOOL bLine = sfLog.ReadString(csLine);
		m_nLine = 0;
		do {
			if (!csLine.IsEmpty()) {
				CString szRet = pcLogger->clLogs.DecryptString(csLine, pcLogger->clLogs.m_csAppsPPhrase);
				csLine = szRet;
				
				if (m_bSpecUser) {
					if (csLine.Left(csSel.GetLength()) == csSel)
						csaLogInfo.Add(csLine); //InsertItems(csLine);
				}
				else {
					csaLogInfo.Add(csLine); //InsertItems(csLine);
				}
				m_nLine++;
			}
			bLine = sfLog.ReadString(csLine);
		} while (bLine);
	}
	fclose(fLog);

	int nUBound = csaLogInfo.GetUpperBound();
	for (int n=nUBound; n>=0; n--) {

⌨️ 快捷键说明

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