fscanary/main.cpp

61 lines
2.0 KiB
C++

/* Copyright (C) Sean McArdle - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* Written by Sean McArdle <sean@mcardletech.com>, Jun 21, 2017
*/
#include <iostream>
#include <chrono>
#include <thread>
#include "efsw/efsw.hpp"
#include "parg.h"
class UpdateListener : public efsw::FileWatchListener
{
public:
UpdateListener() {}
void handleFileAction( efsw::WatchID watchid, const std::string& dir, const std::string& filename, efsw::Action action, std::string oldFilename = "" )
{
switch( action )
{
case efsw::Actions::Add:
std::cout << "DIR (" << dir << ") FILE (" << filename << ") has event Added" << '\n';
break;
case efsw::Actions::Delete:
std::cout << "DIR (" << dir << ") FILE (" << filename << ") has event Delete" << '\n';
break;
case efsw::Actions::Modified:
std::cout << "DIR (" << dir << ") FILE (" << filename << ") has event Modified" << '\n';
break;
case efsw::Actions::Moved:
std::cout << "DIR (" << dir << ") FILE (" << filename << ") has event Moved from (" << oldFilename << ")" << '\n';
break;
default:
std::cout << "Should never happen!" << '\n';
}
}
};
int main() {
std::cout << "Hello, World!" << '\n';
auto fwatcher = new efsw::FileWatcher();
auto listener = new UpdateListener();
// Add a folder to watch, and get the efsw::WatchID
// It will watch the /tmp folder recursively ( the third parameter indicates that is recursive )
// Reporting the files and directories changes to the instance of the listener
efsw::WatchID watchID = fwatcher->addWatch( "~/Logs", listener, true );
// Start watching asynchronously the directories
fwatcher->watch();
while (true) {
std::this_thread::sleep_for(std::chrono::nanoseconds(100));
}
return 0;
}