Skip to content

Commit

Permalink
application_entry.py: Add handling for when CWD disappears
Browse files Browse the repository at this point in the history
  • Loading branch information
khronokernel committed May 31, 2024
1 parent b62eb7e commit 8f0e8d6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions opencore_legacy_patcher/application_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8f0e8d6

Please sign in to comment.