Skip to content

Commit 8ccb0d0

Browse files
author
arch
committed
fix broken installation
1 parent ad88041 commit 8ccb0d0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
OFS_EXTENSION_DIR = os.path.expandvars(r'%APPDATA%\OFS\OFS2_data\extensions')
2121
OFS_V1_EXTENSION_DIR = os.path.expandvars(r'%APPDATA%\OFS\OFS_data\extensions')
2222
LATEST_RELEASE_API_URL = 'https://api.github.com/repos/michael-mueller-git/Python-Funscript-Editor/releases/latest'
23+
EXTENSION_NAME = "Funscript Generator Windows"
2324

2425

2526
class DownloadProgressBar(tqdm):
@@ -34,6 +35,10 @@ def download_url(url, output_path):
3435
with DownloadProgressBar(unit='B', unit_scale=True, miniters=1, desc=url.split('/')[-1]) as t:
3536
urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to)
3637

38+
def uninstall():
39+
version_file = os.path.join(OFS_EXTENSION_DIR, EXTENSION_NAME, "funscript-editor", "funscript_editor", "VERSION.txt")
40+
if os.path.exists(version_file):
41+
os.remove(version_file)
3742

3843
def error(msg):
3944
print("ERROR: " + msg)
@@ -46,7 +51,7 @@ def is_ofs_installed():
4651
if os.path.exists(OFS_V1_EXTENSION_DIR):
4752
error("Please update your [OFS](https://github.com/OpenFunscripter/OFS/releases) Installation to V2.X.X. Then run this installer again")
4853
else:
49-
error("OFS is not installed. Please download and install [OFS](https://github.com/OpenFunscripter/OFS/releases). Befor running this installer open OFS once!")
54+
error("OFS is not installed. Please download and install [OFS](https://github.com/OpenFunscripter/OFS/releases). Befor running this installer open OFS once!!")
5055

5156

5257
def get_download_urls_with_api():
@@ -69,6 +74,7 @@ def get_download_urls_with_api():
6974

7075
def get_required_installer_version(mtfg_dir):
7176
if not os.path.exists(os.path.join(mtfg_dir, "install.json")):
77+
uninstall()
7278
error("Installer notes missing, please use an newer version")
7379

7480
with open(os.path.join(mtfg_dir, "install.json"), 'r') as f:
@@ -89,6 +95,7 @@ def process_exists(process_name):
8995

9096
def install_lua_scripts(root_src_dir, extension_dir):
9197
if not os.path.exists(root_src_dir):
98+
uninstall()
9299
error(str(root_src_dir) + " do not exists (corrupt install pack?)")
93100
for src_dir, _, files in os.walk(root_src_dir):
94101
dst_dir = src_dir.replace(root_src_dir, extension_dir, 1)
@@ -111,7 +118,7 @@ def is_latest_version_installed(version_file, version):
111118

112119

113120
def update(download_urls, latest, release_notes):
114-
extension_dir = os.path.join(OFS_EXTENSION_DIR, "Funscript Generator Windows")
121+
extension_dir = os.path.join(OFS_EXTENSION_DIR, EXTENSION_NAME)
115122
zip_file = os.path.join(extension_dir, "funscript-editor-v" + str(latest) + ".zip")
116123
mtfg_dir = os.path.join(os.path.dirname(zip_file), "funscript-editor")
117124
version_file = os.path.join(os.path.dirname(zip_file), "funscript-editor", "funscript_editor", "VERSION.txt")
@@ -143,18 +150,23 @@ def update(download_urls, latest, release_notes):
143150
os.remove(zip_file)
144151
continue
145152
else:
153+
uninstall()
146154
error("Installation failed")
147155

148156
if process_exists("OpenFunscripter.exe"):
157+
uninstall()
149158
error("OpenFunscripter is currently running, please close OpenFunscripter and execute this installer again, to update the MTFG Extension")
150159

151160
if os.path.exists(mtfg_dir):
152161
try: shutil.rmtree(mtfg_dir)
153-
except: error('Error while deleting old Version (Is OFS currenty running?)')
162+
except:
163+
uninstall()
164+
error('Error while deleting old Version (Is OFS currenty running?)')
154165

155166
min_required_installer_version = get_required_installer_version(mtfg_dir + "_update")
156167
print('check min required installer version', min_required_installer_version)
157168
if version.parse(min_required_installer_version) < version.parse(VERSION.lower().replace('v', '')):
169+
uninstall()
158170
error("min required installer version is " + str(min_required_installer_version))
159171

160172
shutil.move(mtfg_dir + "_update", mtfg_dir)

0 commit comments

Comments
 (0)