def refill_menu(): menu.categories.clear() try: import sc_compression del sc_compression from system.lib.features.csv.compress import compress_csv from system.lib.features.csv.decompress import decompress_csv try: import PIL del PIL from system.lib.features.sc.assembly_encode import sc1_encode from system.lib.features.sc.decode import sc_decode from system.lib.features.sc.decode_and_cut import sc1_decode from system.lib.features.sc.sc_encode import sc_encode sc_category = Menu.Category(0, locale.sc_label) sc_category.add( Menu.Item(locale.decode_sc, locale.decode_sc_description, sc_decode)) sc_category.add( Menu.Item(locale.encode_sc, locale.encode_sc_description, sc_encode)) sc_category.add( Menu.Item(locale.decode_by_parts, locale.decode_by_parts_description, sc1_decode)) sc_category.add( Menu.Item(locale.encode_by_parts, locale.encode_by_parts_description, sc1_encode)) sc_category.add( Menu.Item(locale.overwrite_by_parts, locale.overwrite_by_parts_description, lambda: sc1_encode(True))) menu.add_category(sc_category) except ImportError: logger.warning(locale.install_to_unlock % 'PILLOW') csv_category = Menu.Category(1, locale.csv_label) csv_category.add( Menu.Item(locale.decompress_csv, locale.decompress_csv_description, decompress_csv)) csv_category.add( Menu.Item(locale.compress_csv, locale.compress_csv_description, compress_csv)) menu.add_category(csv_category) except ImportError: logger.warning(locale.install_to_unlock % 'sc-compression') other = Menu.Category(10, locale.other_features_label) try: import requests del requests other.add( Menu.Item(locale.check_update, locale.version % config.version, check_update)) except ImportError: logger.warning(locale.install_to_unlock % 'requests') other.add(Menu.Item(locale.check_for_outdated, None, check_for_outdated)) other.add( Menu.Item(locale.reinit, locale.reinit_description, lambda: (initialize(), refill_menu()))) other.add( Menu.Item( locale.change_language, locale.change_lang_description % config.language, lambda: (config.change_language(locale.change()), refill_menu()))) other.add( Menu.Item( locale.clear_directories, locale.clean_dirs_description, lambda: clear_directories() if Console.question(locale.clear_qu) else -1)) other.add( Menu.Item(locale.toggle_update_auto_checking, locale.enabled if config.auto_update else locale.disabled, lambda: (config.toggle_auto_update(), refill_menu()))) other.add(Menu.Item(locale.exit, None, lambda: (clear(), exit()))) menu.add_category(other)
def compile_sc(_dir, from_memory=None, img_data=None, folder_export=None): sc_data = None name = _dir.split('/')[-2] if from_memory: files = from_memory else: files = [] [ files.append(i) if i.endswith('.png') else None for i in os.listdir(_dir) ] files.sort() if not files: return logger.info(locale.dir_empty % _dir.split('/')[-2]) files = [Image.open(f'{_dir}{i}') for i in files] logger.info(locale.collecting_inf) sc = Writer() has_xcod = False use_lzham = False if from_memory: use_lzham = img_data['use_lzham'] else: try: sc_data = open(f'{_dir}/{name}.xcod', 'rb') sc_data.read(4) use_lzham, = struct.unpack('?', sc_data.read(1)) sc_data.read(1) has_xcod = True except OSError: logger.info(locale.not_xcod) logger.info(locale.default_types) for picture_index in range(len(files)): img = files[picture_index] print() if from_memory: file_type = img_data['data'][picture_index]['file_type'] pixel_type = img_data['data'][picture_index]['pixel_type'] else: if has_xcod: file_type, pixel_type, width, height = struct.unpack( '>BBHH', sc_data.read(6)) if (width, height) != img.size: logger.info(locale.illegal_size % (width, height, img.width, img.height)) if Console.question(locale.resize_qu): logger.info(locale.resizing) img = img.resize((width, height), Image.ANTIALIAS) else: file_type, pixel_type = 1, 0 width, height = img.size pixel_size = get_pixel_size(pixel_type) img = img.convert('RGBA') x = Image.new('RGBA', img.size, (0, 0, 0, 1)) x.paste(img, (0, 0), img) img = x img = img.convert(pixel_type2str(pixel_type)) file_size = width * height * pixel_size + 5 logger.info(locale.about_sc % (name, picture_index, pixel_type, width, height)) sc.write( struct.pack('<BIBHH', file_type, file_size, pixel_type, width, height)) if file_type in (27, 28): split_image(img) print() rgba2bytes(sc, img, pixel_type) print() sc.write(bytes(5)) print() write_sc(f'{folder_export}/{name}.sc', sc.getvalue(), use_lzham)
locale.load(config.language) try: import requests del requests if config.auto_update and time.time( ) - config.last_update > 60 * 60 * 24 * 7: check_update() config.last_update = int(time.time()) config.dump() if config.has_update: logger.opt( colors=True).info(f'<green>{locale.update_done % ""}</green>') if Console.question(locale.done_qu): latest_tag = get_tags('vorono4ka', 'xcoder')[0] latest_tag_name = latest_tag['name'][1:] config.has_update = False config.version = latest_tag_name config.last_update = int(time.time()) config.dump() else: exit() except ImportError: pass @logger.catch() def refill_menu():