Click here to Skip to main content
15,891,895 members
Articles / Desktop Programming / WTL

Log Harvester

Rate me:
Please Sign up or sign in to vote.
4.50/5 (3 votes)
17 Sep 2012CPOL3 min read 20.6K   1.8K   13  
A complete log viewer written in C++/WTL.
// Filterdlg.cpp : implementation of the CFilterDlg class
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "resource.h"

#include "filterdlg.h"
#include <string>
#include <algorithm>

using namespace std;

LRESULT CFilterDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	SendDlgItemMessage(IDC_FILTER01_LEVDIST_SPIN, UDM_SETRANGE, 0, MAKELONG(10, 1));
	CenterWindow(GetParent());
	m_bCaseSensitivity = FALSE;
	m_bSimilarity = FALSE;

	if (m_csAction.Find(L"NOT") > 0)
		GetDlgItem(IDC_FILTER01_SIMILAR).EnableWindow(FALSE);

	DoDataExchange(FALSE);
	BOOL bDiscard;
	OnSimilar(0, 0, 0, bDiscard);
	CComboBox cbx = (CComboBox)GetDlgItem(IDC_FILTER01_SEARCH_TEXT_COMBO);	
	
	CRegKey key; 
	if(key.Open(HKEY_CURRENT_USER, _T("SOFTWARE\\AWS\\Harvester\\Selects"), KEY_READ) == ERROR_SUCCESS)
	{
		for (int i = 0; i < 1000; i++)
		{
			CString csValName, csVal;
			csValName.Format(L"Select%04d", i);

			ULONG dwcbNeeded = 0;
			if(key.QueryValue(csValName, NULL, NULL, &dwcbNeeded) == ERROR_SUCCESS)
			{
				LPTSTR pszVal = csVal.GetBuffer(dwcbNeeded);
				if (key.QueryStringValue(csValName, pszVal, &dwcbNeeded) == ERROR_SUCCESS)
				{
					csVal.ReleaseBuffer();
					cbx.AddString(csVal);
					m_setEntries.push_back(pszVal);
				}
				else
					csVal.ReleaseBuffer(0);	
			}
		}
		key.Close();
	}

	DoDataExchange(FALSE);
	cbx.SetCurSel(0);
	
	return TRUE;
}

void CFilterDlg::SetValues(bool bInvertedAction, bool bCaseSensitivity, bool bSimilarity, int nMaxLevenstein)
{
	m_csAction = _T("Select lines ");
	m_csAction += bInvertedAction ? _T("NOT ") : _T("");
	m_csAction += _T("containing following text");
	m_bCaseSensitivity = bCaseSensitivity;
	m_bSimilarity = bSimilarity;
	m_nMaxLevensthein = nMaxLevenstein;
}

LRESULT CFilterDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	DoDataExchange(TRUE);

	if (wID == IDOK)
	{
		reverse(m_setEntries.begin(),m_setEntries.end());

		bool bPrio = false;
		if (m_csSearchText.GetLength() && (find(m_setEntries.begin(), m_setEntries.end(), (wstring)m_csSearchText) == m_setEntries.end()) || !m_setEntries.size())
			m_setEntries.push_back(m_csSearchText.GetBuffer(m_csSearchText.GetLength()));
		else if (m_csSearchText.GetLength() && (find(m_setEntries.begin(), m_setEntries.end(), (wstring)m_csSearchText) != m_setEntries.end()))
			bPrio = true;

		CRegKey key; 
		if(key.Create(HKEY_CURRENT_USER, _T("SOFTWARE\\AWS\\Harvester\\Selects"), REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE) == ERROR_SUCCESS)
		{
			int i = 0;
			if (bPrio)
			{
				key.SetStringValue(_T("Select0000"), m_csSearchText);
				i++;
			}

			while (m_setEntries.size())
			{	
				if (bPrio && m_setEntries.back() == (wstring)m_csSearchText)
				{
					m_setEntries.pop_back();
					continue;
				}

				CString csVal;
				csVal.Format(L"Select%04d", i++);
				key.SetStringValue(csVal,  m_setEntries.back().c_str());
				m_setEntries.pop_back();
			}
			key.Close();
		}
	}

	EndDialog(wID);	
	return 0;
}

LRESULT CFilterDlg::OnSimilar(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	DoDataExchange(TRUE);
	GetDlgItem(IDC_FILTER01_LEVDIST_EDIT).EnableWindow(m_bSimilarity);
	GetDlgItem(IDC_FILTER01_LEVDIST_SPIN).EnableWindow(m_bSimilarity);
	GetDlgItem(IDC_FILTER01_LEVDIST_STATIC).EnableWindow(m_bSimilarity);
	return 0;
}

LRESULT CFilterDlg::OnOR(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	DoDataExchange(TRUE);
	m_csSearchText += _T("�");
	DoDataExchange(FALSE);
	GetDlgItem(IDC_FILTER01_SEARCH_TEXT_COMBO).SetFocus();
	((CComboBox)GetDlgItem(IDC_FILTER01_SEARCH_TEXT_COMBO)).SetEditSel(m_csSearchText.GetLength(), m_csSearchText.GetLength());
	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Czech Republic Czech Republic
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions