def _sign_sounds(self): sound_list = [] JFileUtils.find_files(self._dst_dir, sound_list, ['.mp3']) if len(sound_list) < 1: return author = JWords.hump(5, 10) print('... sign sounds, author:', author) JSoundsSigner.sign_sounds(sound_list, author)
def rand_dir_path_by_depth(parent, depth, left=3, right=15): dir_path = parent for i in range(depth): while (True): f = os.path.join(dir_path, JWords.hump(left, right)) if not os.path.exists(f): # 避免覆盖 dir_path = f break if (not os.path.exists(dir_path)): JFileUtils.mkdir(dir_path) return dir_path
def _marge_assets(self): if (self._src_dir is None) or (self._tmp_dir is None): return print('... coping resource') JFileUtils.rmdir(self._tmp_dir) JFileUtils.copy_dirs(self._src_dir, self._tmp_dir) # 合并马甲资源 if self._merge_dirs is not None: print('... merging resource') for res_dir in self._merge_dirs: # JFileUtils.merge_dir(res_dir, os.path.join(self._tmp_dir, os.path.basename(res_dir))) JFileUtils.merge_dir(res_dir, self._tmp_dir)
def _prepare(self): JFileUtils.rmdir(self._source_dir) mix_dirs = [] for i in range(random.randint(1, 21)): d = os.path.join(self._source_dir, JOcHelper.var(self._mix_dirs)) JFileUtils.mkdir(d) mix_dirs.append(d) self._mix_dirs = mix_dirs refs_dir = os.path.join(self._source_dir, JOcHelper.var()) JFileUtils.mkdir(refs_dir) self._refs_dir = refs_dir
def _pack_assets(self): if (self._tmp_dir is None) or (self._package_nums is None): return print('... packaging, nums:', self._package_nums) packageInfos = [] for i in range(self._package_nums): pi = JPackageInfo() pi.pack_bin_path = JFileUtils.rand_path(self._dst_dir, JPackageInfo.ASSETS_PACKAGE_EXT) pi.pack_bin_sign = random.randint(1, 9999999) pi.pack_bin_version = random.randint(1, 9999999) pi.pack_bin_compress = 0 packageInfos.append(pi) self._assets_info.package_list = packageInfos # 把.mp3文件先抽出来 ignor_count = 0 root_node_p = len(self._tmp_dir) + 1 for (root, dirs, files) in os.walk(self._tmp_dir): for f in files: if (os.path.splitext(f)[1].lower() == '.mp3'): file_path = os.path.join(root, f) dest_node = file_path[root_node_p:] dest_path = os.path.join(self._dst_dir, dest_node) dest_dir = os.path.dirname(dest_path) if not os.path.exists(dest_dir): os.makedirs(dest_dir) shutil.move(file_path, dest_path) ignor_count += 1 print('packaging strip file:', ignor_count) # 生成资源包 bin_exec = os.path.dirname(os.path.abspath(__file__)) + '/execs/AssetsBinTools' cmd = 'exec %s %d %s' % (bin_exec, 1, self._tmp_dir) for pi in packageInfos: cmd += (' %s %d %d %d' % (pi.pack_bin_path, pi.pack_bin_version, pi.pack_bin_sign, pi.pack_bin_compress)) print('CMD:', cmd) exit_code = os.system(cmd) assert exit_code == 0, 'pack assets error:%d' % exit_code
def _rename_assets(self): # 获取文件列表 root_dir = self._dst_dir file_list = [] JFileUtils.find_files(root_dir, file_list) if len(file_list) < 1: return print('... renaming') # 生成垃圾文件夹结构 use_junk_tree = False file_ext_list = None junks_maker = self._junks_maker if (self._app_filler_nums > 0) and (self._app_filler_size > 0): junks_maker.make_app_filler(root_dir, self._app_filler_nums, self._app_filler_size) use_junk_tree = True else: file_ext_list = [] for i in range(random.randint(2, 5)): file_ext_list.append(JFillerHelper.rand_file_ext()) # 重命名资源 name_pos = len(root_dir) + 1 name_map = {} for file in file_list: new_path = None if use_junk_tree : new_ext = junks_maker.rand_file_ext() new_dir = junks_maker.find_folder_by_ext(new_ext) new_path = new_dir.rand_child_path(new_ext) else: new_path = JFileUtils.rand_path(root_dir, random.choice(file_ext_list)) shutil.move(file, new_path) new_name = new_path[name_pos:] # 保存引用索引 if os.path.splitext(file)[1] == JPackageInfo.ASSETS_PACKAGE_EXT: for pi in self._assets_info.package_list: if 0 == JFileUtils.compare_path(file, pi.pack_bin_path): pi.pack_bin_path = new_name # print('package: %s' % new_name) break else: old_name = file[name_pos:] name_map[old_name] = new_name JFileUtils.delete_gap_dir(root_dir)# 删除空的文件夹 self._assets_info.mapping_dict = name_map print('rename done [%d]' % len(name_map))
def _prepare(self): JFileUtils.rmdir(self._dst_dir) JFileUtils.mkdir(self._dst_dir)