51 using namespace FIFFLIB;
57 const static char m_sDefaultDirectory[](
"realtime_shared_files");
58 const static char m_sDefaultFileName[](
"realtime_file");
72 : m_sDirectory(QDir::currentPath() +
"/" + sDirName)
81 if(initSharedDirectory()){
82 QString sFilePath(m_sDirectory +
"/" + m_sDefaultFileName + QString::number(m_iFileIndex++) +
"_raw.fif");
84 if(QFile::copy(sSourcePath, sFilePath)){
85 QFile newFile(sFilePath);
86 if(newFile.open(QIODevice::ReadWrite)){
88 stream.skipRawData(newFile.bytesAvailable());
101 if(initSharedDirectory()){
102 clearSharedDirectory();
103 m_fileWatcher.addPath(m_sDirectory);
104 connect(&m_fileWatcher, &QFileSystemWatcher::directoryChanged,
105 this, &FiffFileSharer::onDirectoryChanged, Qt::UniqueConnection);
106 connect(&m_fileWatcher, &QFileSystemWatcher::fileChanged,
107 this, &FiffFileSharer::onFileChanged, Qt::UniqueConnection);
109 qWarning() <<
"[FiffFileSharer::initWatcher] Unable to initilaize shared directory";
115 void FiffFileSharer::clearSharedDirectory()
117 QDir directory(m_sDirectory);
118 directory.setNameFilters(QStringList(
"*.*"));
119 directory.setFilter(QDir::Files);
120 for(
auto& file : directory.entryList()){
121 directory.remove(file);
127 void FiffFileSharer::onDirectoryChanged(
const QString &sPath)
129 QString filePath(sPath +
"/" + m_sDefaultFileName + QString::number(m_iFileIndex) +
"_raw.fif");
130 m_fileWatcher.addPath(filePath);
135 void FiffFileSharer::onFileChanged(
const QString &sPath)
138 m_fileWatcher.removePath(sPath);
145 bool FiffFileSharer::initSharedDirectory()
147 QDir sharedDirectory(m_sDirectory);
148 if(!sharedDirectory.exists()){
149 sharedDirectory.mkpath(
".");
152 return sharedDirectory.exists();