# 递归检查‘新增’文件 # param1: 源文件夹;param2:目的文件夹 function rec_check_add_file() { dir_list=$(ls $1) # 获取所有(可视)文件 for name in ${dir_list[*]} # 遍历文件路径数组 do # 资源文件夹过滤判断 if [ "$1" == "$source_dir" ] ; then # 顶层文件夹过滤 if [ "$name" != "Classes" ] && [ "$name" != "Data" ] && [ "$name" != "Libraries" ]; then continue fi fi
if [ "$1" == "$source_dir/Classes" ]; then # Classes/Native 文件夹过滤 if [ "$name" != "Native" ]; then continue fi fi
if [ -f $1/$name ]; then # 如果路径 ‘$1/$name’ 是文件 if [ ! -f $2/$name ]; then # 如果路径 ‘$2/$name’ 文件不存在 add_file_array[${#add_file_array[@]}]=$2/$name # 记录‘新增’文件 fi echo "拷贝文件:$1/$name" cp $1/$name $2/$name # 拷贝到目标路径
elif [ -d $1/$name ]; then # 如果 $1/$name 是文件夹 if [ ! -d $2/$name ]; then # 如果 $2/$name 文件夹不存在 add_foloder_array[${#add_foloder_array[@]}]=$2/$name # 记录‘新增’文件夹 echo "创建文件夹:$2/$name" mkdir -p $2/$name # 创建文件夹 fi # 递归处理 rec_check_add_file $1/$name $2/$name fi done }
# 递归检查‘新增’文件 defrec_check_add_file(src_file_path, dest_file_path) Dir.foreach(src_file_path) do|file_name| # 系统‘隐藏’文件过滤 if file_name == "."or file_name == ".."or file_name == ".DS_Store" next end # 资源文件夹过滤 if src_file_path == @source_dir_path # 顶层文件夹过滤 if file_name != "Classes"and file_name != "Data"and file_name != "Libraries" next end end # Classes/Native 文件夹过滤 if src_file_path == @source_dir_path + "/Classes" if file_name != "Native" next end end
# 添加文件依赖 defadd_reference(target, project, to_group, file_path, need_mrc) if to_group and File::exist?(file_path) if file_path != "."and file_path != ".."and file_path != ".DS_Store" pb_gen_file_path = file_path if to_group.find_file_by_path(pb_gen_file_path) puts pb_gen_file_path + " reference exist" else file_reference = to_group.new_reference(pb_gen_file_path) if need_mrc and file_path.include?("pbobjc.m") target.add_file_references([file_reference],'-fno-objc-arc') else target.add_file_references([file_reference]) end end end project.save end end
删除 Unity 文件依赖(Ruby)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# 移除文件依赖 defrmv_reference(target, project, from_group, file_path) if from_group and file_path from_group.files.each do|file_ref| if file_ref.real_path.to_s == file_path file_ref.remove_from_project target.source_build_phase.remove_file_reference(file_ref) target.resources_build_phase.remove_file_reference(file_ref) target.headers_build_phase.remove_file_reference(file_ref) break end end project.save end end