UIoperator.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:UPBGE-CommunityAddon 作者: elmeunick9 项目源码 文件源码
def execute(self, context):
        name = os.path.basename(self.filepath)

        #TODO: put on another file and module

        def checkProjectFile(path):
            if os.path.basename(path) != "project.json": return False
            if not os.path.isfile(path): return False

            utils.loadProjectFile(path)

            if not 'bge-project' in utils.project_data: return False

            return True

        def getMainBlend(path):
            path = os.path.dirname(path) + os.sep + "project" +  os.sep + "main.blend"
            if os.path.isfile(path): return path

        #If we have a zip
        if os.path.isfile(self.filepath):
            for x in [".zip", ".tar", ".gztar", ".bztar", ".xztar"]:
                if self.filepath.endswith(x):
                    tpath = tempfile.gettempdir() + os.sep + os.path.basename(self.filepath)[:-len(x)] + os.sep
                    shutil.unpack_archive(self.filepath, tpath)
                    self.filepath = tpath
                    print("Extracted to: ", tpath)

        #Once we have a folder...
        list=[self.filepath, self.filepath + "project.json", os.path.dirname(self.filepath) + os.sep + "project.json", os.path.dirname(self.filepath) + os.sep + "../" + "project.json"]

        endpath=None
        for path in list:
            if checkProjectFile(path): endpath=getMainBlend(path)

        if endpath==None:
            self.report({'ERROR_INVALID_INPUT'}, "Error loading project, project file not found.")
            return {'CANCELLED'}

        bpy.ops.wm.open_mainfile(filepath=endpath)
        return {'FINISHED'}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号