diff --git a/opencore_legacy_patcher/application_entry.py b/opencore_legacy_patcher/application_entry.py index 4a950b6348..8617f5b2d9 100644 --- a/opencore_legacy_patcher/application_entry.py +++ b/opencore_legacy_patcher/application_entry.py @@ -45,6 +45,20 @@ def __init__(self) -> None: gui_entry.EntryPoint(self.constants).start() + def _fix_cwd(self) -> None: + """ + In some extreme scenarios, our current working directory may disappear + """ + _test_dir = None + try: + _test_dir = Path.cwd() + logging.info(f"Current working directory: {_test_dir}") + except FileNotFoundError: + _test_dir = Path(__file__).parent.parent.resolve() + os.chdir(_test_dir) + logging.warning(f"Current working directory was invalid, switched to: {_test_dir}") + + def _generate_base_data(self) -> None: """ Generate base data required for the patcher to run @@ -73,6 +87,7 @@ def _generate_base_data(self) -> None: # Generate environment data self.constants.recovery_status = utilities.check_recovery() utilities.disable_cls() + self._fix_cwd() # Generate binary data launcher_script = None