Merge changes from upstream

This commit is contained in:
2024-12-18 16:43:35 -05:00
7 changed files with 134 additions and 104 deletions

View File

@@ -18,6 +18,15 @@ class TitleData:
danger: str
@dataclass
class BatchTitleData:
# Class to store all data for a Title in a batch operation.
tid: str
version: int
console: str
archive_name: str
def check_nusget_updates(app, current_version: str, progress_callback=None) -> str | None:
# Simple function to make a request to the GitHub API and then check if the latest available version is newer.
gh_api_request = requests.get(url="https://api.github.com/repos/NinjaCheetah/NUSGet/releases/latest", stream=True)

40
modules/download_batch.py Normal file
View File

@@ -0,0 +1,40 @@
# "modules/download_batch.py", licensed under the MIT license
# Copyright 2024 NinjaCheetah
import pathlib
from typing import List
from modules.core import BatchTitleData
from modules.download_dsi import run_nus_download_dsi
from modules.download_wii import run_nus_download_wii
def run_nus_download_batch(out_folder: pathlib.Path, titles: List[BatchTitleData], pack_wad_chkbox: bool,
keep_enc_chkbox: bool, decrypt_contents_chkbox: bool, wiiu_nus_chkbox: bool,
use_local_chkbox: bool, repack_vwii_chkbox: bool, patch_ios: bool,
progress_callback=None):
for title in titles:
if title.version == -1:
version_str = "Latest"
else:
version_str = str(title.version)
if title.console == "Wii" or title.console == "vWii":
if title.archive_name != "":
archive_name = f"{title.archive_name}-v{version_str}-{title.console}.wad"
else:
archive_name = f"{title.tid}-v{version_str}-{title.console}.wad"
result = run_nus_download_wii(out_folder, title.tid, version_str, pack_wad_chkbox, keep_enc_chkbox,
decrypt_contents_chkbox, wiiu_nus_chkbox, use_local_chkbox, repack_vwii_chkbox,
patch_ios, archive_name, progress_callback)
if result != 0:
return result
elif title.console == "DSi":
if title.archive_name != "":
archive_name = f"{title.archive_name}-v{version_str}-{title.console}.tad"
else:
archive_name = f"{title.tid}-v{version_str}-{title.console}.tad"
result = run_nus_download_dsi(out_folder, title.tid, version_str, pack_wad_chkbox, keep_enc_chkbox,
decrypt_contents_chkbox, use_local_chkbox, archive_name, progress_callback)
if result != 0:
return result
progress_callback.emit(f"Batch download finished.")
return 0

View File

