Skip to content

Commit

Permalink
Merge pull request #166 from mocchapi/main
Browse files Browse the repository at this point in the history
Purrform checks on theme repository format version
  • Loading branch information
Dpeta authored Feb 4, 2024
2 parents 5ab95b4 + 7a74303 commit 9014a8a
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions theme_repo_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class ThemeManager(QtCore.QObject):
manifest_path = os.path.join(getDataDir(), "manifest.js")
NAManager = None

supported_version = 3

downloads = {}

def __init__(self, config):
Expand Down Expand Up @@ -131,9 +133,9 @@ def download_theme(self, theme_name):
QtCore.QUrl(self.database_entries[theme_name]["download"])
)
)
self.downloads[self.database_entries[theme_name]["download"]] = (
self.database_entries[theme_name]
)
self.downloads[
self.database_entries[theme_name]["download"]
] = self.database_entries[theme_name]

def install_theme(self, theme_name, force_install=False):
# A higher way to install a theme than download_theme
Expand Down Expand Up @@ -279,8 +281,24 @@ def _on_reply(self, reply):
as_json = bytes(reply.readAll()).decode("utf-8")
self.database = json.loads(as_json)
self.database_entries = {}

version = self.database.get("meta", {}).get("format_version")

if version != self.supported_version:
err = ""
if version > self.supported_version:
err = f"Theme database is too new! (got v{version} instead of supported v{self.supported_version}). Try checking if there is a new client update available!"
else:
err = f"Theme database is too old! (got v{version} instead of supported v{self.supported_version})."
PchumLog.error(err)
self.errored.emit(err)
self.database = {}
self.database_entries = {}
return

if not self.is_database_valid():
self.database = {}
self.database_entries = {}
PchumLog.error('Incorrect database format, missing "entries"')
self.errored.emit('Incorrect database format, missing "entries"')
return
Expand Down

0 comments on commit 9014a8a

Please sign in to comment.