Skip to content

Commit

Permalink
keep update info in a single file.
Browse files Browse the repository at this point in the history
  • Loading branch information
th3w1zard1 committed Mar 15, 2024
1 parent f72110b commit 90e614f
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 35 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 20 additions & 3 deletions Tools/HolocronToolset/src/toolset/config.py
Original file line number Diff line number Diff line change
@@ -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": "<br> - Tons of performance optimizations<br> - Fix filtering by name in the Texture tab<br> - Fix editors not starting on top<br> - Use new strategy for IO<br> - Use pillow to load large TGA images.<br> - Fix reload/refresh buttons<br> - Prompt before creating a .mod when using module designer.<br> - Fix bug when compiling scripts inside RIMs, when rims saving setting is disabled.<br> - Optimize installation loading and show progress bar for the entire process.<br> - Fix issue with installations not being cached when swapping to a different installation in the combobox.<br> - Fix issue with windows not having separate taskbar entries.<br> - Add an option to disable/enable loading Override textures into the module designer (workaround for large textures taking ages to load).<br> - Add additional resources into the Core tab.<br><br>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--->#
4 changes: 2 additions & 2 deletions Tools/HolocronToolset/src/toolset/gui/dialogs/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]))
6 changes: 3 additions & 3 deletions Tools/HolocronToolset/src/toolset/gui/windows/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,7 +26,6 @@

from PyQt5.QtWidgets import QWidget


class HelpWindow(QMainWindow):
ENABLE_UPDATES = True

Expand Down Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down
60 changes: 37 additions & 23 deletions Tools/HolocronToolset/src/toolset/gui/windows/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import base64
import json
import re
import traceback

from contextlib import suppress
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Binary file not shown.

0 comments on commit 90e614f

Please sign in to comment.