This repository was archived by the owner on Mar 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirstRun.py
59 lines (51 loc) · 2.57 KB
/
FirstRun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# SPDX-License-Identifier: MIT
# ***************************************************************************
# * *
# * Copyright (c) 2023 2023 Ondsel, Inc. *
# * *
# * This file is part of Ondsel Preference Pack *
# * *
# * See LICENSE file for details about copyright. *
# * *
# ***************************************************************************
import FreeCAD as App
import FreeCADGui as Gui
import json
import os
import shutil
from PySide import QtCore
import install_mod
import uninstall_mod
version = App.Version()
version = version[0].__str__() + '.' + version[1].__str__()
params = App.ParamGet('User parameter:BaseApp')
mw = Gui.getMainWindow()
modpath = os.path.dirname(__file__)
userModPath=os.path.join(App.getUserAppDataDir(),"Mod")
def onStart():
if mw.property("eventLoop"):
timer.stop()
timer.timeout.disconnect(onStart)
mw.addon_installers = []
# uninstall addons that should be loaded from the bundle
for mod in ['OpenDark','sheetmetal']:
param_path = f'Ondsel/mods/{mod}'
if os.path.exists(os.path.join(userModPath,mod)):
if not params.GetGroup(param_path).GetBool('Uninstalled',False):
mw.addon_installers.append(uninstall_mod.uninstaller(name=mod,param_path=param_path))
else:
params.GetGroup(param_path).SetBool('Uninstalled',True)
# Install updatable addons
with open(os.path.join(modpath,'mods.json'), "r") as fp:
mods = json.load(fp)
for mod in mods["addons"]:
param_path = f'Ondsel/{version}/mods/{mod["name"]}'
if mod["installToUser"] and not params.GetGroup(param_path).GetBool('Installed', False):
mw.addon_installers.append(install_mod.installer(mod["name"],mod["url"],mod["branch"],param_path))
for mod in mods["preferencePacks"]:
param_path = f'Ondsel/{version}/mods/{mod["name"]}'
if mod["installToUser"] and not params.GetGroup(param_path).GetBool('Installed', False):
mw.addon_installers.append(install_mod.installer(mod["name"],mod["url"],mod["branch"],param_path))
timer = QtCore.QTimer()
timer.timeout.connect(onStart)
timer.start(500)