From dccc39633b029974f10cb7a9444fbea912e7be28 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Thu, 8 Jun 2023 09:56:01 -0600 Subject: [PATCH 1/2] gui_update.py: Work-around users manually moving app Oversight from original update system, users were not expected to manually move the app to `/Applications`. This will ensure that there will always be a symlink instead --- CHANGELOG.md | 2 ++ resources/wx_gui/gui_main_menu.py | 33 ++++++++++++++++++++++++++++++- resources/wx_gui/gui_update.py | 10 ++++++---- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ca0a4f38..05a3152d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Update non-Metal Binaries: - Improve experimental Menubar implementation stability - Implement reduce transparency Menubar +- Resolve app not updating in `/Applications` after an update + - Work-around users manually copying app to `/Applications` instead of allowing Root Volume Patcher to create a proper alias - Increment Binaries: - PatcherSupportPkg 1.1.3 - release diff --git a/resources/wx_gui/gui_main_menu.py b/resources/wx_gui/gui_main_menu.py index 91b5502d7..6914e2a8e 100644 --- a/resources/wx_gui/gui_main_menu.py +++ b/resources/wx_gui/gui_main_menu.py @@ -4,6 +4,9 @@ import sys import logging import threading import webbrowser +import subprocess + +from pathlib import Path from resources.wx_gui import ( gui_build, @@ -11,7 +14,6 @@ from resources.wx_gui import ( gui_support, gui_help, gui_settings, - gui_sys_patch_start, gui_sys_patch_display, gui_update, ) @@ -204,6 +206,8 @@ class MainFrame(wx.Frame): self.on_build_and_install() return + self._fix_local_install() + if "--update_installed" in sys.argv and self.constants.has_checked_updates is False and gui_support.CheckProperties(self.constants).host_can_build(): # Notify user that the update has been installed self.constants.has_checked_updates = True @@ -235,6 +239,33 @@ class MainFrame(wx.Frame): threading.Thread(target=self._check_for_updates).start() + def _fix_local_install(self) -> None: + """ + Work-around users manually copying the app to /Applications + We'll delete the app, and create a proper symlink + Note: This *shouldn't* be needed with installs after 0.6.7, but it's a good catch-all + """ + + if "--update_installed" not in sys.argv: + return + if self.constants.has_checked_updates is True: + return + + # Check if app exists in /Applications, and is not a symlink + if Path("/Applications/OpenCore-Patcher.app").exists() and Path("/Applications/OpenCore-Patcher.app").is_symlink() is False: + # Delete app + result = subprocess.run(["rm", "-rf", "/Applications/OpenCore-Patcher.app"], capture_output=True) + if result.returncode != 0: + print("Failed to delete app from /Applications") + return + + # Create symlink + result = subprocess.run(["ln", "-s", "/Library/Application Support/Dortania/OpenCore-Patcher.app", "/Applications/OpenCore-Patcher.app"], capture_output=True) + if result.returncode != 0: + print("Failed to create symlink to /Applications") + return + + def _check_for_updates(self): if self.constants.has_checked_updates is True: return diff --git a/resources/wx_gui/gui_update.py b/resources/wx_gui/gui_update.py index 2b00b8631..f5ab367b9 100644 --- a/resources/wx_gui/gui_update.py +++ b/resources/wx_gui/gui_update.py @@ -227,18 +227,20 @@ if [ ! -d "/Library/Application Support/Dortania" ]; then mkdir -p "/Library/Application Support/Dortania" fi -# Check if '/Library/Application Support/Dortania/OpenCore-Patcher.app' exists +# Check if 'OpenCore-Patcher.app' exists if [ -d "/Library/Application Support/Dortania/OpenCore-Patcher.app" ]; then rm -rf "/Library/Application Support/Dortania/OpenCore-Patcher.app" fi +if [ -d "/Applications/OpenCore-Patcher.app" ]; then + rm -rf "/Applications/OpenCore-Patcher.app" +fi + # Move '/tmp/OpenCore-Patcher.app' to '/Library/Application Support/Dortania' mv "{str(self.application_path)}" "/Library/Application Support/Dortania/OpenCore-Patcher.app" # Check if '/Applications/OpenCore-Patcher.app' exists -if [ ! -d "/Applications/OpenCore-Patcher.app" ]; then - ln -s "/Library/Application Support/Dortania/OpenCore-Patcher.app" "/Applications/OpenCore-Patcher.app" -fi +ln -s "/Library/Application Support/Dortania/OpenCore-Patcher.app" "/Applications/OpenCore-Patcher.app" # Create update.plist with info about update cat << EOF > "/Library/Application Support/Dortania/update.plist" From 5d4a9b7ec70f5bf21eff9816f3703b67f968cc22 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Thu, 8 Jun 2023 09:58:18 -0600 Subject: [PATCH 2/2] gui_main_menu.py: Add logging --- resources/wx_gui/gui_main_menu.py | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/wx_gui/gui_main_menu.py b/resources/wx_gui/gui_main_menu.py index 6914e2a8e..07a5234ad 100644 --- a/resources/wx_gui/gui_main_menu.py +++ b/resources/wx_gui/gui_main_menu.py @@ -253,6 +253,7 @@ class MainFrame(wx.Frame): # Check if app exists in /Applications, and is not a symlink if Path("/Applications/OpenCore-Patcher.app").exists() and Path("/Applications/OpenCore-Patcher.app").is_symlink() is False: + logging.info("Found user-installed app in /Applications, replacing with symlink") # Delete app result = subprocess.run(["rm", "-rf", "/Applications/OpenCore-Patcher.app"], capture_output=True) if result.returncode != 0: