Skip to content

Commit 1cf7c0f

Browse files
author
arch
committed
update installer
1 parent f417687 commit 1cf7c0f

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

contrib/Installer/mtfg-ofs-extension-installer.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
from bs4 import BeautifulSoup # beautifulsoup4
1414
from tqdm import tqdm
1515

16-
VERSION = "v0.0.1"
16+
VERSION = "v0.0.2"
1717
LUA_EXTENSION_URL = "https://raw.githubusercontent.com/michael-mueller-git/Python-Funscript-Editor/main/contrib/Installer/assets/main.lua"
1818
FUNSCRIPT_GENERATOR_RELEASE_URL = "https://github.com/michael-mueller-git/Python-Funscript-Editor/releases"
1919
OFS_EXTENSION_DIR = os.path.expandvars(r'%APPDATA%\OFS\OFS_data\extensions')
20+
LATEST_RELEASE_API_URL = 'https://api.github.com/repos/michael-mueller-git/Python-Funscript-Editor/releases/latest'
2021

2122

2223
class DownloadProgressBar(tqdm):
@@ -52,13 +53,31 @@ def get_download_urls():
5253
if link.get('href').endswith(".zip") and "/releases/" in link.get('href')]
5354
}
5455
latest = max(download_urls)
55-
return download_urls, latest
56+
return download_urls, latest, ""
5657
except:
5758
time.sleep(2)
5859
if i == 2:
5960
error("Download URL not found (" + FUNSCRIPT_GENERATOR_RELEASE_URL + ")")
6061

6162

63+
def get_download_urls_with_api():
64+
# sometimes requests failed to fetch the url so we try up to 3 times
65+
for i in range(3):
66+
try:
67+
response = requests.get(LATEST_RELEASE_API_URL).json()
68+
assets_download_urls = ([x['browser_download_url'] for x in response['assets'] if 'browser_download_url' in x])
69+
program_download_url = [x for x in assets_download_urls if x.lower().endswith('.zip')]
70+
if len(program_download_url) == 0:
71+
error("MTFG Release not found")
72+
73+
latest = response['tag_name'].lower().replace("v", "")
74+
return {latest: program_download_url[0]}, latest, response['body']
75+
except:
76+
time.sleep(2)
77+
if i == 2:
78+
error("Download URL not found (" + LATEST_RELEASE_API_URL + ")")
79+
80+
6281
def is_latest_version_installed(version_file, version):
6382
if os.path.exists(version_file):
6483
with open(version_file, 'r') as f:
@@ -67,14 +86,19 @@ def is_latest_version_installed(version_file, version):
6786
sys.exit()
6887

6988

70-
def update(download_urls, latest):
89+
def update(download_urls, latest, release_notes):
7190
extension_dir = os.path.join(OFS_EXTENSION_DIR, "Funscript Generator Windows")
7291
zip_file = os.path.join(extension_dir, "funscript-editor-v" + str(latest) + ".zip")
7392
dest_dir = os.path.join(os.path.dirname(zip_file), "funscript-editor")
7493
version_file = os.path.join(os.path.dirname(zip_file), "funscript-editor", "funscript_editor", "VERSION.txt")
7594

7695
is_latest_version_installed(version_file, latest)
7796

97+
print('New Version is available')
98+
print('')
99+
print('Release notes:')
100+
print(release_notes)
101+
78102
trial = 0
79103
while True:
80104
os.makedirs(os.path.dirname(zip_file), exist_ok = True)
@@ -113,8 +137,8 @@ def update(download_urls, latest):
113137
error("This installer only work on Windows")
114138

115139
is_ofs_installed()
116-
download_urls, latest = get_download_urls()
117-
update(download_urls, latest)
140+
download_urls, latest, release_notes = get_download_urls_with_api()
141+
update(download_urls, latest, release_notes)
118142

119143
print("Installation completed")
120144

0 commit comments

Comments
 (0)