# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#  Copyright (C) 2014-2018 Blender Foundation
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>

__version__ = "1.21"

bl_info = {
    "name": "Blender Asset Tracer",
    "author": "Campbell Barton, Sybren A. St\u00fcvel, Lo\u00efc Charri\u00e8re, Cl\u00e9ment Ducarteron, Mario Hawat, Joseph Henry",
    "version": (1, 21, 0),
    "blender": (2, 80, 0),
    "location": "File > External Data > BAT",
    "description": "Utility for packing blend files",
    "warning": "",
    "wiki_url": "https://developer.blender.org/project/profile/79/",
    "category": "Import-Export",
}

# Reset root module name if folder has an unexpected name
# (like "blender_asset_tracer-main" from zip-dl)
import sys

if __name__ != "blender_asset_tracer":
    sys.modules["blender_asset_tracer"] = sys.modules[__name__]

try:
    import bpy

    _HAS_BPY = True
except ImportError:
    _HAS_BPY = False

if _HAS_BPY:
    from blender_asset_tracer import blendfile
    from . import preferences, operators

    # Match the CLI's default: skip dangling pointers gracefully instead of crashing.
    # Production blend files often have references to missing linked libraries.
    blendfile.set_strict_pointer_mode(False)

    classes = (
        preferences.BATPreferences,
        operators.BAT_SequenceFileEntry,
        operators.ExportBatPack,
        operators.BAT_OT_export_zip,
        operators.BAT_OT_scan_sequence,
        operators.BAT_OT_sequence_pack,
    )

    def register():
        for cls in classes:
            bpy.utils.register_class(cls)
        bpy.types.TOPBAR_MT_file_external_data.append(operators.menu_func)
        bpy.types.WindowManager.bat_sequence_template = bpy.props.EnumProperty(
            name="Studio Template",
            description="Folder convention used to find published blend files",
            items=operators.STUDIO_TEMPLATE_ITEMS,
        )
        bpy.types.WindowManager.bat_sequence_task = bpy.props.EnumProperty(
            name="Task",
            description="Which task folder to scan (for templates that require it)",
            items=operators.TASK_CHOICE_ITEMS,
        )
        bpy.types.WindowManager.bat_sequence_dir = bpy.props.StringProperty(
            name="Sequence Directory",
            description="Root folder of the sequence last scanned for published blend files",
        )
        bpy.types.WindowManager.bat_sequence_files = bpy.props.CollectionProperty(
            type=operators.BAT_SequenceFileEntry,
        )

    def unregister():
        bpy.types.TOPBAR_MT_file_external_data.remove(operators.menu_func)
        del bpy.types.WindowManager.bat_sequence_files
        del bpy.types.WindowManager.bat_sequence_dir
        del bpy.types.WindowManager.bat_sequence_task
        del bpy.types.WindowManager.bat_sequence_template
        for cls in reversed(classes):
            bpy.utils.unregister_class(cls)

    if __name__ == "__main__":
        register()
