Skip to content

Commit

Permalink
Merge pull request OpenShot#2275 from fschill/fix_project_media_relink
Browse files Browse the repository at this point in the history
fix for automatic relinking of missing media files during project open
  • Loading branch information
DylanC authored Nov 1, 2018
2 parents c9f49f2 + ba00580 commit 2a4ab70
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions src/classes/project_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,42 +906,64 @@ def check_if_paths_are_valid(self):

from PyQt5.QtWidgets import QFileDialog, QMessageBox

log.info("checking project files...")

# Loop through each files (in reverse order)
for file in reversed(self._data["files"]):
path = file["path"]
parent_path, file_name_with_ext = os.path.split(path)

log.info("checking file %s" % path)
while not os.path.exists(path) and "%" not in path:
# File already exists! Prompt user to find missing file
QMessageBox.warning(None, _("Missing File (%s)") % file["id"], _("%s cannot be found.") % file_name_with_ext)
starting_folder = QFileDialog.getExistingDirectory(None, _("Find directory that contains: %s" % file_name_with_ext), starting_folder)
log.info("Missing folder chosen by user: %s" % starting_folder)
if starting_folder:
# Update file path and import_path
path = os.path.join(starting_folder, file_name_with_ext)
# try to find clip with previous starting folder:
if starting_folder and os.path.exists(os.path.join(starting_folder, file_name_with_ext)):
# Update clip path
file["path"] = path
get_app().updates.update(["import_path"], os.path.dirname(path))
else:
log.info('Removed missing file: %s' % file_name_with_ext)
self._data["files"].remove(file)
log.info("Auto-updated missing file: %s" % file["path"])
break
else:
QMessageBox.warning(None, _("Missing File (%s)") % file["id"], _("%s cannot be found.") % file_name_with_ext)
starting_folder = QFileDialog.getExistingDirectory(None, _("Find directory that contains: %s" % file_name_with_ext), starting_folder)
log.info("Missing folder chosen by user: %s" % starting_folder)
if starting_folder:
# Update file path and import_path
path = os.path.join(starting_folder, file_name_with_ext)
file["path"] = path
get_app().updates.update(["import_path"], os.path.dirname(path))
else:
log.info('Removed missing file: %s' % file_name_with_ext)
self._data["files"].remove(file)
break

# Loop through each clip (in reverse order)
for clip in reversed(self._data["clips"]):
path = clip["reader"]["path"]
parent_path, file_name_with_ext = os.path.split(path)

log.info("checking file %s" % path)
while not os.path.exists(path) and "%" not in path:
# Clip already exists! Prompt user to find missing file
QMessageBox.warning(None, _("Missing File in Clip (%s)") % clip["id"], _("%s cannot be found.") % file_name_with_ext)
starting_folder = QFileDialog.getExistingDirectory(None, _("Find directory that contains: %s" % file_name_with_ext), starting_folder)
log.info("Missing folder chosen by user: %s" % starting_folder)
if starting_folder:
# try to find clip with previous starting folder:
if starting_folder and os.path.exists(os.path.join(starting_folder, file_name_with_ext)):
# Update clip path
path = os.path.join(starting_folder, file_name_with_ext)
clip["reader"]["path"] = path
else:
log.info('Removed missing clip: %s' % file_name_with_ext)
self._data["clips"].remove(clip)
log.info("Auto-updated missing file: %s" % clip["reader"]["path"])
break
else:
QMessageBox.warning(None, _("Missing File in Clip (%s)") % clip["id"], _("%s cannot be found.") % file_name_with_ext)
starting_folder = QFileDialog.getExistingDirectory(None, _("Find directory that contains: %s" % file_name_with_ext), starting_folder)
log.info("Missing folder chosen by user: %s" % starting_folder)
if starting_folder:
# Update clip path
path = os.path.join(starting_folder, file_name_with_ext)
clip["reader"]["path"] = path
else:
log.info('Removed missing clip: %s' % file_name_with_ext)
self._data["clips"].remove(clip)
break

def convert_paths_to_absolute(self):
""" Convert all paths to absolute """
Expand Down

0 comments on commit 2a4ab70

Please sign in to comment.