Skip to content

Commit 96f72ed

Browse files
author
arch
committed
improve win installler
1 parent 6fca9ba commit 96f72ed

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

contrib/windows_installer.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import platform
55
import zipfile
66
import os
7+
import sys
78

89
from packaging import version
910
from bs4 import BeautifulSoup # beautifulsoup4
@@ -18,23 +19,37 @@ def update_to(self, b=1, bsize=1, tsize=None):
1819

1920

2021
def download_url(url, output_path):
21-
with DownloadProgressBar(unit='B', unit_scale=True,
22-
miniters=1, desc=url.split('/')[-1]) as t:
22+
with DownloadProgressBar(unit='B', unit_scale=True, miniters=1, desc=url.split('/')[-1]) as t:
2323
urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to)
2424

2525

26+
if platform.system() != "Windows":
27+
print("ERROR: This installer only work on Windows")
28+
sys.exit()
29+
30+
ofs_extension_dir = os.path.expandvars(r'%APPDATA%\OFS_data\extensions')
31+
32+
if not os.path.exists(ofs_extension_dir):
33+
print("ERROR: OFS is not installed. Please download and install OFS. Befor running this installer open OFS once on your Computer")
34+
print("Cancel installation")
35+
sys.exit()
36+
2637
release_url = "https://github.com/michael-mueller-git/Python-Funscript-Editor/releases"
2738
html_text = requests.get(release_url).text
2839
download_urls = { version.parse(re.search(r'v[^/]*', x).group().lower().replace("v", "")) : "https://github.com" + x \
2940
for x in [link.get('href') for link in BeautifulSoup(html_text, 'html.parser').find_all('a') \
3041
if link.get('href').endswith(".zip") and "/releases/" in link.get('href')]
3142
}
3243
latest = max(download_urls)
33-
zip_file = "funscript-editor-v" + str(latest) + ".zip"
44+
zip_file = os.path.join(ofs_extension_dir, "Funscript Generator Windows", "funscript-editor-v" + str(latest) + ".zip")
45+
dest_dir = os.path.dirname(zip_file)
46+
os.makedirs(dest_dir, exist_ok = True)
3447

3548
if not os.path.exists(zip_file):
3649
download_url(download_urls[latest], zip_file)
3750

3851
with zipfile.ZipFile(zip_file) as zf:
3952
for member in tqdm(zf.infolist(), desc='Extracting '):
4053
zf.extract(member, "funscript-editor")
54+
55+
# TODO download the main.lua to the extension dir

0 commit comments

Comments
 (0)