@@ -99,6 +99,8 @@ def run_nus_download_dsi(out_folder: pathlib.Path, tid: str, version: str, pack_
# Use a typed TAD name if there is one, and auto generate one based on the TID and version if there isn't.
progress_callback.emit("Packing TAD...")
if tad_file_name != "" and tad_file_name is not None:
# Batch downloads may insert -vLatest, so if it did we can fill in the real number now.
tad_file_name = tad_file_name.replace("-vLatest", f"-v{title_version}")
if tad_file_name[-4:].lower() != ".tad":
tad_file_name += ".tad"
else:
@@ -112,15 +114,3 @@ def run_nus_download_dsi(out_folder: pathlib.Path, tid: str, version: str, pack_
if (not pack_tad_enabled and pack_tad_chkbox) or (not decrypt_contents_enabled and decrypt_contents_chkbox):
return 1
return 0
def run_nus_download_dsi_batch(out_folder: pathlib.Path, titles: List[Tuple[str, str, str]], pack_tad_chkbox: bool,
keep_enc_chkbox: bool, decrypt_contents_chkbox: bool, use_local_chkbox: bool,
progress_callback=None):
for title in titles:
result = run_nus_download_dsi(out_folder, title[0], title[1], pack_tad_chkbox, keep_enc_chkbox,
decrypt_contents_chkbox, use_local_chkbox, f"{title[2]}-{title[1]}.tad",
progress_callback)
if result != 0:
return result
progress_callback.emit(f"Batch download finished.")
return 0

View File

@@ -150,6 +150,8 @@ def run_nus_download_wii(out_folder: pathlib.Path, tid: str, version: str, pack_
# Use a typed WAD name if there is one, and auto generate one based on the TID and version if there isn't.
progress_callback.emit(" - Packing WAD...")
if wad_file_name != "" and wad_file_name is not None:
# Batch downloads may insert -vLatest, so if it did we can fill in the real number now.
wad_file_name = wad_file_name.replace("-vLatest", f"-v{title_version}")
if wad_file_name[-4:].lower() != ".wad":
wad_file_name += ".wad"
else:
@@ -174,16 +176,3 @@ def run_nus_download_wii(out_folder: pathlib.Path, tid: str, version: str, pack_
if (not pack_wad_enabled and pack_wad_chkbox) or (not decrypt_contents_enabled and decrypt_contents_chkbox):
return 1
return 0
def run_nus_download_wii_batch(out_folder: pathlib.Path, titles: List[Tuple[str, str, str]], pack_wad_chkbox: bool,
keep_enc_chkbox: bool, decrypt_contents_chkbox: bool, wiiu_nus_chkbox: bool,
use_local_chkbox: bool, repack_vwii_chkbox: bool, patch_ios: bool,
progress_callback=None):
for title in titles:
result = run_nus_download_wii(out_folder, title[0], title[1], pack_wad_chkbox, keep_enc_chkbox,
decrypt_contents_chkbox, wiiu_nus_chkbox, use_local_chkbox, repack_vwii_chkbox,
patch_ios, f"{title[2]}-{title[1]}.wad", progress_callback)
if result != 0:
return result
progress_callback.emit(f"Batch download finished.")
return 0

View File

@@ -11,7 +11,7 @@ class TreeItem:
self.data = data
self.parent = parent
self.children = []
self.metadata = metadata # Store hidden metadata
self.metadata = metadata
def add_child(self, item):
self.children.append(item)
@@ -53,14 +53,16 @@ class NUSGetTreeModel(QAbstractItemModel):
name = entry.get("Name")
versions = entry.get("Versions", {})
if tid:
tid_item = TreeItem([f"{tid} - {name}", ""], key_item)
tid_item = TreeItem([f"{tid} - {name}", ""], key_item, entry.get("Ticket"))
key_item.add_child(tid_item)
for region, version_list in versions.items():
region_item = TreeItem([region, ""], tid_item)
tid_item.add_child(region_item)
for version in version_list:
danger = entry.get("Danger") if entry.get("Danger") is not None else ""
metadata = TitleData(entry.get("TID"), entry.get("Name"), entry.get("Archive Name"),
archive_name = (entry.get("Archive Name") if entry.get("Archive Name") is not None
else entry.get("Name").replace(" ", "-"))
metadata = TitleData(entry.get("TID"), entry.get("Name"), archive_name,
version, entry.get("Ticket"), region, key, danger)
public_versions = entry.get("Public Versions")
if public_versions is not None:
@@ -96,12 +98,11 @@ class NUSGetTreeModel(QAbstractItemModel):
if role == Qt.DecorationRole and index.column() == 0:
# Check for icons based on the "Ticket" metadata only at the TID level
if item.parent and item.parent.data_at(0) == "System":
if item.metadata and "Ticket" in item.metadata:
if item.metadata["Ticket"]:
return QIcon.fromTheme("dialog-ok") # Checkmark icon
else:
return QIcon.fromTheme("dialog-cancel") # X icon
if item.metadata is not None and isinstance(item.metadata, bool):
if item.metadata is True:
return QIcon.fromTheme("dialog-ok")
else:
return QIcon.fromTheme("dialog-cancel")
return None
def headerData(self, section, orientation, role=Qt.DisplayRole):