Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 46 additions & 55 deletions LogMonitor/src/LogMonitor/LogFileMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ DWORD LogFileMonitor::EnqueueDirChangeEvents(DirChangeNotificationEvent event, B

if (m_directoryChangeEvents.size() == 1)
{
//wprintf(L"Signalling worker thread to start processing the event queue\n");
if(!SetEvent(m_workerThreadEvent))
{
logWriter.TraceError(
Expand Down Expand Up @@ -645,8 +644,6 @@ LogFileMonitor::InitializeDirectoryChangeEventsQueue()
DWORD status = ERROR_SUCCESS;
std::vector<std::pair<std::wstring, FILE_ID_INFO> > logFiles;

//wprintf(L"InitializeDirectoryChangeEventsQueue\n");

status = GetFilesInDirectory(m_logDirectory, m_filter, logFiles, m_includeSubfolders);

if (status == ERROR_SUCCESS)
Expand Down Expand Up @@ -896,49 +893,7 @@ LogFileMonitor::LogFilesChangeHandler()

ReleaseSRWLockExclusive(&m_eventQueueLock);

switch (event.Action)
{
case EventAction::Add:
{
status = LogFileAddEventHandler(event);
break;
}

case EventAction::Modify:
{
status = LogFileModifyEventHandler(event);
break;
}

case EventAction::Remove:
{
status = LogFileRemoveEventHandler(event);
break;
}

case EventAction::RenameOld:
{
//
// Nothing to do
//
break;
}

case EventAction::RenameNew:
{
status = LogFileRenameNewEventHandler(event);
break;
}

case EventAction::ReInit:
{
status = LogFileReInitEventHandler(event);
break;
}

default:
break;
}
status = GetLogFileEventStatus(event);

AcquireSRWLockExclusive(&m_eventQueueLock);
}
Expand Down Expand Up @@ -978,8 +933,6 @@ LogFileMonitor::LogFilesChangeHandler()
{
map<std::wstring, std::shared_ptr<LogFileInformation>>::iterator it;

//wprintf(L"LogFilesChangeHandler: Timer event\n");

for ( it = m_logFilesInformation.begin(); it != m_logFilesInformation.end(); it++ )
{
ReadLogFile(it->second);
Expand Down Expand Up @@ -1023,6 +976,50 @@ LogFileMonitor::LogFilesChangeHandler()
}


DWORD LogFileMonitor::GetLogFileEventStatus(DirChangeNotificationEvent& event)
{
DWORD status = ERROR_SUCCESS;
switch (event.Action)
{
case EventAction::Add:
{
status = LogFileAddEventHandler(event);
break;
}

case EventAction::Modify:
{
status = LogFileModifyEventHandler(event);
break;
}

case EventAction::Remove:
{
status = LogFileRemoveEventHandler(event);
break;
}

case EventAction::RenameNew:
{
status = LogFileRenameNewEventHandler(event);
break;
}

case EventAction::ReInit:
{
status = LogFileReInitEventHandler(event);
break;
}

case EventAction::RenameOld:
default:
break;
}

return status;
}


DWORD
LogFileMonitor::LogFileAddEventHandler(
_In_ DirChangeNotificationEvent& Event
Expand Down Expand Up @@ -1379,9 +1376,6 @@ LogFileMonitor::LogFileReInitEventHandler(
}

map<std::wstring, std::shared_ptr<LogFileInformation>>::iterator it;

//wprintf(L"LogFilesChangeHandler: Timer event\n");

for ( it = m_logFilesInformation.begin(); it != m_logFilesInformation.end(); it++ )
{
ReadLogFile(it->second);
Expand Down Expand Up @@ -1588,7 +1582,7 @@ LogFileMonitor::ReadLogFile(
{
remainingStringIndex = found + 1;

if ((found - 1) >= 0
if (found >= 1 // Ensures non-negative after subtraction
&& (decodedString[(found - 1)] == L'\n' || decodedString[(found - 1)] == L'\r')
&& decodedString[(found - 1)] != decodedString[found])
{
Expand Down Expand Up @@ -1816,8 +1810,6 @@ LogFileMonitor::GetFilesInDirectory(
FILE_ID_INFO fileId{ 0 };
GetFileId(fileName, fileId);

//wprintf(L"Started monitoring file: %s\n",fileName.c_str());

Files.push_back({ fileName, fileId });
}
} while (FindNextFile(hFind, &ffd) != 0);
Expand Down Expand Up @@ -1849,7 +1841,6 @@ LogFileMonitor::FileTypeFromBuffer(
LM_FILETYPE lmFileType = LM_FILETYPE::FileTypeUnknown;
FoundBomSize = 0;

PWSTR szBuf = (PWSTR)FileContents;
if (ContentSize <= 1 && BomSize <= 1)
{
return lmFileType;
Expand Down
2 changes: 2 additions & 0 deletions LogMonitor/src/LogMonitor/LogFileMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,6 @@ class LogFileMonitor final
_In_ const std::wstring &FullLongPath,
_Out_ FILE_ID_INFO &FileId,
_In_opt_ HANDLE Handle = INVALID_HANDLE_VALUE);

DWORD GetLogFileEventStatus(DirChangeNotificationEvent& event);
};