|
|
@ -4,8 +4,9 @@ namespace ofx { |
|
|
|
namespace piMapper { |
|
|
|
|
|
|
|
DirectoryWatcher::DirectoryWatcher(string path, int watcherMediaType){ |
|
|
|
directoryPath = path; |
|
|
|
_mediaType = watcherMediaType; |
|
|
|
|
|
|
|
|
|
|
|
if(_mediaType == SourceType::SOURCE_TYPE_VIDEO){ |
|
|
|
_directory.allowExt("mp4"); |
|
|
|
_directory.allowExt("h264"); |
|
|
@ -21,20 +22,27 @@ DirectoryWatcher::DirectoryWatcher(string path, int watcherMediaType){ |
|
|
|
ofLogFatalError("DirectoryWatcher::DirectoryWatcher", "Unkonwn media type"); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
|
|
|
|
_directory.listDir(path); |
|
|
|
|
|
|
|
_directory.listDir(directoryPath); |
|
|
|
_directory.sort(); |
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < _directory.size(); ++i){ |
|
|
|
_filePaths.push_back(path + _directory.getName(i)); |
|
|
|
|
|
|
|
ofFile file(path + _directory.getName(i)); |
|
|
|
_filePaths.push_back(directoryPath + _directory.getName(i)); |
|
|
|
|
|
|
|
ofFile file(directoryPath + _directory.getName(i)); |
|
|
|
if(_mediaType == SourceType::SOURCE_TYPE_VIDEO){ |
|
|
|
file.copyTo("sources/videos/" + _directory.getName(i)); |
|
|
|
}else if(_mediaType == SourceType::SOURCE_TYPE_IMAGE){ |
|
|
|
file.copyTo("sources/images/" + _directory.getName(i)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
dirSize = _directory.size(); |
|
|
|
} |
|
|
|
|
|
|
|
DirectoryWatcher::~DirectoryWatcher() { |
|
|
|
endWatch(); |
|
|
|
// waitForThread(false);
|
|
|
|
} |
|
|
|
|
|
|
|
vector <string> & DirectoryWatcher::getFilePaths(){ |
|
|
@ -45,5 +53,28 @@ int DirectoryWatcher::getMediaType(){ |
|
|
|
return _mediaType; |
|
|
|
} |
|
|
|
|
|
|
|
void DirectoryWatcher::beginWatch(int intervalInMillis) { |
|
|
|
watchInterval = intervalInMillis; |
|
|
|
startThread(); |
|
|
|
} |
|
|
|
|
|
|
|
void DirectoryWatcher::endWatch() { |
|
|
|
stopThread(); |
|
|
|
} |
|
|
|
|
|
|
|
void DirectoryWatcher::threadedFunction() { |
|
|
|
|
|
|
|
while (isThreadRunning()) { |
|
|
|
|
|
|
|
int newSize = _directory.listDir(); |
|
|
|
if (newSize != dirSize) { |
|
|
|
ofLogVerbose("DirectoryWatcher") << "Directory changed"; |
|
|
|
ofNotifyEvent(directoryFileCountChangedEvent, this); |
|
|
|
} |
|
|
|
|
|
|
|
sleep(watchInterval); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} // namespace piMapper
|
|
|
|
} // namespace ofx
|
|
|
|