diff --git a/Build-Binary.command b/Build-Binary.command index fdbb0381d..1da9a6a71 100755 --- a/Build-Binary.command +++ b/Build-Binary.command @@ -11,6 +11,7 @@ # Copyright (C) 2022 - Mykola Grymalyuk from pathlib import Path +import time import argparse import os import subprocess @@ -204,15 +205,21 @@ class create_binary: def add_commit_data(self): if not self.args.branch and not self.args.commit and not self.args.commit_date: - print(" - No commit data provided, skipping") - return + print(" - No commit data provided, adding source info") + branch = "Built from source" + commit_url = "" + commit_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + else: + branch = self.args.branch + commit_url = self.args.commit + commit_date = self.args.commit_date print(" - Adding commit data to Info.plist") plist_path = Path("./dist/OpenCore-Patcher.app/Contents/Info.plist") plist = plistlib.load(Path(plist_path).open("rb")) plist["Github"] = { - "Branch": self.args.branch, - "Commit URL": self.args.commit, - "Commit Date": self.args.commit_date + "Branch": branch, + "Commit URL": commit_url, + "Commit Date": commit_date, } plistlib.dump(plist, Path(plist_path).open("wb"), sort_keys=True) diff --git a/gui/gui_main.py b/gui/gui_main.py index 68147646f..76da470c1 100644 --- a/gui/gui_main.py +++ b/gui/gui_main.py @@ -2785,11 +2785,45 @@ class wx_python_gui: ) self.real_user_id_label.Center(wx.HORIZONTAL) + + commit_dict = self.constants.commit_info + # Label: Built from Branch: + self.built_from_branch_label = wx.StaticText(self.frame_modal, label=f"Branch: {commit_dict[0]}") + self.built_from_branch_label.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) + self.built_from_branch_label.SetPosition( + wx.Point(self.real_user_id_label.GetPosition().x, self.real_user_id_label.GetPosition().y + self.real_user_id_label.GetSize().height + 10) + ) + self.built_from_branch_label.Center(wx.HORIZONTAL) + + # Label: Built on: (Date) + self.built_on_label = wx.StaticText(self.frame_modal, label=f"Date: {commit_dict[1]}") + self.built_on_label.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) + self.built_on_label.SetPosition( + wx.Point(self.built_from_branch_label.GetPosition().x, self.built_from_branch_label.GetPosition().y + self.built_from_branch_label.GetSize().height + 10) + ) + + # Label: Commit URL: (hyperlink) + self.commit_url_label = wx.StaticText(self.frame_modal, label=f"URL: ") + self.commit_url_label.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) + self.commit_url_label.SetPosition( + wx.Point(self.built_on_label.GetPosition().x, self.built_on_label.GetPosition().y + self.built_on_label.GetSize().height + 10) + ) + + # Hyperlink to the right of commit_url_label + if commit_dict[2] != "": + self.commit_url_hyperlink = hyperlink.HyperLinkCtrl(self.frame_modal, id=wx.ID_ANY, label=f"Link", URL=f"{commit_dict[2]}") + self.commit_url_hyperlink.SetPosition( + wx.Point(self.commit_url_label.GetPosition().x + self.commit_url_label.GetSize().width, self.commit_url_label.GetPosition().y) + ) + self.commit_url_hyperlink.SetForegroundColour((25, 179, 231)) + else: + self.commit_url_label.Label = f"URL: Not applicable" + # Label: Model Dump self.model_dump_label = wx.StaticText(self.frame_modal, label="Model Dump") self.model_dump_label.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) self.model_dump_label.SetPosition( - wx.Point(self.real_user_id_label.GetPosition().x, self.real_user_id_label.GetPosition().y + self.real_user_id_label.GetSize().height + 10) + wx.Point(self.commit_url_label.GetPosition().x, self.commit_url_label.GetPosition().y + self.commit_url_label.GetSize().height + 10) ) self.model_dump_label.Center(wx.HORIZONTAL) diff --git a/resources/commit_info.py b/resources/commit_info.py new file mode 100644 index 000000000..3e52ca756 --- /dev/null +++ b/resources/commit_info.py @@ -0,0 +1,40 @@ +# Parse Commit Info from binary's info.plist +# App Structure: +# OpenCore-Patcher.app: +# Contents: +# MacOS: +# OpenCore-Patcher +# Info.plist + +from pathlib import Path +import plistlib + +class commit_info: + + def __init__(self, binary_path): + self.binary_path = str(binary_path) + self.plist_path = self.convert_binary_path_to_plist_path() + + + def convert_binary_path_to_plist_path(self): + if Path(self.binary_path).exists(): + plist_path = self.binary_path.replace("MacOS/OpenCore-Patcher", "Info.plist") + if Path(plist_path).exists() and plist_path.endswith(".plist"): + return plist_path + return None + + def generate_commit_info(self): + if self.plist_path: + # print(self.plist_path) + plist_info = plistlib.load(Path(self.plist_path).open("rb")) + if "Github" in plist_info: + return ( + plist_info["Github"]["Branch"], + plist_info["Github"]["Commit Date"], + plist_info["Github"]["Commit URL"], + ) + return ( + "Running from source", + "Not applicable", + "", + ) \ No newline at end of file diff --git a/resources/constants.py b/resources/constants.py index 33bd7afbe..f8b217135 100644 --- a/resources/constants.py +++ b/resources/constants.py @@ -193,6 +193,7 @@ class Constants: self.host_is_non_metal = False # Determine if host is non-metal (ie. enable UI hacks) self.needs_to_open_preferences = False # Determine if preferences need to be opened self.host_is_hackintosh = False # Determine if host is Hackintosh + self.commit_info = (None, None, None) self.legacy_accel_support = [ os_data.os_data.big_sur, diff --git a/resources/main.py b/resources/main.py index dd2053492..8ffe8512c 100644 --- a/resources/main.py +++ b/resources/main.py @@ -8,7 +8,7 @@ from pathlib import Path import time import threading -from resources import build, cli_menu, constants, utilities, device_probe, os_probe, defaults, arguments, install, tui_helpers, reroute_payloads, global_settings +from resources import build, cli_menu, constants, utilities, device_probe, os_probe, defaults, arguments, install, tui_helpers, reroute_payloads, commit_info from data import model_array class OpenCoreLegacyPatcher: @@ -47,6 +47,7 @@ class OpenCoreLegacyPatcher: self.constants.launcher_script = launcher_script self.constants.unpack_thread = threading.Thread(target=reroute_payloads.reroute_payloads(self.constants).setup_tmp_disk_image) self.constants.unpack_thread.start() + self.constants.commit_info = commit_info.commit_info(self.constants.launcher_binary).generate_commit_info() defaults.generate_defaults.probe(self.computer.real_model, True, self.constants)