diff --git a/CHANGELOG.md b/CHANGELOG.md index 030d379..a4842f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,15 +6,25 @@ The format is based on [Keep a Changelog][keep a changelog] and this project adh ## [Unreleased] -### Added - -- Export `asyncio` -- `_asyncio.pyd`, `_overlapped.pyd` to the distributed files +- / --- ## [Released] +## [0.4.1] - 2021-03-27 + +### Added +- `asyncio` +- `_asyncio.pyd`, `_overlapped.pyd` to the distributed files +- library version checker +- new troubleshooting page +- more exception handling + +### Changed +- mod version check handling + + ## [0.4.0] - 2021-03-25 ### Added @@ -81,6 +91,7 @@ The format is based on [Keep a Changelog][keep a changelog] and this project adh [unreleased]: https://github.com/RLNT/bl2_eridium/compare/v1.0.0...HEAD [released]: https://github.com/RLNT/bl2_eridium/releases +[0.4.1]: https://github.com/RLNT/bl2_eridium/compare/v0.4.0...v0.4.1 [0.4.0]: https://github.com/RLNT/bl2_eridium/compare/v0.3.2...v0.4.0 [0.3.2]: https://github.com/RLNT/bl2_eridium/compare/v0.3.1...v0.3.2 [0.3.1]: https://github.com/RLNT/bl2_eridium/compare/v0.3.0...v0.3.1 diff --git a/README.md b/README.md index 8e64000..5969c9b 100644 --- a/README.md +++ b/README.md @@ -19,16 +19,6 @@ - `Borderlands 2\Binaries\Win32\Mods` -## **🐞 Troubleshooting** -What you can do if this website was opened automatically upon starting the game: - -- make sure you installed the latest **release** from [releases] -- make sure the EridiumLib sits in the right path - - `Borderlands 2\Binaries\Win32\Mods\EridiumLib` -- make sure you have the `dist` folder within the mod directory and there are files in it -- if it's still not working, contact us on [Discord] - - ## **💻 Developing** In order to work on this library, you need the latest python files from the `requirements.txt`. diff --git a/__init__.py b/__init__.py index a0a02f4..f484db7 100644 --- a/__init__.py +++ b/__init__.py @@ -29,27 +29,28 @@ # isort: skip +import asyncio import socket import ssl -import asyncio import requests # noqa: E402 import semver # noqa: E402 import ujson # noqo: E402 - __all__ = [ "log", "isClient", "getCurrentPlayerController", - "checkLibraryVersion", "getCurrentWorldInfo", "getCurrentGameInfo", "getSkillManager", "getActionSkill", "getVaultHunterClassName", + "validateVersion", "getLatestVersion", "isLatestRelease", + "checkLibraryVersion", + "checkModVersion", "EridiumMod", "keys", "debug", @@ -61,7 +62,7 @@ "ssl", "asyncio", ] -__version__ = "0.4.0" +__version__ = "0.4.1" def log(mod: SDKMod, *args: Any) -> None: @@ -117,38 +118,71 @@ def getVaultHunterClassName(PC: Optional[unrealsdk.UObject] = None) -> str: return str(PC.PlayerClass.CharacterNameId.CharacterClassId.ClassName) -def getLatestVersion(repo: str) -> str: - response = requests.get(f"https://api.github.com/repos/{repo}/releases") - response.raise_for_status() - releases = response.json() +def validateVersion(version: str) -> str: + if version[0] == "v": + version = version[1:] + return version + + +def getLatestVersion(repository: str) -> str: + """ + Gets the latest public release tag name of a passed in repository. + Will raise an exception if the releases couldn't be fetched. + """ + try: + response = requests.get(f"https://api.github.com/repos/{repository}/releases") + response.raise_for_status() + releases = response.json() + except Exception: + raise + if len(releases) < 1: - raise RuntimeWarning(f"{repo} has no releases") - return str(releases[0]["tag_name"]) + raise RuntimeWarning(f"{repository} has no releases!") + return str(releases[0]["tag_name"]) -def isLatestRelease(latest_version: str, current_version: str) -> bool: - if latest_version[0] == "v": - latest_version = latest_version[1:] - if current_version[0] == "v": - current_version = current_version[1:] - return int(semver.compare(current_version, latest_version)) >= 0 +def isLatestRelease(latestVersion: str, currentVersion: str) -> bool: + """ + Returns True if the current version is equal + or higher than the latest version. + """ + return int(semver.compare(validateVersion(currentVersion), validateVersion(latestVersion))) >= 0 -def checkLibraryVersion(required_version: str) -> bool: - """Returns True if the version of EridiumLib is compatible. - Opens the download page for EridiumLib if the version is incompatible. +def checkLibraryVersion(requiredVersion: str) -> bool: + """ + Returns True if the version of EridiumLib is compatible. + If not, opens a page which informs that the EridiumLib version is incompatible. """ import webbrowser - if int(semver.compare(__version__, required_version)) >= 0: + if int(semver.compare(__version__, validateVersion(requiredVersion))) >= 0: return True - webbrowser.open("https://github.com/RLNT/bl2_eridium/releases/latest") - + webbrowser.open("https://github.com/RLN/bl2_eridiumT/blob/main/docs/TROUBLESHOOTING.md") return False +def checkModVersion(mod: SDKMod, repository: str) -> None: + """ + Checks if the mod version is up-to-date. + Will log the results to the console. + """ + log(mod, f"Version: v{mod.Version}") + + try: + latestVersion: str = getLatestVersion(repository) + except Exception: + log(mod, "Latest version couldn't be fetched! Skipping version check.") + return + + if isLatestRelease(validateVersion(latestVersion), validateVersion(mod.Version)): + log(mod, "Mod is up-to-date!") + else: + log(mod, f"Newer version available: {latestVersion}") + + class EridiumLib(SDKMod): Name = "EridiumLib" Author = "Chronophylos, Relentless" @@ -166,12 +200,7 @@ class EridiumLib(SDKMod): def __init__(self) -> None: self.Status = "Enabled" - - log(self, f"Version: {self.Version}") - try: - log(self, f"Latest release tag: {getLatestVersion('RLNT/bl2_eridium')}") - except RuntimeWarning as ex: - log(self, f"Warning: {ex}") + checkModVersion(self, "RLNT/bl2_eridium") log(self, f"Python Version: {sys.version}") log(self, f"__debug__: {__debug__}") diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md new file mode 100644 index 0000000..ea53e0f --- /dev/null +++ b/docs/TROUBLESHOOTING.md @@ -0,0 +1,41 @@ +# **🐞 Troubleshooting** + +> If this site opened automatically when you started the game, it means you have an issue with your mod installation. + +## **What can be the reasons for this?** +- outdated library version + - happens if a mod requests a newer version of this library +- module not found error + - means you didn't install this library at all or it's not installed correctly +- import error + - means there are functions required by a mod which are not in the library + - ususally caused by an outdated library version + +## **How do I see what the reason is?** +You can usually see the error in the console of the game. + +If you don't have a console, you can also take a look at the PythonSDK log which is located here:
+`Borderlands2\Binaries\Win32\python-sdk.log` + +## **How can I fix my problem?** +- outdated library version: + - download the latest **release** from [releases] and install it +- module not found error: + - make sure you installed the EridiumLib correctly + - it has to be in the right path + - `Borderlands 2\Binaries\Win32\Mods\EridiumLib` + - the name of the mod folder is important +- import error: + - download the latest **release** from [releases] and install it +- other possible solutions: + - make sure you have the `dist` folder within the mod directory and there are files in it + - try redownloading the latest **release** from [releases] and make sure the path is correct + - make sure you didn't download the repository source code, use the release + +## **I am still having problems!** +Join our [Discord] and ask for help. + + + +[discord]: https://discordapp.com/invite/Q3qxws6 +[releases]: https://github.com/RLNT/bl2_eridium/releases diff --git a/modinfo.json b/modinfo.json index 4722747..4db4309 100644 --- a/modinfo.json +++ b/modinfo.json @@ -15,8 +15,9 @@ "supports": ["BL2", "TPS"], "issues": "https://github.com/RLNT/bl2_eridium/issues", "source": "https://github.com/RLNT/bl2_eridium", - "latest": "0.4.0", + "latest": "0.4.1", "versions": { + "0.4.1": "https://github.com/RLNT/bl2_eridium/releases/tag/v0.4.1", "0.4.0": "https://github.com/RLNT/bl2_eridium/releases/tag/v0.4.0", "0.3.2": "https://github.com/RLNT/bl2_eridium/releases/tag/v0.3.2" },