def load_config():
global CONFIG
if os.path.isfile( CONFIG_FILEPATH ):
try:
with open( CONFIG_FILEPATH, 'rb' ) as f:
CONFIG = pickle.load( f )
except:
print('[ERROR]: Can not read config from %s' %CONFIG_FILEPATH)
for tag in _CONFIG_DEFAULTS_ALL:
if tag not in CONFIG:
CONFIG[ tag ] = _CONFIG_DEFAULTS_ALL[ tag ]
for tag in _CONFIG_TAGS_:
if tag not in CONFIG:
if sys.platform.startswith('win'):
CONFIG[ tag ] = _CONFIG_DEFAULTS_WINDOWS[ tag ]
elif sys.platform.startswith('linux') or sys.platform.startswith('darwin') or sys.platform.startswith('freebsd'):
CONFIG[ tag ] = _CONFIG_DEFAULTS_UNIX[ tag ]
else:
print( 'ERROR: unknown platform' )
assert 0
try:
if sys.platform.startswith('win'):
import winreg
# Find the blender2ogre install path from windows registry
registry_key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, r'Software\blender2ogre', 0, winreg.KEY_READ)
exe_install_dir = winreg.QueryValueEx(registry_key, "Path")[0]
if exe_install_dir != "":
# OgreXmlConverter
if os.path.isfile(exe_install_dir + "OgreXmlConverter.exe"):
print ("Using OgreXmlConverter from install path:", exe_install_dir + "OgreXmlConverter.exe")
CONFIG['OGRETOOLS_XML_CONVERTER'] = exe_install_dir + "OgreXmlConverter.exe"
# Run auto updater as silent. Notifies user if there is a new version out.
# This will not show any UI if there are no update and will go to network
# only once per 2 days so it wont be spending much resources either.
# todo: Move this to a more appropriate place than load_config()
if os.path.isfile(exe_install_dir + "check-for-updates.exe"):
subprocess.Popen([exe_install_dir + "check-for-updates.exe", "/silent"])
except Exception as e:
print("Exception while reading windows registry:", e)
# Setup temp hidden RNA to expose the file paths
for tag in _CONFIG_TAGS_:
default = CONFIG[ tag ]
func = eval( 'lambda self,con: CONFIG.update( {"%s" : self.%s} )' %(tag,tag) )
if type(default) is bool:
prop = BoolProperty(
name=tag, description='updates bool setting', default=default,
options={'SKIP_SAVE'}, update=func
)
else:
prop = StringProperty(
name=tag, description='updates path setting', maxlen=128, default=default,
options={'SKIP_SAVE'}, update=func
)
setattr( bpy.types.WindowManager, tag, prop )
return CONFIG
评论列表
文章目录