bl_info = {
'name': 'Cats Blender Plugin',
'category': '3D View',
'author': 'GiveMeAllYourCats & Hotox',
'location': 'View 3D > Tool Shelf > CATS',
'description': 'A tool designed to shorten steps needed to import and optimize models into VRChat',
'version': (0, 19, 0),
'blender': (2, 80, 0),
'wiki_url': 'https://github.com/michaeldegroot/cats-blender-plugin',
'tracker_url': 'https://github.com/michaeldegroot/cats-blender-plugin/issues',
'warning': '',
}
dev_branch = False
import os
import sys
file_dir = os.path.join(os.path.dirname(__file__), 'extern_tools')
if file_dir not in sys.path:
sys.path.append(file_dir)
import shutil
import pathlib
import requests
from . import globs
if "bpy" not in locals():
import bpy
is_reloading = False
else:
is_reloading = True
if not is_reloading:
import mmd_tools_local
from . import updater
from . import tools
from . import ui
from . import extentions
else:
import importlib
importlib.reload(updater)
importlib.reload(mmd_tools_local)
importlib.reload(tools)
importlib.reload(ui)
importlib.reload(extentions)
from .tools import translations
from .tools.translations import t
def remove_corrupted_files():
to_remove = [
'googletrans',
'mmd_tools_local',
'extern_tools',
'resources',
'tests',
'tools',
'ui',
'.gitignore',
'.travis.yml',
'LICENSE',
'README.md',
'__init__.py',
'addon_updater.py',
'addon_updater_ops.py',
'extensions.py',
'globs.py',
'updater.py',
]
no_perm = False
os_error = False
wrong_path = False
faulty_installation = False
main_dir = str(pathlib.Path(os.path.dirname(__file__)).resolve())
if main_dir.endswith('addons'):
print(os.path.dirname(__file__))
print(main_dir)
print('Wrong installation path')
wrong_path = True
else:
main_dir = str(pathlib.Path(os.path.dirname(__file__)).parent.resolve())
files = [f for f in os.listdir(main_dir) if os.path.isfile(os.path.join(main_dir, f))]
folders = [f for f in os.listdir(main_dir) if os.path.isdir(os.path.join(main_dir, f))]
for file in files:
if file in to_remove:
file_path = os.path.join(main_dir, file)
try:
os.remove(file_path)
faulty_installation = True
print('REMOVED', file)
except PermissionError:
no_perm = True
print("Permissions: Failed to remove file " + file)
except OSError:
os_error = True
print("OS: Failed to remove file " + file)
for folder in folders:
if folder in to_remove:
folder_path = os.path.join(main_dir, folder)
try:
shutil.rmtree(folder_path)
faulty_installation = True
print('REMOVED', folder)
except PermissionError:
no_perm = True
print("Permissions: Failed to remove folder " + folder)
except OSError:
os_error = True
print("Failed to remove folder " + folder)
if no_perm:
unregister()
sys.tracebacklimit = 0
raise ImportError(t('Main.error.restartAdmin'))
if os_error:
unregister()
sys.tracebacklimit = 0
message = t('Main.error.deleteFollowing')
for folder in folders:
if folder in to_remove:
message += "\n- " + os.path.join(main_dir, folder)
for file in files:
if file in to_remove:
message += "\n- " + os.path.join(main_dir, file)
raise ImportError(message)
if wrong_path:
unregister()
sys.tracebacklimit = 0
raise ImportError(t('Main.error.installViaPreferences'))
if faulty_installation:
unregister()
sys.tracebacklimit = 0
raise ImportError(t('Main.error.restartAndEnable'))
def check_unsupported_blender_versions():
if bpy.app.version < (2, 79):
unregister()
sys.tracebacklimit = 0
raise ImportError(t('Main.error.unsupportedVersion'))
if (2, 80, 0) <= bpy.app.version < (2, 80, 75):
unregister()
sys.tracebacklimit = 0
raise ImportError(t('Main.error.beta2.80'))
def set_cats_version_string():
version = bl_info.get('version')
version_temp = []
version_str = ''
for n in version:
version_temp.append(n)
if len(version_temp) > 0:
if dev_branch:
version_temp[len(version_temp)-1] += 1
version_str += str(version_temp[0])
for index, i in enumerate(version_temp):
if index == 0:
continue
version_str += '.' + str(version_temp[index])
if dev_branch:
version_str += '-dev'
return version_str
def register():
print("\n### Loading CATS...")
check_unsupported_blender_versions()
remove_corrupted_files()
version_str = set_cats_version_string()
updater.register(bl_info, dev_branch, version_str)
globs.dev_branch = dev_branch
globs.version_str = version_str
try:
tools.settings.load_settings()
except FileNotFoundError:
sys.tracebacklimit = 0
raise ImportError(t('Main.error.restartAndEnable_alt'))
try:
mmd_tools_local.register()
except NameError:
print('Could not register local mmd_tools')
except AttributeError:
print('Could not register local mmd_tools')
except ValueError:
print('mmd_tools is already registered')
count = 0
tools.register.order_classes()
for cls in tools.register.__bl_classes:
try:
bpy.utils.register_class(cls)
count += 1
except ValueError:
pass
if count < len(tools.register.__bl_classes):
print('Skipped', len(tools.register.__bl_classes) - count, 'CATS classes.')
extentions.register()
tools.supporter.load_other_icons()
tools.supporter.load_supporters()
tools.supporter.register_dynamic_buttons()
globs.dict_found = tools.translate.load_translations()
if hasattr(tools.common.get_user_preferences(), 'system') and hasattr(tools.common.get_user_preferences().system, 'use_international_fonts'):
tools.common.get_user_preferences().system.use_international_fonts = True
elif hasattr(tools.common.get_user_preferences(), 'view') and hasattr(tools.common.get_user_preferences().view, 'use_international_fonts'):
tools.common.get_user_preferences().view.use_international_fonts = True
else:
pass
tools.common.get_user_preferences().filepaths.use_file_compression = True
bpy.context.window_manager.addon_support = {'OFFICIAL', 'COMMUNITY', 'TESTING'}
if hasattr(bpy.types, 'MESH_MT_shape_key_specials'):
bpy.types.MESH_MT_shape_key_specials.append(tools.shapekey.addToShapekeyMenu)
else:
bpy.types.MESH_MT_shape_key_context_menu.append(tools.shapekey.addToShapekeyMenu)
requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
tools.fbx_patch.start_patch_fbx_exporter_timer()
tools.settings.start_apply_settings_timer()
print("### Loaded CATS successfully!\n")
def unregister():
print("### Unloading CATS...")
updater.unregister()
if not bpy.context.scene.show_mmd_tabs:
tools.common.toggle_mmd_tabs(shutdown_plugin=True)
try:
mmd_tools_local.unregister()
except NameError:
print('mmd_tools was not registered')
pass
except AttributeError:
print('Could not unregister local mmd_tools')
pass
except ValueError:
print('mmd_tools was not registered')
pass
count = 0
for cls in reversed(tools.register.__bl_ordered_classes):
try:
bpy.utils.unregister_class(cls)
count += 1
except ValueError:
pass
except RuntimeError:
pass
print('Unregistered', count, 'CATS classes.')
tools.supporter.unregister_dynamic_buttons()
tools.supporter.unload_icons()
try:
bpy.types.MESH_MT_shape_key_specials.remove(tools.shapekey.addToShapekeyMenu)
except AttributeError:
print('shapekey button was not registered')
pass
if file_dir in sys.path:
sys.path.remove(file_dir)
print("### Unloaded CATS successfully!\n")
if __name__ == '__main__':
register()