| 240 | } |
| 241 | |
| 242 | bool |
| 243 | KnobGuiFile::checkFileModificationAndWarnInternal(bool doCheck, |
| 244 | SequenceTime time, |
| 245 | bool errorAndAbortRender) |
| 246 | { |
| 247 | bool useNotifications = appPTR->getCurrentSettings()->notifyOnFileChange(); |
| 248 | |
| 249 | if (!useNotifications) { |
| 250 | return false; |
| 251 | } |
| 252 | KnobFilePtr knob = _knob.lock(); |
| 253 | if (!knob) { |
| 254 | return false; |
| 255 | } |
| 256 | EffectInstance* effect = dynamic_cast<EffectInstance*>( knob->getHolder() ); |
| 257 | assert(effect); |
| 258 | if ( !effect || !effect->getNode()->isActivated() ) { |
| 259 | return false; |
| 260 | } |
| 261 | |
| 262 | ///Get the current file, if it exists, add the file path to the file system watcher |
| 263 | ///to get notified if the file changes. |
| 264 | std::string filepath = knob->getFileName( time, knob->getCurrentView() ); |
| 265 | if ( !filepath.empty() && knob->getHolder() && knob->getHolder()->getApp() ) { |
| 266 | knob->getHolder()->getApp()->getProject()->canonicalizePath(filepath); |
| 267 | } |
| 268 | |
| 269 | QString qfilePath = QString::fromUtf8( filepath.c_str() ); |
| 270 | if ( !QFile::exists(qfilePath) ) { |
| 271 | return false; |
| 272 | } |
| 273 | |
| 274 | QDateTime date; |
| 275 | std::map<std::string, QDateTime>::iterator foundModificationDate = _lastModificationDates.find(filepath); |
| 276 | QFileInfo info(qfilePath); |
| 277 | date = info.lastModified(); |
| 278 | |
| 279 | //We already have a modification date |
| 280 | bool ret = false; |
| 281 | if ( foundModificationDate != _lastModificationDates.end() ) { |
| 282 | if ( doCheck && (date != foundModificationDate->second) ) { |
| 283 | if (errorAndAbortRender) { |
| 284 | QString warn = tr("The file \"%1\" has changed on disk.\n" |
| 285 | "Press reload file to load the new version of the file").arg(qfilePath); |
| 286 | effect->setPersistentMessage( eMessageTypeError, warn.toStdString() ); |
| 287 | effect->abortAnyEvaluation(); |
| 288 | } |
| 289 | effect->purgeCaches(); |
| 290 | effect->getNode()->removeAllImagesFromCache(true); |
| 291 | _lastModificationDates.clear(); |
| 292 | ret = true; |
| 293 | } else { |
| 294 | return false; |
| 295 | } |
| 296 | } |
| 297 | _lastModificationDates.insert( std::make_pair(filepath, date) ); |
| 298 | |
| 299 | return ret; |
nothing calls this directly
no test coverage detected