MCPcopy Create free account
hub / github.com/MrKepzie/Natron / checkFileModificationAndWarnInternal

Method checkFileModificationAndWarnInternal

Gui/KnobGuiFile.cpp:241–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

notifyOnFileChangeMethod · 0.80
getCurrentSettingsMethod · 0.80
getFileNameMethod · 0.80
emptyMethod · 0.80
canonicalizePathMethod · 0.80
getProjectMethod · 0.80
toStdStringMethod · 0.80
lockMethod · 0.45
getHolderMethod · 0.45
isActivatedMethod · 0.45
getNodeMethod · 0.45

Tested by

no test coverage detected