Skip to content

Commit

Permalink
fix update status of DLC
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ex4 committed Nov 15, 2023
1 parent 82083ec commit 42a66cb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
20 changes: 17 additions & 3 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,26 @@ def get_all_titles():
title.update(library_status)
title['title_id_name'] = title['name']
if title['type'] == APP_TYPE_DLC:
dlc_has_latest_version = None
all_dlc_existing_versions = get_all_dlc_existing_versions(title['app_id'])

if title['version'] == all_dlc_existing_versions[-1]:
title['has_latest_version'] = True
if all_dlc_existing_versions is not None and len(all_dlc_existing_versions):
if title['version'] == all_dlc_existing_versions[-1]:
dlc_has_latest_version = True
else:
dlc_has_latest_version = False

else:
title['has_latest_version'] = False
app_id_version_from_versions_txt = get_app_id_version_from_versions_txt(title['app_id'])
if app_id_version_from_versions_txt is not None:
if title['version'] == int(app_id_version_from_versions_txt):
dlc_has_latest_version = True
else:
dlc_has_latest_version = False


if dlc_has_latest_version is not None:
title['has_latest_version'] = dlc_has_latest_version

titleid_info = get_game_info(title['title_id'])
title['title_id_name'] = titleid_info['name']
Expand Down
17 changes: 16 additions & 1 deletion app/titles.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def load_titledb(app_settings):
global cnmts_db
global titles_db
global versions_db
global versions_txt_db
with open(os.path.join(TITLEDB_DIR, 'cnmts.json')) as f:
cnmts_db = json.load(f)

Expand All @@ -108,6 +109,13 @@ def load_titledb(app_settings):
with open(os.path.join(TITLEDB_DIR, 'versions.json')) as f:
versions_db = json.load(f)

versions_txt_db = {}
with open(os.path.join(TITLEDB_DIR, 'versions.txt')) as f:
for line in f:
line_strip = line.rstrip("\n")
app_id, rightsId, version = line_strip.split('|')
versions_txt_db[app_id] = version

def identify_file_from_filename(filename):
version = get_version_from_filename(filename)
if version is None:
Expand Down Expand Up @@ -225,11 +233,18 @@ def get_all_dlc_existing_versions(app_id):
app_id = app_id.lower()
if app_id in cnmts_db:
versions_from_cnmts_db = cnmts_db[app_id].keys()
return sorted(versions_from_cnmts_db)
if len(versions_from_cnmts_db):
return sorted(versions_from_cnmts_db)
else:
print(f'No keys in cnmts.json for DLC app ID: {app_id.upper()}')
return None
else:
print(f'DLC app ID not in cnmts.json: {app_id.upper()}')
return None

def get_app_id_version_from_versions_txt(app_id):
return versions_txt_db.get(app_id, None)

def get_all_existing_dlc(title_id):
title_id = title_id.lower()
dlcs = []
Expand Down

0 comments on commit 42a66cb

Please sign in to comment.