I'm testing with wx 2.91 and wxFileSystemWatcher. I want to oberve a dir and notify my app if a file was created or modified.
Here's my wxFileSystemWatcher-Class:
My header-file:
Code: Select all
#pragma once
#ifndef HHFILEWATCHER_H
#define HHFILEWATCHER_H
extern const wxEventType wxEVT_CMD_JOB_STATUS;
extern const wxEventType wxEVT_CMD_JOB_STATUS_VOID_PTR;
#include <wx/fswatcher.h>
#include "ProviderFinder.h"
class HHFileWatcher : public wxFileSystemWatcher
{
public:
HHFileWatcher(void);
~HHFileWatcher(void);
ProviderFinder ProviderDef;
void SendEvent(int i, wxString &msg);
wxString tmpfilename;
protected:
void OnChange(int changeType, const wxFileName& path, const wxFileName& newPath);
void OnWarning(const wxString &errorMessage);
void OnError(const wxString &errorMessage);
};
#endif // HHFILEWATCHER_H
Code: Select all
#include "HHFileWatcher.h"
HHFileWatcher::HHFileWatcher(void)
{
}
HHFileWatcher::~HHFileWatcher(void)
{
}
void HHFileWatcher::OnChange(int changeType, const wxFileName& path, const wxFileName& newPath)
{
if( (changeType != wxFSW_EVENT_DELETE) || (changeType != wxFSW_EVENT_ERROR) || (changeType != wxFSW_EVENT_WARNING) || (changeType != wxFSW_EVENT_ACCESS) )
{
if( path.GetExt().Find(_T("txt")) > wxNOT_FOUND )
{
if(ProviderDef.GetProviderFromFile(path.GetFullPath()) > 0)
{
tmpfilename = wxString::Format(_T("FILE_TO_PARSE:%s"), path.GetFullPath());
SendEvent(0, tmpfilename);
}
}
}
}
void HHFileWatcher::OnWarning(const wxString &errorMessage)
{
}
void HHFileWatcher::OnError(const wxString &errorMessage)
{
}
void HHFileWatcher::SendEvent(int i, wxString &msg)
{
if (GetOwner()) {
wxCommandEvent e(wxEVT_CMD_JOB_STATUS);
e.SetInt(i);
e.SetString(msg);
GetOwner()->AddPendingEvent(e);
}
}
Code: Select all
FileWatcher = new HHFileWatcher();
FileWatcher->SetOwner(this);
wxFileName dirname( "C:\wurst", "" );
FileWatcher->Add(wxFileName::DirName("C:\wurst"), wxFSW_EVENT_ALL);
Any idea what could be the error? Am I doing it wrong?
Thank you very much