44import platform
55import zipfile
66import os
7+ import sys
78
89from packaging import version
910from bs4 import BeautifulSoup # beautifulsoup4
@@ -18,23 +19,37 @@ def update_to(self, b=1, bsize=1, tsize=None):
1819
1920
2021def 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+
2637release_url = "https://github.com/michael-mueller-git/Python-Funscript-Editor/releases"
2738html_text = requests .get (release_url ).text
2839download_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}
3243latest = 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
3548if not os .path .exists (zip_file ):
3649 download_url (download_urls [latest ], zip_file )
3750
3851with 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