예제 #1
0
 def run(self):
     try:
         AutoFix.info('Started image manager...', 5)
         self.__clean()
         while self.enabled:
             if len(self.queue):
                 self.__decode_brres_images(self.queue.pop(0))
             else:
                 self.is_ready = True
             sleep(0.3)
     except:
         AutoFix.exception(shutdown=True)
예제 #2
0
 def __decode_brres_images(self, brres):
     name = self.__get_brres_key(brres)
     folder_name = self.brres_to_folder.get(name)
     if not folder_name:
         self.brres_to_folder[
             name] = folder_name = self.__get_unique_folder_name()
     else:
         shutil.rmtree(folder_name, ignore_errors=True)
     try:
         ImgConverter().batch_decode(brres.textures, folder_name)
         self.signals.on_image_update.emit((brres, folder_name))
     except DecodeError as e:
         AutoFix.exception(e)
예제 #3
0
 def run(self):
     AutoFix.info('Started converter... ', 5)
     try:
         while True:
             if len(self.queue):
                 self.item = self.queue.pop(0)
                 self.item.convert()
                 self.signals.on_conversion_finish.emit(self.item)
                 self.item = None
                 # for x in self.observers:
                 #     x.on_conversion_finish(self.item)
             if not self.is_running:
                 break
             sleep(0.2)
     except:
         AutoFix.exception(shutdown=True)
예제 #4
0
 def _import_images(self, image_path_map):
     try:
         return self._try_import_textures(self.brres, image_path_map)
     except NoImgConverterError as e:
         AutoFix.exception(e)
예제 #5
0
def parse_args(argv, app_dir):
    interactive = overwrite = debug = False
    type = ""
    cmd_args = None
    command = destination = brres_file = command_file = model = value = key = ""
    autofix = loudness = None
    name = None
    no_normals = no_colors = single_bone = no_uvs = moonview = patch = False
    do_help = False
    for i in range(len(argv)):
        if argv[i][0] == '-':
            if i != 0:
                cmd_args = argv[:i]
                argv = argv[i:]
            break

    try:
        opts, args = getopt.gnu_getopt(argv, "ahd:oc:t:k:v:n:b:m:f:iul:g", [
            "auto-fix", "help", "destination=", "overwrite", "command=",
            "type=", "key=", "value=", "name=", "brres=", "model=", "file=",
            "interactive", "loudness=", "debug", "single-bone", "no-colors",
            "no-normals", "no-uvs", "moonview", "patch"
        ])
    except getopt.GetoptError as e:
        print(e)
        print(USAGE)
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            do_help = True
        elif opt in ('-b', '--brres'):
            brres_file = arg
        elif opt in ("-f", "--file"):
            command_file = arg
        elif opt in ("-d", "--destination"):
            destination = arg
        elif opt in ("-o", "--overwrite"):
            overwrite = True
        elif opt in ("-k", "--key"):
            key = arg
        elif opt in ("-v", "--value"):
            value = arg
        elif opt in ("-t", "--type"):
            type = arg
        elif opt in ("-n", "--name"):
            name = arg
        elif opt in ("-m", "--model"):
            model = arg
        elif opt in ("-c", "--command"):
            command = arg
        elif opt in ("-i", "--interactive"):
            interactive = True
        elif opt in ("-a", "--auto-fix"):
            autofix = arg
        elif opt in ("-l", "--loudness"):
            loudness = arg
        elif opt in ("-g", "--debug"):
            debug = True
        elif opt == '--single-bone':
            single_bone = True
        elif opt == '--no-normals':
            no_normals = True
        elif opt == '--no-colors':
            no_colors = True
        elif opt == '--no-uvs':
            no_uvs = True
        elif opt == '--patch':
            patch = True
        elif opt == '--moonview':
            moonview = True
        else:
            print("Unknown option '{}'".format(opt))
            print(USAGE)
            sys.exit(2)
    if args:
        if cmd_args:
            cmd_args.extend(args)
        else:
            cmd_args = args
    if do_help:
        if not command and cmd_args:
            command = cmd_args[0]
        hlp(command)
        sys.exit()

    app_dir = os.path.dirname(os.path.dirname(app_dir))
    while not os.path.exists(os.path.join(app_dir, 'etc')):
        app_dir = os.path.dirname(app_dir)
        if not app_dir:
            AutoFix.error('Failed to find folder "etc"')
            break
    if debug and loudness is None:
        loudness = 5
    if app_dir:
        app_dir = os.path.join(app_dir, 'etc', 'abmatt')
        config = load_config(app_dir, loudness, autofix)
    Command.APP_DIR = app_dir
    Command.DEBUG = debug
    Brres.MOONVIEW = moonview
    cmds = []
    if cmd_args:
        if cmd_args[0] == 'convert':
            if single_bone:
                cmd_args.append('--single-bone')
            if no_colors:
                cmd_args.append('--no-colors')
            if no_normals:
                cmd_args.append('--no-normals')
            if no_uvs:
                cmd_args.append('--no-uvs')
            if patch:
                cmd_args.append('--patch')
        cmds.append(Command(arg_list=cmd_args))
    if command:
        args = [command, type]
        if key:
            if value:
                args.append(key + ':' + value)
            else:
                args.append(key)
        if not name and key != 'keys':
            name = '*'
        if name or model:
            args.extend(['for', name])
            if model:
                args.extend(['in', 'model', model])
        if command == 'convert':
            if single_bone:
                args.append('--single-bone')
            if no_colors:
                args.append('--no-colors')
            if no_normals:
                args.append('--no-normals')
            if no_uvs:
                args.append('--no-uvs')
            if patch:
                args.append('--patch')
        cmds.append(Command(arg_list=args))
    if destination:
        Command.DESTINATION = destination
        Brres.DESTINATION = destination
    if overwrite:
        Command.OVERWRITE = overwrite
        Brres.OVERWRITE = overwrite
    if brres_file:
        try:
            Command.updateSelection(brres_file)
        except NoSuchFile as e:
            AutoFix.exception(e, True)

    if command_file:
        try:
            filecmds = Command.load_commandfile(command_file)
            if filecmds:
                cmds = cmds + filecmds
        except NoSuchFile as err:
            AutoFix.error(err)

    # Run Commands
    if cmds:
        if not Command.run_commands(cmds):
            sys.exit(1)
    if interactive:
        Shell().cmdloop('Interactive shell started...')
    return Brres.OPEN_FILES