-#!/bin/bash
-###
- # @Date: 2024-06-07 09:44:50
+#!/bin/bash
+###
+# @Date: 2024-06-07 09:44:50
# @LastEditors: Caisking 3449750381@qq.com
- # @LastEditTime: 2024-07-18 16:59:20
+ # @LastEditTime: 2024-08-30 15:00:54
# @FilePath: /FD230/tools/dial_converter_tool/make_tools/gen_dial_bin.sh
-###
-
-# 返回上一级目录
-cd ..
-
-# 检查并创建 out 和 dial_lzma 目录
-mkdir -p out dial_lzma
-
-# 获取 instance 目录下的所有子目录列表
-subdirs=(instance/*/)
-for subdir in "${subdirs[@]}"; do
- # 提取子目录名称
- dial=$(basename "$subdir")
-
- # 查找子目录中的 XML 文件并提取文件名
- xml_file=$(find "$subdir" -maxdepth 1 -type f -name "*.xml" -printf "%f\n" | head -n 1)
- if [ -z "$xml_file" ]; then
- echo "Error: XML file not found in $subdir"
- continue
- fi
-
- # 计算文件数量和大小
- dialfilecount=$(find "$subdir" -maxdepth 1 -type f | wc -l)
- dialfilesize=$(du -sh "$subdir" | awk '{print $1}')
-
- # 输出统计信息
- echo "Processing $dial [$dialfilecount files, $dialfilesize size]"
-
- # 调用 main.py 处理子目录中的文件
- if ! python main.py -dir "$subdir" -output out/; then
- echo "Error processing directory $dial"
- continue
- fi
-
- # 压缩 .bin 文件到 .lzma 文件
- bin_file="out/${xml_file%.xml}.bin"
- lzma_file="dial_lzma/$dial/${xml_file%.xml}.lzma"
-
- # 创建必要的目录
- mkdir -p "$(dirname "$lzma_file")"
-
- # 使用 lzma_tool 压缩文件
- if ! ../../code/sdk/tools/bin/lzma_tool/lzma_tool -d12 -lc0 -lp0 e "$bin_file" "$lzma_file"; then
- echo " lzma_tool directory $dial error"
- else
- echo " lzma_tool directory $dial ok"
- fi
+###
+
+# 返回上一级目录
+cd ..
+
+# 检查并创建 out 和 dial_lzma 目录
+mkdir -p out dial_lzma
+
+# 检查是否传入参数
+if [ "$#" -gt 1 ]; then
+ echo "Usage: $0 [dial_folder]"
+ exit 1
+fi
+
+# 如果有参数,则处理指定的目录;否则处理所有子目录
+if [ "$#" -eq 1 ]; then
+ subdirs=("instance/$1/")
+ if [ ! -d "instance/$1" ]; then
+ echo "Error: Specified directory 'instance/$1' does not exist."
+ exit 1
+ fi
+else
+ subdirs=(instance/*/)
+fi
+
+for subdir in "${subdirs[@]}"; do
+ # 提取子目录名称
+ dial=$(basename "$subdir")
+
+ # 查找子目录中的 XML 文件并提取文件名
+ xml_file=$(find "$subdir" -maxdepth 1 -type f -name "*.xml" -printf "%f\n" | head -n 1)
+ if [ -z "$xml_file" ]; then
+ echo "Error: XML file not found in $subdir"
+ continue
+ fi
+
+ # 计算文件数量和大小
+ dialfilecount=$(find "$subdir" -maxdepth 1 -type f | wc -l)
+ dialfilesize=$(du -sh "$subdir" | awk '{print $1}')
+
+ # 输出统计信息
+ echo "Processing $dial [$dialfilecount files, $dialfilesize size]"
+
+ # 调用 main.py 处理子目录中的文件
+ if ! python main.py -dir "$subdir" -output out/; then
+ echo "Error processing directory $dial"
+ continue
+ fi
+
+ # 压缩 .bin 文件到 .lzma 文件
+ bin_file="out/${xml_file%.xml}.bin"
+ lzma_file="dial_lzma/$dial/${xml_file%.xml}.lzma"
+
+ # 创建必要的目录
+ mkdir -p "$(dirname "$lzma_file")"
+
+ # 使用 lzma_tool 压缩文件
+ if ! ../../code/sdk/tools/bin/lzma_tool/lzma_tool -d12 -lc0 -lp0 e "$bin_file" "$lzma_file"; then
+ echo " lzma_tool directory $dial error"
+ else
+ echo " lzma_tool directory $dial ok"
+ fi
done
\ No newline at end of file