Skip to content

Commit 5be2d1a

Browse files
author
arch
committed
improve installer
1 parent cae8169 commit 5be2d1a

File tree

8 files changed

+181
-93
lines changed

8 files changed

+181
-93
lines changed

contrib/Installer/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.egg-info
2+
Miniconda3-latest*.sh
3+
__pycache__
4+
build
5+
debug*
6+
dist
7+
*.spec

contrib/Installer/build.bat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@echo off
2+
rmdir /Q /S "build" 2>NUL
3+
rmdir /Q /S "dist" 2>NUL
4+
del mtfg-ofs-extension-installer.spec 2>NUL
5+
pyinstaller --add-data="assets/*;./" --noupx --onefile mtfg-ofs-extension-installer.py
6+

contrib/Installer/environment.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: build-installer
2+
channels:
3+
- defaults
4+
dependencies:
5+
- altgraph=0.17=pyhd3eb1b0_0
6+
- beautifulsoup4=4.10.0=pyh06a4308_0
7+
- brotlipy=0.7.0=py39h2bbff1b_1003
8+
- ca-certificates=2021.9.30=haa95532_1
9+
- certifi=2021.10.8=py39haa95532_0
10+
- cffi=1.14.6=py39h2bbff1b_0
11+
- charset-normalizer=2.0.4=pyhd3eb1b0_0
12+
- cryptography=3.4.8=py39h71e12ea_0
13+
- future=0.18.2=py39haa95532_1
14+
- idna=3.2=pyhd3eb1b0_0
15+
- macholib=1.14=pyhd3eb1b0_1
16+
- openssl=1.1.1l=h2bbff1b_0
17+
- packaging=21.0=pyhd3eb1b0_0
18+
- pefile=2019.4.18=py_0
19+
- pip=21.2.4=py39haa95532_0
20+
- pycparser=2.20=py_2
21+
- pycryptodome=3.10.1=py39h2bbff1b_0
22+
- pyinstaller=3.6=py39h8cc25b3_6
23+
- pyopenssl=20.0.1=pyhd3eb1b0_1
24+
- pyparsing=2.4.7=pyhd3eb1b0_0
25+
- pysocks=1.7.1=py39haa95532_0
26+
- python=3.9.7=h6244533_1
27+
- pywin32=228=py39hbaba5e8_1
28+
- pywin32-ctypes=0.2.0=py39haa95532_1000
29+
- requests=2.26.0=pyhd3eb1b0_0
30+
- setuptools=58.0.4=py39haa95532_0
31+
- six=1.16.0=pyhd3eb1b0_0
32+
- soupsieve=2.2.1=pyhd3eb1b0_0
33+
- sqlite=3.36.0=h2bbff1b_0
34+
- tqdm=4.62.2=pyhd3eb1b0_1
35+
- tzdata=2021a=h5d7bf9c_0
36+
- urllib3=1.26.7=pyhd3eb1b0_0
37+
- vc=14.2=h21ff451_1
38+
- vs2015_runtime=14.27.29016=h5e58377_2
39+
- wheel=0.37.0=pyhd3eb1b0_1
40+
- win_inet_pton=1.1.0=py39haa95532_0
41+
- wincertstore=0.2=py39haa95532_2
42+
prefix: C:\Users\win10\miniconda3\envs\build-installer
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import urllib.request
2+
import requests
3+
import re
4+
import platform
5+
import zipfile
6+
import os
7+
import sys
8+
import traceback
9+
import shutil
10+
11+
from packaging import version
12+
from bs4 import BeautifulSoup # beautifulsoup4
13+
from tqdm import tqdm
14+
15+
LUA_EXTENSION_URL = "https://raw.githubusercontent.com/michael-mueller-git/Python-Funscript-Editor/main/contrib/Installer/assets/main.lua"
16+
FUNSCRIPT_GENERATOR_RELEASE_URL = "https://github.com/michael-mueller-git/Python-Funscript-Editor/releases"
17+
OFS_EXTENSION_DIR = os.path.expandvars(r'%APPDATA%\OFS\OFS_data\extensions')
18+
19+
20+
class DownloadProgressBar(tqdm):
21+
def update_to(self, b=1, bsize=1, tsize=None):
22+
if tsize is not None:
23+
self.total = tsize
24+
self.update(b * bsize - self.n)
25+
26+
27+
def download_url(url, output_path):
28+
print("Download latest release of Python-Funscript-Editor")
29+
with DownloadProgressBar(unit='B', unit_scale=True, miniters=1, desc=url.split('/')[-1]) as t:
30+
urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to)
31+
32+
33+
def error(msg):
34+
print("ERROR: " + msg)
35+
sys.exit()
36+
37+
38+
def is_ofs_installed():
39+
if not os.path.exists(OFS_EXTENSION_DIR):
40+
error("OFS is not installed. Please download and install OFS. Befor running this installer open OFS once!")
41+
42+
43+
def get_download_urls():
44+
try:
45+
html_text = requests.get(FUNSCRIPT_GENERATOR_RELEASE_URL).text
46+
download_urls = { version.parse(re.search(r'v[^/]*', x).group().lower().replace("v", "")) : "https://github.com" + x \
47+
for x in [link.get('href') for link in BeautifulSoup(html_text, 'html.parser').find_all('a') \
48+
if link.get('href').endswith(".zip") and "/releases/" in link.get('href')]
49+
}
50+
latest = max(download_urls)
51+
return download_urls, latest
52+
except:
53+
error("Download URL not found (" + FUNSCRIPT_GENERATOR_RELEASE_URL + ")")
54+
55+
56+
def is_latest_version_installed(version_file, version):
57+
if os.path.exists(version_file):
58+
with open(version_file, 'r') as f:
59+
if str(f.read()).lower() == "v"+str(version):
60+
print("You have already the latest version installed")
61+
sys.exit()
62+
63+
64+
def update(download_urls, latest):
65+
extension_dir = os.path.join(OFS_EXTENSION_DIR, "Funscript Generator Windows")
66+
zip_file = os.path.join(extension_dir, "funscript-editor-v" + str(latest) + ".zip")
67+
dest_dir = os.path.join(os.path.dirname(zip_file), "funscript-editor")
68+
version_file = os.path.join(os.path.dirname(zip_file), "funscript-editor", "funscript_editor", "VERSION.txt")
69+
70+
is_latest_version_installed(version_file, latest)
71+
72+
trial = 0
73+
while True:
74+
os.makedirs(os.path.dirname(zip_file), exist_ok = True)
75+
if not os.path.exists(zip_file):
76+
download_url(download_urls[latest], zip_file)
77+
78+
try:
79+
os.makedirs(dest_dir + "_update", exist_ok = True)
80+
with zipfile.ZipFile(zip_file) as zf:
81+
for member in tqdm(zf.infolist(), desc='Extracting '):
82+
zf.extract(member, dest_dir + "_update")
83+
break
84+
except:
85+
trial += 1
86+
if trial < 2:
87+
print("Local Version is corrupt redownloading")
88+
os.remove(zip_file)
89+
continue
90+
else:
91+
error("Installation failed")
92+
93+
if os.path.exists(dest_dir):
94+
try: shutil.rmtree(dest_dir)
95+
except: error('Error while deleting old Version (Is OFS currenty running?)')
96+
97+
shutil.move(dest_dir + "_update", dest_dir)
98+
99+
with open(os.path.join(extension_dir, "main.lua"), "wb") as f:
100+
f.write(requests.get(LUA_EXTENSION_URL).content)
101+
102+
103+
if __name__ == "__main__":
104+
try:
105+
if platform.system() != "Windows":
106+
error("This installer only work on Windows")
107+
108+
is_ofs_installed()
109+
download_urls, latest = get_download_urls()
110+
update(download_urls, latest)
111+
112+
print("Installation completed")
113+
114+
except SystemExit as e:
115+
input()
116+
117+
except:
118+
traceback.print_exc()
119+
input()

contrib/OpenFunscripter/openfunscripter_setup_linux.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ if [ -d ./OFS ]; then
44
echo "OpenFunscripter Source already downloaded"
55
pushd OFS
66
git pull
7+
git submodule update
78
else
89
git clone https://github.com/OpenFunscripter/OFS.git
910
pushd OFS

contrib/windows_installer.py

Lines changed: 0 additions & 92 deletions
This file was deleted.

funscript-editor.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/bin/env python3
22

3+
import traceback
34
from funscript_editor.__main__ import main
45

56
if __name__ == '__main__':
6-
main()
7+
try:
8+
main()
9+
except:
10+
traceback.print_exc()
11+
input()

0 commit comments

Comments
 (0)