Skip to content

Commit

Permalink
kdk_handler.py: Add optional check_backups_only property
Browse files Browse the repository at this point in the history
Reduces false positives for Patcher’s `—cache_os` property, where an installed KDK would match against an expected backup
  • Loading branch information
khronokernel committed Nov 6, 2023
1 parent 432736e commit 139f94a
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions resources/kdk_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ class KernelDebugKitObject:
"""

def __init__(self, global_constants: constants.Constants, host_build: str, host_version: str, ignore_installed: bool = False, passive: bool = False) -> None:
def __init__(self, global_constants: constants.Constants,
host_build: str, host_version: str,
ignore_installed: bool = False, passive: bool = False,
check_backups_only: bool = False
) -> None:

self.constants: constants.Constants = global_constants

self.host_build: str = host_build # ex. 20A5384c
self.host_version: str = host_version # ex. 11.0.1

self.passive: bool = passive # Don't perform actions requiring elevated privileges

self.ignore_installed: bool = ignore_installed # If True, will ignore any installed KDKs and download the latest
self.ignore_installed: bool = ignore_installed # If True, will ignore any installed KDKs and download the latest
self.check_backups_only: bool = check_backups_only # If True, will only check for KDK backups, not KDKs already installed
self.kdk_already_installed: bool = False

self.kdk_installed_path: str = ""
Expand Down Expand Up @@ -400,18 +406,20 @@ def _local_kdk_installed(self, match: str = None, check_version: bool = False) -
if not Path(KDK_INSTALL_PATH).exists():
return None

for kdk_folder in Path(KDK_INSTALL_PATH).iterdir():
if not kdk_folder.is_dir():
continue
if check_version:
if match not in kdk_folder.name:
# Installed KDKs only
if self.check_backups_only is False:
for kdk_folder in Path(KDK_INSTALL_PATH).iterdir():
if not kdk_folder.is_dir():
continue
else:
if not kdk_folder.name.endswith(f"{match}.kdk"):
continue

if self._local_kdk_valid(kdk_folder):
return kdk_folder
if check_version:
if match not in kdk_folder.name:
continue
else:
if not kdk_folder.name.endswith(f"{match}.kdk"):
continue

if self._local_kdk_valid(kdk_folder):
return kdk_folder

# If we can't find a KDK, next check if there's a backup present
# Check for KDK packages in the same directory as the KDK
Expand Down

0 comments on commit 139f94a

Please sign in to comment.