Implement the logging tab by reading the log file straight from disk.

This commit is contained in:
Mike Crowe 2006-05-30 11:29:59 +00:00
parent 975dbb6f22
commit 5ca7890013
5 changed files with 108 additions and 3 deletions

View File

@ -100,7 +100,8 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSM
CAPTION "Log"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_LOG,4,4,214,212,ES_AUTOHSCROLL | ES_READONLY
EDITTEXT IDC_LOG,6,6,210,189,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL
PUSHBUTTON "&Refresh",IDC_REFRESH,166,200,50,14
END
IDD_PAGE_ADVANCED DIALOGEX 0, 0, 222, 220
@ -144,6 +145,14 @@ BEGIN
TOPMARGIN, 7
BOTTOMMARGIN, 216
END
IDD_PAGE_LOG, DIALOG
BEGIN
VERTGUIDE, 6
VERTGUIDE, 216
HORZGUIDE, 6
HORZGUIDE, 214
END
END
#endif // APSTUDIO_INVOKED
@ -293,6 +302,8 @@ END
STRINGTABLE
BEGIN
IDS_FAILED_CONFIGURE_STARTUP "Failed to reconfigure startup application."
IDS_LOG_NOLOG "Firefly server logging is not enabled."
IDS_LOG_OPENFAILED "Failed to open server log file '%s'."
END
#endif // English (U.S.) resources

View File

@ -16,8 +16,94 @@
#include "stdafx.h"
#include "LogPage.h"
#include "FireflyShell.h"
#include "IniFile.h"
LRESULT CLogPage::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
LoadLog();
return 0;
}
LRESULT CLogPage::OnRefresh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
LoadLog();
return 0;
}
void CLogPage::LoadLog()
{
CWaitCursor wait;
const size_t MAX_LOG = 65000;
IniFile ini(GetApplication()->GetConfigPath());
CString filename = ini.GetString(_T("general"), _T("logfile"), _T(""));
if (filename.IsEmpty())
{
CString str;
str.LoadString(IDS_LOG_NOLOG);
GetDlgItem(IDC_LOG).SetWindowText(str);
}
else
{
FILE *fp = _tfopen(filename, _T("r"));
if (fp)
{
// Fathom the length
fseek(fp, 0, SEEK_END);
long len = ftell(fp);
if (len > MAX_LOG)
{
len = MAX_LOG;
fseek(fp, -len, SEEK_END);
}
else
{
fseek(fp, 0, SEEK_SET);
}
char *buffer = new char[len + 1];
size_t nread = fread(buffer, 1, len, fp);
ATLASSERT(nread < MAX_LOG);
buffer[nread] = 0;
fclose(fp);
// Normalise the line endings. Not particularly efficient but
// it does work. It would be nice if we could cheaply tell
// CString to preallocate a certain size.
CString log(_T("Log file: "));
log += filename;
log += _T("\r\n\r\n");
size_t n = 0;
while (n < nread)
{
switch (buffer[n])
{
case '\r':
// Ignore
break;
case '\n':
log += _T("\r\n");
break;
default:
log += buffer[n];
break;
}
++n;
}
GetDlgItem(IDC_LOG).SetWindowText(log);
delete []buffer;
}
else
{
CString str;
str.Format(IDS_LOG_OPENFAILED, filename);
GetDlgItem(IDC_LOG).SetWindowText(str);
}
}
}

View File

@ -32,10 +32,15 @@ private:
// Message Handlers
BEGIN_MSG_MAP(CLogPage)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_HANDLER(IDC_REFRESH, BN_CLICKED, OnRefresh)
CHAIN_MSG_MAP(base)
END_MSG_MAP()
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnRefresh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
void LoadLog();
};
#endif // LOGPAGE_H

View File

@ -24,7 +24,7 @@ CMainDlg::CMainDlg()
{
this->AddPage(m_pageConfig);
this->AddPage(m_pageAdvanced);
//this->AddPage(m_pageLog);
this->AddPage(m_pageLog);
this->AddPage(m_pageAbout);
ATLVERIFY(m_strTitle.LoadString(IDR_MAINFRAME));

View File

@ -19,6 +19,8 @@
#define IDS_VERSIONINFO_PATH 142
#define IDS_FAILED_CONFIGURE_SERVICE 143
#define IDS_FAILED_CONFIGURE_STARTUP 144
#define IDS_LOG_NOLOG 145
#define IDS_LOG_OPENFAILED 146
#define IDD_PAGE_BASIC 201
#define IDD_PAGE_ADVANCED 202
#define IDD_PAGE_LOG 203
@ -45,6 +47,7 @@
#define IDC_WEBSITE 1014
#define IDC_VERSIONLIST 1015
#define IDC_COPY 1016
#define IDC_REFRESH 1018
#define ID_SHELLNOTIFY 4242
// Next default values for new objects
@ -53,7 +56,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 208
#define _APS_NEXT_COMMAND_VALUE 32773
#define _APS_NEXT_CONTROL_VALUE 1017
#define _APS_NEXT_CONTROL_VALUE 1019
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif