-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Wolfmyths/test-branch
Implements auto updater
- Loading branch information
Showing
7 changed files
with
158 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pypresence==4.2.1 | ||
semantic-version==2.10.0 | ||
pyinstaller==5.13.0 | ||
psutil==5.9.5 | ||
psutil==5.9.5 | ||
requests==2.31.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import os | ||
import shutil | ||
|
||
import requests | ||
|
||
def downloadUpdate() -> str | None: | ||
''' | ||
Downloads and installs the newest hoi4 update. | ||
Returns download path if successful, else None | ||
''' | ||
|
||
try: | ||
|
||
downloadTemp: str = None | ||
extractedTemp: str = None | ||
|
||
# Get latest release data | ||
latestRelease = requests.get("https://api.github.com/repos/ThiaudioTT/hoi4-presence/releases/latest") | ||
|
||
latestReleaseData: dict = latestRelease.json() | ||
|
||
# Find asset data api link | ||
assetUrl: str = latestReleaseData["assets_url"] | ||
|
||
# Get asset data | ||
assetsData: dict = requests.get(assetUrl , headers={"accept":"application/vnd.github+json"}).json() | ||
|
||
# Incase there are muiltiple assets create a for loop | ||
downloadLink: str = None | ||
fileName = f"hoi4-presence-{latestReleaseData['tag_name']}.zip" | ||
|
||
for asset in assetsData: | ||
|
||
if asset["name"] == fileName: | ||
|
||
# Found the download link | ||
downloadLink = asset["browser_download_url"] | ||
|
||
break | ||
|
||
if downloadLink is not None: | ||
|
||
downloadTemp = os.path.join(os.environ["TEMP"], fileName) | ||
|
||
# Creating a new file in "write in binary" mode | ||
with open(downloadTemp, "wb") as f: | ||
|
||
# Get data for download | ||
request = requests.get(downloadLink, allow_redirects=True, stream=True) | ||
|
||
chunksDownloaded = 0 | ||
totalChunks = len(request.content) | ||
|
||
print("Starting Download") | ||
# Write it to fileName in chunks | ||
for chunk in request.iter_content(1024**2): | ||
print(f"{chunksDownloaded / totalChunks * 100:.0f}%") | ||
f.write(chunk) | ||
chunksDownloaded += len(chunk) | ||
|
||
print("100%") | ||
print("Download successful!") | ||
|
||
extractedTemp = os.path.join(os.environ["TEMP"], f"hoi4-presence-{latestReleaseData['tag_name']}") | ||
|
||
# Unzipping | ||
shutil.unpack_archive(downloadTemp, extractedTemp) | ||
|
||
return extractedTemp | ||
|
||
except Exception as e: | ||
|
||
print(f"An error has occured while updating:\n{e}\n\nStarting current version...") | ||
|
||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"OBS:": "THIS IS A TEST VERSION ONLY FOR DELEVOPING PURPOSES", | ||
"version": "0.1.0", | ||
"auto-update": false, | ||
"auto-update": true, | ||
"date": "23-sep-2022" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "1.1.0", | ||
"auto-update": false, | ||
"version": "1.2.0", | ||
"auto-update": true, | ||
"date": "19-august-2023" | ||
} |