From 90e614ff0d8c7b174f624694d181c47001f5f6c4 Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Fri, 15 Mar 2024 15:11:51 -0500 Subject: [PATCH] keep update info in a single file. --- .gitignore | 2 - Tools/HolocronToolset/src/toolset/config.py | 23 ++++++- .../src/toolset/gui/dialogs/about.py | 4 +- .../src/toolset/gui/windows/help.py | 6 +- .../src/toolset/gui/windows/indoor_builder.py | 5 +- .../src/toolset/gui/windows/main.py | 60 +++++++++++------- .../src/toolset/profiler_output.pstat | Bin 1168 -> 0 bytes 7 files changed, 65 insertions(+), 35 deletions(-) delete mode 100644 Tools/HolocronToolset/src/toolset/profiler_output.pstat diff --git a/.gitignore b/.gitignore index c3cc3a48c..f01e8fadc 100644 --- a/.gitignore +++ b/.gitignore @@ -63,8 +63,6 @@ Tools/HolocronToolset/src/toolset/kits/*/* .venv_wsl .secrets tests/results/ -Tools/HolocronToolset/src/toolset/profiler_output.pstat -Tools/HolocronToolset/src/toolset/profiler_output.pstat *.pstat installlog.txt ./vendor diff --git a/Tools/HolocronToolset/src/toolset/config.py b/Tools/HolocronToolset/src/toolset/config.py index 1756ee8d0..d5e235018 100644 --- a/Tools/HolocronToolset/src/toolset/config.py +++ b/Tools/HolocronToolset/src/toolset/config.py @@ -1,5 +1,22 @@ from __future__ import annotations -UPDATE_INFO_LINK: str = "https://api.github.com/repos/NickHugi/PyKotor/contents/update_info.json" -UPDATE_BETA_INFO_LINK: str = "https://api.github.com/repos/NickHugi/PyKotor/contents/update_info_beta.json" -PROGRAM_VERSION: str = "2.2.1b9" +# config.py + +LOCAL_PROGRAM_INFO = \ +{ #<---JSON_START--->#{ + "currentVersion": "2.1b18", + "toolsetLatestVersion": "2.1.2", + "toolsetLatestBetaVersion": "2.2.1b18", + "updateInfoLink": "https://api.github.com/repos/NickHugi/PyKotor/contents/Tools/HolocronToolset/src/toolset/config.py", + "updateBetaInfoLink": "https://api.github.com/repos/NickHugi/PyKotor/contents/Tools/HolocronToolset/src/toolset/config.py?ref=bleeding-edge", + "toolsetDownloadLink": "https://deadlystream.com/files/file/1982-holocron-toolset", + "toolsetBetaDownloadLink": "https://mega.nz/folder/cGJDAKaa#WzsWF8LgUkM8U2FDEoeeRA", + "toolsetLatestNotes": "Fixed major bug that was causing most editors to load data incorrectly.", + "toolsetLatestBetaNotes": "
- Tons of performance optimizations
- Fix filtering by name in the Texture tab
- Fix editors not starting on top
- Use new strategy for IO
- Use pillow to load large TGA images.
- Fix reload/refresh buttons
- Prompt before creating a .mod when using module designer.
- Fix bug when compiling scripts inside RIMs, when rims saving setting is disabled.
- Optimize installation loading and show progress bar for the entire process.
- Fix issue with installations not being cached when swapping to a different installation in the combobox.
- Fix issue with windows not having separate taskbar entries.
- Add an option to disable/enable loading Override textures into the module designer (workaround for large textures taking ages to load).
- Add additional resources into the Core tab.

Thank you to the users who've reported the bugs in the last few versions.", + "kits": { + "Black Vulkar Base": {"version": 1, "id": "blackvulkar"}, + "Endar Spire": {"version": 1, "id": "endarspire"}, + "Hidden Bek Base": {"version": 1, "id": "hiddenbek"} + }, + "help": {"version": 3} +} #<---JSON_END---># diff --git a/Tools/HolocronToolset/src/toolset/gui/dialogs/about.py b/Tools/HolocronToolset/src/toolset/gui/dialogs/about.py index 25c048629..b9c92657e 100644 --- a/Tools/HolocronToolset/src/toolset/gui/dialogs/about.py +++ b/Tools/HolocronToolset/src/toolset/gui/dialogs/about.py @@ -4,7 +4,7 @@ from PyQt5.QtWidgets import QDialog -from toolset.config import PROGRAM_VERSION +from toolset.config import LOCAL_PROGRAM_INFO if TYPE_CHECKING: from PyQt5.QtWidgets import QWidget @@ -32,4 +32,4 @@ def __init__(self, parent: QWidget): self.ui.closeButton.clicked.connect(self.close) - self.ui.aboutLabel.setText(self.ui.aboutLabel.text().replace("X.X.X", PROGRAM_VERSION)) + self.ui.aboutLabel.setText(self.ui.aboutLabel.text().replace("X.X.X", LOCAL_PROGRAM_INFO["currentVersion"])) diff --git a/Tools/HolocronToolset/src/toolset/gui/windows/help.py b/Tools/HolocronToolset/src/toolset/gui/windows/help.py index 47c894855..30edbd7fb 100644 --- a/Tools/HolocronToolset/src/toolset/gui/windows/help.py +++ b/Tools/HolocronToolset/src/toolset/gui/windows/help.py @@ -16,7 +16,7 @@ from pykotor.common.stream import BinaryReader from pykotor.tools.encoding import decode_bytes_with_fallbacks from toolset.__main__ import is_frozen -from toolset.config import UPDATE_INFO_LINK +from toolset.config import LOCAL_PROGRAM_INFO from toolset.gui.dialogs.asyncloader import AsyncLoader from utility.error_handling import universal_simplify_exception from utility.system.path import Path, PurePath @@ -26,7 +26,6 @@ from PyQt5.QtWidgets import QWidget - class HelpWindow(QMainWindow): ENABLE_UPDATES = True @@ -147,7 +146,8 @@ def _request_api_data(self, api_url: str): def checkForUpdates(self): try: - req = requests.get(UPDATE_INFO_LINK, timeout=15) + update_info_link = LOCAL_PROGRAM_INFO["updateInfoLink"] # TODO: settings.useBetaChannel + req = requests.get(update_info_link, timeout=15) req.raise_for_status() file_data = req.json() base64_content = file_data["content"] diff --git a/Tools/HolocronToolset/src/toolset/gui/windows/indoor_builder.py b/Tools/HolocronToolset/src/toolset/gui/windows/indoor_builder.py index 91fca6adb..fccdf18da 100644 --- a/Tools/HolocronToolset/src/toolset/gui/windows/indoor_builder.py +++ b/Tools/HolocronToolset/src/toolset/gui/windows/indoor_builder.py @@ -37,7 +37,7 @@ from pykotor.common.geometry import Vector2, Vector3 from pykotor.common.stream import BinaryReader, BinaryWriter from toolset.__main__ import is_frozen -from toolset.config import UPDATE_INFO_LINK +from toolset.config import LOCAL_PROGRAM_INFO from toolset.data.indoorkit import load_kits from toolset.data.indoormap import IndoorMap, IndoorMapRoom from toolset.gui.dialogs.asyncloader import AsyncLoader @@ -982,7 +982,8 @@ def _setupDownloads(self): - If not, sets button to "Download" - Adds kit name and button to layout in group box """ - file_data = self._get_update_data(UPDATE_INFO_LINK) + update_info_link = LOCAL_PROGRAM_INFO["updateInfoLink"] # TODO: settings.useBetaChannel + file_data = self._get_update_data(update_info_link) base64_content = file_data["content"] decoded_content = base64.b64decode(base64_content) # Correctly decoding the base64 content updateInfoData = json.loads(decoded_content.decode("utf-8")) diff --git a/Tools/HolocronToolset/src/toolset/gui/windows/main.py b/Tools/HolocronToolset/src/toolset/gui/windows/main.py index 973355dde..04a91e7c0 100644 --- a/Tools/HolocronToolset/src/toolset/gui/windows/main.py +++ b/Tools/HolocronToolset/src/toolset/gui/windows/main.py @@ -2,6 +2,7 @@ import base64 import json +import re import traceback from contextlib import suppress @@ -30,7 +31,8 @@ from pykotor.resource.type import ResourceType from pykotor.tools import model, module from pykotor.tools.misc import is_any_erf_type_file, is_bif_file, is_capsule_file, is_erf_file, is_mod_file, is_rim_file -from toolset.config import PROGRAM_VERSION, UPDATE_BETA_INFO_LINK, UPDATE_INFO_LINK +from pykotor.tools.path import CaseAwarePath +from toolset.config import LOCAL_PROGRAM_INFO from toolset.data.installation import HTInstallation from toolset.gui.dialogs.about import About from toolset.gui.dialogs.asyncloader import AsyncBatchLoader, AsyncLoader @@ -646,53 +648,65 @@ def checkForUpdates(self, *, silent: bool = False): ).exec_() def _check_toolset_update(self, *, silent: bool): - if isinstance(PROGRAM_VERSION, tuple): - x = "" - for v in PROGRAM_VERSION: - if not x: - x = str(v) - else: - x += f".{v}" + CURRENT_VERSION = LOCAL_PROGRAM_INFO["currentVersion"] + if self.settings.useBetaChannel: + UPDATE_INFO_LINK = LOCAL_PROGRAM_INFO["updateBetaInfoLink"] else: - x = str(PROGRAM_VERSION) - if "b" in PROGRAM_VERSION: - self.settings.useBetaChannel = True + UPDATE_INFO_LINK = LOCAL_PROGRAM_INFO["updateInfoLink"] - if self.settings.useBetaChannel: # use the beta channel if the setting is set or their version is already beta. - req: requests.Response = requests.get(UPDATE_BETA_INFO_LINK, timeout=15) - else: - req = requests.get(UPDATE_INFO_LINK, timeout=15) + req = requests.get(UPDATE_INFO_LINK, timeout=15) req.raise_for_status() file_data = req.json() base64_content = file_data["content"] decoded_content = base64.b64decode(base64_content) # Correctly decoding the base64 content - data = json.loads(decoded_content.decode("utf-8")) - assert isinstance(data, dict) + decoded_content_str = decoded_content.decode(encoding="utf-8") + # use for testing only: + #with open("config.py") as f: + # decoded_content_str = f.read() + # Use regex to extract the JSON part between the markers + json_data_match = re.search(r"<---JSON_START--->\#(.*)\#<---JSON_END--->", decoded_content_str, flags=re.DOTALL) + + if json_data_match: + #print(f"Match found! {json_data_match.group(1)}") + json_str = json_data_match.group(1) # Extract the JSON string + REMOTE_PROGRAM_INFO = json.loads(json_str) # Parse the JSON string into a Python dictionary + + # Now you can access the data from config_dict + print(REMOTE_PROGRAM_INFO["toolsetLatestVersion"]) + print(REMOTE_PROGRAM_INFO["updateInfoLink"]) + else: + raise ValueError(f"JSON data not found or markers are incorrect: {json_data_match}") + assert isinstance(REMOTE_PROGRAM_INFO, dict) + + if self.settings.useBetaChannel: + toolsetLatestNotes = REMOTE_PROGRAM_INFO.get("toolsetBetaLatestNotes", "") + toolsetDownloadLink = REMOTE_PROGRAM_INFO.get("toolsetDownloadLink", LOCAL_PROGRAM_INFO["toolsetDownloadLink"]) + else: + toolsetLatestNotes = REMOTE_PROGRAM_INFO.get("toolsetLatestNotes", "") + toolsetDownloadLink = REMOTE_PROGRAM_INFO.get("toolsetBetaDownloadLink", LOCAL_PROGRAM_INFO["toolsetBetaDownloadLink"]) version_check: bool | None = None with suppress(Exception): from packaging import version - version_check = version.parse(data["toolsetLatestVersion"]) > version.parse(x) + version_check = version.parse(REMOTE_PROGRAM_INFO["toolsetLatestVersion"]) > version.parse(CURRENT_VERSION) if version_check is None: with suppress(Exception): from distutils.version import LooseVersion - version_check = LooseVersion(data["toolsetLatestVersion"]) > LooseVersion(x) - if version_check is False: # only check False, if None then the version check failed + version_check = LooseVersion(REMOTE_PROGRAM_INFO["toolsetLatestVersion"]) > LooseVersion(CURRENT_VERSION) + if version_check is False: # Only check False. if None then the version check failed if silent: return QMessageBox( QMessageBox.Information, "Version is up to date", - f"You are running the latest version ({PROGRAM_VERSION}).", + f"You are running the latest version ({CURRENT_VERSION}).", QMessageBox.Ok, self, ).exec_() return - toolsetDownloadLink = data["toolsetDownloadLink"] - toolsetLatestNotes = data.get("toolsetLatestNotes", "") betaString = "beta " if self.settings.useBetaChannel else "" msgBox = QMessageBox( QMessageBox.Information, diff --git a/Tools/HolocronToolset/src/toolset/profiler_output.pstat b/Tools/HolocronToolset/src/toolset/profiler_output.pstat deleted file mode 100644 index f4694a5a66349cd6d9c56dfd03305adadcb05d45..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1168 zcmbVL&ubGw6i!W}w6@h2A%d5j3{earNg+zv6*W!4Lwl${z=fFXPNq{gGhueqq^xM6 zcu?`6coV%84VY|WCoX5$O^w92#^Gbphwtz2L{-#P#Tc76aDj2U9S#eoTK#ReM;cA$}n1tkOp zTph`e=Jf@lU&-sHu!s>0bw#F^>g(t3yj7_0Kmm9fxf&5tCwg81@)*3s57;IgW~0M$4|vd=4*urzcW-Xw}g$j%NS|hMDxD-l{Y)aExm*3}7D)k-g%s75Kfu>J3 zKCF%JrIDCw4J~Rgt57saG$KloXx_A74@+^NP=b|}a9dm?y4@ht8B;QQ;M@1)Gllw& z)APIB50rZ5I+4A%=swt1>EpXM9<4syR(k`yLw#LoZ$Gx7lli2xwNYRFqfp;*WC)XW Li^6|uV-ktKW^;Rs