mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-11 06:20:17 -05:00
Implement the logging tab by reading the log file straight from disk.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user