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

Method checkFileModificationAndWarnInternal

Gui/KnobGuiFile.cpp:242–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242bool
243KnobGuiFile::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;

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