mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-06-15 11:50:00 +10:00
updates.py: Adjust private function names
This commit is contained in:
@@ -255,7 +255,7 @@ class wx_python_gui:
|
||||
if local_build_date <= installed_build_date:
|
||||
return False
|
||||
|
||||
elif updates.check_binary_updates(self.constants).check_if_build_newer(local_version, application_version) is False:
|
||||
elif updates.CheckBinaryUpdates(self.constants)._check_if_build_newer(local_version, application_version) is False:
|
||||
return False
|
||||
|
||||
# Ask user if they want to move the application to the Applications folder
|
||||
@@ -310,7 +310,7 @@ class wx_python_gui:
|
||||
if ignore_updates is not True:
|
||||
self.constants.ignore_updates = False
|
||||
self.constants.has_checked_updates = True
|
||||
dict = updates.check_binary_updates(self.constants).check_binary_updates()
|
||||
dict = updates.CheckBinaryUpdates(self.constants).check_binary_updates()
|
||||
if dict:
|
||||
for entry in dict:
|
||||
version = dict[entry]["Version"]
|
||||
|
||||
@@ -46,7 +46,7 @@ class AutomaticSysPatch:
|
||||
if patches[patch] is True and not patch.startswith("Settings") and not patch.startswith("Validation"):
|
||||
patch_string += f"- {patch}\n"
|
||||
# Check for updates
|
||||
dict = updates.check_binary_updates(self.constants).check_binary_updates()
|
||||
dict = updates.CheckBinaryUpdates(self.constants).check_binary_updates()
|
||||
if not dict:
|
||||
logging.info("- No new binaries found on Github, proceeding with patching")
|
||||
if self.constants.launcher_script is None:
|
||||
@@ -128,7 +128,7 @@ class AutomaticSysPatch:
|
||||
return False
|
||||
|
||||
# Check if installed version is newer than booted version
|
||||
if updates.check_binary_updates(self.constants).check_if_build_newer(
|
||||
if updates.CheckBinaryUpdates(self.constants)._check_if_build_newer(
|
||||
self.constants.computer.oclp_version.split("."), self.constants.patcher_version.split(".")
|
||||
) is True:
|
||||
logging.info("- Installed version is newer than booted version")
|
||||
|
||||
+71
-45
@@ -10,17 +10,26 @@ from resources import network_handler, constants
|
||||
REPO_LATEST_RELEASE_URL: str = "https://api.github.com/repos/dortania/OpenCore-Legacy-Patcher/releases/latest"
|
||||
|
||||
|
||||
class check_binary_updates:
|
||||
class CheckBinaryUpdates:
|
||||
def __init__(self, global_constants: constants.Constants):
|
||||
self.constants: constants.Constants = global_constants
|
||||
|
||||
self.binary_version = self.constants.patcher_version
|
||||
self.binary_version_array = [int(x) for x in self.binary_version.split(".")]
|
||||
|
||||
self.available_binaries = {}
|
||||
|
||||
def _check_if_build_newer(self, remote_version: list = None, local_version: list = None):
|
||||
"""
|
||||
Check if the remote version is newer than the local version
|
||||
|
||||
Parameters:
|
||||
remote_version (list): Remote version to compare against
|
||||
local_version (list): Local version to compare against
|
||||
|
||||
Returns:
|
||||
bool: True if remote version is newer, False if not
|
||||
"""
|
||||
|
||||
def check_if_build_newer(self, remote_version=None, local_version=None):
|
||||
if remote_version is None:
|
||||
remote_version = self.remote_version_array
|
||||
if local_version is None:
|
||||
@@ -40,13 +49,32 @@ class check_binary_updates:
|
||||
|
||||
return False
|
||||
|
||||
def determine_local_build_type(self):
|
||||
|
||||
def _determine_local_build_type(self):
|
||||
"""
|
||||
Check if the local build is a GUI or TUI build
|
||||
|
||||
Returns:
|
||||
str: "GUI" or "TUI"
|
||||
"""
|
||||
|
||||
if self.constants.wxpython_variant is True:
|
||||
return "GUI"
|
||||
else:
|
||||
return "TUI"
|
||||
|
||||
def determine_remote_type(self, remote_name):
|
||||
|
||||
def _determine_remote_type(self, remote_name: str):
|
||||
"""
|
||||
Check if the remote build is a GUI or TUI build
|
||||
|
||||
Parameters:
|
||||
remote_name (str): Name of the remote build
|
||||
|
||||
Returns:
|
||||
str: "GUI" or "TUI"
|
||||
"""
|
||||
|
||||
if "TUI" in remote_name:
|
||||
return "TUI"
|
||||
elif "GUI" in remote_name:
|
||||
@@ -54,45 +82,43 @@ class check_binary_updates:
|
||||
else:
|
||||
return "Unknown"
|
||||
|
||||
|
||||
def check_binary_updates(self):
|
||||
# logging.info("- Checking for updates...")
|
||||
if network_handler.NetworkUtilities(REPO_LATEST_RELEASE_URL).verify_network_connection():
|
||||
# logging.info("- Network connection functional")
|
||||
response = requests.get(REPO_LATEST_RELEASE_URL)
|
||||
data_set = response.json()
|
||||
# logging.info("- Retrieved latest version data")
|
||||
self.remote_version = data_set["tag_name"]
|
||||
# logging.info(f"- Latest version: {self.remote_version}")
|
||||
self.remote_version_array = self.remote_version.split(".")
|
||||
self.remote_version_array = [
|
||||
int(x) for x in self.remote_version_array
|
||||
]
|
||||
if self.check_if_build_newer() is True:
|
||||
# logging.info("- Remote version is newer")
|
||||
for asset in data_set["assets"]:
|
||||
logging.info(f"- Found asset: {asset['name']}")
|
||||
if self.determine_remote_type(asset["name"]) == self.determine_local_build_type():
|
||||
# logging.info(f"- Found matching asset: {asset['name']}")
|
||||
self.available_binaries.update({
|
||||
asset['name']: {
|
||||
"Name":
|
||||
asset["name"],
|
||||
"Version":
|
||||
self.remote_version,
|
||||
"Link":
|
||||
asset["browser_download_url"],
|
||||
"Type":
|
||||
self.determine_remote_type(asset["name"]),
|
||||
"Github Link":
|
||||
f"https://github.com/dortania/OpenCore-Legacy-Patcher/releases/{self.remote_version}"
|
||||
}
|
||||
})
|
||||
break
|
||||
if self.available_binaries:
|
||||
return self.available_binaries
|
||||
else:
|
||||
# logging.info("- No matching binaries available")
|
||||
return None
|
||||
# else:
|
||||
# logging.info("- Failed to connect to GitHub API")
|
||||
"""
|
||||
Check if any updates are available for the OpenCore Legacy Patcher binary
|
||||
|
||||
Returns:
|
||||
dict: Dictionary with Link and Version of the latest binary update if available
|
||||
"""
|
||||
|
||||
available_binaries: list = {}
|
||||
|
||||
if not network_handler.NetworkUtilities(REPO_LATEST_RELEASE_URL).verify_network_connection():
|
||||
return None
|
||||
|
||||
response = requests.get(REPO_LATEST_RELEASE_URL)
|
||||
data_set = response.json()
|
||||
|
||||
self.remote_version = data_set["tag_name"]
|
||||
|
||||
self.remote_version_array = self.remote_version.split(".")
|
||||
self.remote_version_array = [int(x) for x in self.remote_version_array]
|
||||
|
||||
if self._check_if_build_newer() is False:
|
||||
return None
|
||||
|
||||
for asset in data_set["assets"]:
|
||||
logging.info(f"- Found asset: {asset['name']}")
|
||||
if self._determine_remote_type(asset["name"]) == self._determine_local_build_type():
|
||||
available_binaries.update({
|
||||
asset['name']: {
|
||||
"Name": asset["name"],
|
||||
"Version": self.remote_version,
|
||||
"Link": asset["browser_download_url"],
|
||||
"Type": self._determine_remote_type(asset["name"]),
|
||||
"Github Link": f"https://github.com/dortania/OpenCore-Legacy-Patcher/releases/{self.remote_version}"
|
||||
}
|
||||
})
|
||||
return available_binaries
|
||||
|
||||
return None
|
||||
Reference in New Issue
Block a user