Skip to content

Commit

Permalink
repair project files with invalid json for paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson committed Aug 27, 2021
1 parent 5468a9a commit 4238b0a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/classes/project_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ def load(self, file_path, clear_thumbnails=True):
default_project = self._data

try:
self.quote_json_keys(file_path)
# Attempt to load v2.X project file
project_data = self.read_from_file(file_path, path_mode="absolute")

Expand Down Expand Up @@ -647,7 +648,7 @@ def read_legacy_project_file(self, file_path):
# Increment track counter
track_counter += 1

except Exception:
except Exception as ex:
# Error parsing legacy contents
msg = "Failed to load legacy project file %(path)s" % {"path": file_path}
log.error(msg, exc_info=1)
Expand Down Expand Up @@ -720,6 +721,21 @@ def upgrade_project_data_structures(self):
if self._data.get("id") == "T0":
self._data["id"] = self.generate_id()

# Ensure projects can open
# after PR #4211 introduced a bug
# which wrote certain projects with invalid JSON.
def quote_json_keys(self, file_path):
import re

f = open(file_path)
txt = f.read()
f.close()
newText = re.sub('(\n\s*)(\w*):', r'\1"\2":', txt)
f = open(file_path, 'w')
f.write(newText)
f.close()
return

def save(self, file_path, move_temp_files=True, make_paths_relative=True):
""" Save project file to disk """
import openshot
Expand Down

0 comments on commit 4238b0a

Please sign in to comment.