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
This commit is contained in:
Mykola Grymalyuk
2023-06-08 09:56:01 -06:00
parent 40160b644b
commit dccc39633b
3 changed files with 40 additions and 5 deletions

View File

@@ -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

View File

@@ -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"