- Add max rom id option support,

- Change duplicate rom naming: now the first OK and KO roms are not marked duplicate,
- Improve and fix statistics.
This commit is contained in:
agibert 2009-03-29 23:46:42 +00:00
parent dcc023872f
commit 17864a7329

192
nds2rm
View File

@ -5,9 +5,9 @@
# (C) 2009 Arnaud G. Gibert
#-----------------------------------------------------------------------------------------------------------------------------------
# $RCSfile: nds2rm,v $
# $Revision: 1.7 $
# $Revision: 1.8 $
# $Name: $
# $Date: 2009/03/26 09:16:35 $
# $Date: 2009/03/29 23:46:42 $
# $Author: agibert $
#-----------------------------------------------------------------------------------------------------------------------------------
@ -79,12 +79,13 @@ function help_print()
echo "-D|--dsrom: dsrom.lst will be dumped"
echo "-h|--help: print this help and exit"
echo "-V|--version: print the version and exit"
echo "-r|--rebuild: don't trust archive file name (test & correct mode), "
echo "-r|--rebuild: don't trust archive file name (test & correct mode)"
echo " rebuild archives (correct mode)"
echo "-n|--renum: try to renumber archives,"
echo " --list_ok:"
echo " --list_ko:"
echo " --list_miss:"
echo "-m|--max <id>: maximum rom id to load from dat file"
echo "-n|--renum: try to renumber archives"
echo " --list_ok: list roms with ok status"
echo " --list_ko: list roms with ko status"
echo " --list_miss: list missing roms"
echo "-v|--verbose: switch on verbosity"
}
@ -97,7 +98,6 @@ function help_print()
function args_parse()
{
mode="test"
rebuild="no"
renum="no"
@ -105,8 +105,10 @@ function args_parse()
lko="no"
lmiss="no"
verbose="no"
max_idx=9999
tmp_args=$(getopt -o CTDhVrnv --long correct,test,dsrom,help,version,rebuild,renum,list_ok,list_ko,list_miss,verbose -n 'nds_rom_mng' -- "$@")
tmp_args=$(getopt -o CTDhVrm:nv --long correct,test,dsrom,help,version,rebuild,max:,renum,list_ok,list_ko,list_miss,verbose -n 'nds_rom_mng' -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
@ -115,18 +117,19 @@ function args_parse()
while true ; do
case "$1" in
-C|--correct) mode="correct"; shift;;
-T|--test) mode="test"; shift;;
-D|--dsrom) mode="dsrom"; shift;;
-h|--help) mode="exit"; help_print; shift;;
-V|--version) mode="exit"; version_print; shift;;
-r|--rebuild) rebuild="yes"; shift;;
-n|--renum) renum="yes"; shift;;
--list_ok) lok="yes"; shift;;
--list_ko) lko="yes"; shift;;
--list_miss) lmiss="yes"; shift;;
-v|--verbose) verbose="yes"; shift;;
--) shift; break;;
-C|--correct) mode="correct"; shift;;
-T|--test) mode="test"; shift;;
-D|--dsrom) mode="dsrom"; shift;;
-h|--help) mode="exit"; help_print; shift;;
-V|--version) mode="exit"; version_print; shift;;
-r|--rebuild) rebuild="yes"; shift;;
-m|--max) shift; max_idx="$1"; shift;;
-n|--renum) renum="yes"; shift;;
--list_ok) lok="yes"; shift;;
--list_ko) lko="yes"; shift;;
--list_miss) lmiss="yes"; shift;;
-v|--verbose) verbose="yes"; shift;;
--) shift; break;;
*) echo "args_parse internal error [$1] !"; exit 1;;
esac
done
@ -143,7 +146,8 @@ function dat_load()
{
echo "loading dsrom.dat..."
IFS=';'
loaded_cnt=0
IFS=';'
while read line
do
@ -175,6 +179,12 @@ function dat_load()
dat_dup[${idx}]="0"
loaded_cnt=$((${loaded_cnt} + 1))
if [[ ${loaded_cnt} -ge ${max_idx} ]]
then
echo "max rom id reached: skipping loading !"
break;
fi
fi
done < ${NDS_DAT}
}
@ -349,19 +359,19 @@ function mask_get()
function dsrom_dump()
{
i=1
i=1
while [[ ${i} -le ${loaded_cnt} ]]
do
if [[ ${dat_status[${i}]} != "?" ]]
then
mask=$(mask_get "${dat_save_type[${i}]}")
while [[ ${i} -le ${loaded_cnt} ]]
do
if [[ ${dat_status[${i}]} != "?" ]]
then
mask=$(mask_get "${dat_save_type[${i}]}")
echo "${dat_id[${i}]} ${dat_fp[${i}]}-0 $mask ${dat_title[${i}]} (${dat_region[${i}]}:${dat_lang[${i}]}) [${dat_status[${i}]}] {${dat_crc[${i}]}}"
fi
echo "${dat_id[${i}]} ${dat_fp[${i}]}-0 $mask ${dat_title[${i}]} (${dat_region[${i}]}:${dat_lang[${i}]}) [${dat_status[${i}]}] {${dat_crc[${i}]}}"
fi
i=$(( ${i} + 1 ))
done
i=$(( ${i} + 1 ))
done
}
@ -660,6 +670,12 @@ function arc_proceed()
id=$1
idx=${id/*(0)/}
if [[ ${idx} -gt ${loaded_cnt} ]]
then
echo "max rom id reached: skipping processing !"
break;
fi
# Get info from dat
title=${dat_title[${idx}]}
@ -879,12 +895,15 @@ function suffix_mng()
{
echo "managing duplicate archives..."
IFS=' '
found_cnt=0
ok_cnt=0
ko_cnt=0
dup_cnt=0
idx_old=0
IFS=' '
found_cnt=0
ok_cnt=0
ko_cnt=0
dup_cnt=0
ignored_cnt=0
idx_old=0
status_old=""
tmp_file=$(mktemp)
@ -897,37 +916,43 @@ function suffix_mng()
id=$1
idx=${id/*(0)/}
status=${file/* \[/}; status=${status/\] \{*/}
crc=${file/*\] \{/}; crc=${crc/\} \<*/}
fp=${file/*\} \</}; fp=${fp/\>-*/}
dat_dup[${idx}]="${dup_id}"
if [[ ${idx} != ${idx_old} ]]
if [[ ${idx} -gt ${loaded_cnt} ]]
then
idx_old=${idx}
dup_id=0
file_name="${file/) \[*/}) [${status}] {${crc}} <${fp}>.zip"
dat_fp[${idx}]="${fp}"
dat_status[${idx}]="${status}"
if [[ "${status}" == "OK" ]]
then
ok_cnt=$((${ok_cnt} + 1))
else
ko_cnt=$((${ko_cnt} + 1))
fi
ignored_cnt=$((${ignored_cnt} + 1))
else
dup_id=$((${dup_id} + 1))
file_name="${file/) \[*/}) [${status}] {${crc}} <${fp}>-${dup_id}.zip"
status=${file/* \[/}; status=${status/\] \{*/}
crc=${file/*\] \{/}; crc=${crc/\} \<*/}
fp=${file/*\} \</}; fp=${fp/\>-*/}
dup_cnt=$((${dup_cnt} + 1))
dat_dup[${idx}]="${dup_id}"
if [[ ( ${idx} != ${idx_old} ) || ( "${status}" != "${status_old}" ) ]]
then
idx_old=${idx}
status_old=${status}
dup_id=0
file_name="${file/) \[*/}) [${status}] {${crc}} <${fp}>.zip"
dat_fp[${idx}]="${fp}"
dat_status[${idx}]="${status}"
if [[ "${status}" == "OK" ]]
then
ok_cnt=$((${ok_cnt} + 1))
else
ko_cnt=$((${ko_cnt} + 1))
fi
else
dup_id=$((${dup_id} + 1))
file_name="${file/) \[*/}) [${status}] {${crc}} <${fp}>-${dup_id}.zip"
dup_cnt=$((${dup_cnt} + 1))
fi
print_verbose "moving ${file} to ${file_name}"
arc_mv "${NDS_ROMS_OUT}/${file_name}" "${NDS_ROMS_OUT}/${file}" "${mode}"
fi
print_verbose "moving ${file} to ${file_name}"
arc_mv "${NDS_ROMS_OUT}/${file_name}" "${NDS_ROMS_OUT}/${file}" "${mode}"
found_cnt=$((${found_cnt} + 1))
printf "found: %4d" ${found_cnt}
@ -1006,12 +1031,15 @@ function stats_update()
function stats_proceed()
{
ss_ok_cnt=0
ss_ko_cnt=0
cs_ok_cnt=0
cs_ko_cnt=0
ks_ok_cnt=0
ks_ko_cnt=0
ss_ok_cnt=0
ss_ko_cnt=0
cs_ok_cnt=0
cs_ko_cnt=0
ks_ok_cnt=0
ks_ko_cnt=0
proceeded_cnt=0
missing_cnt=0
while read file
do
@ -1026,8 +1054,20 @@ function stats_proceed()
\rm -f "${STATS_FILE}"
found_cnt=$((${ok_cnt} + ${ko_cnt}))
missing_cnt=$((${loaded_cnt} - ${found_cnt}))
found_cnt=$((${ok_cnt} + ${ko_cnt} + ${dup_cnt} + ${ignored_cnt}))
proceeded_cnt=$((${found_cnt} - ${ignored_cnt}))
i=1
while [[ ${i} -le ${loaded_cnt} ]]
do
if [[ ${dat_status[${i}]} == "?" ]]
then
missing_cnt=$((${missing_cnt} + 1))
fi
i=$(( ${i} + 1 ))
done
}
@ -1053,6 +1093,8 @@ function stats_print()
echo
printf "%4d roms are in dsrom.dat\n" ${loaded_cnt}
printf "%4d roms are found\n" ${found_cnt}
printf "%4d roms are ignored\n" ${ignored_cnt}
printf "%4d roms are proceeded\n" ${proceeded_cnt}
printf "%4d roms are renumbered\n" ${renum_cnt}
printf "%4d roms are duplicated\n" ${dup_cnt}
printf "%4d roms are missing\n" ${missing_cnt}
@ -1080,6 +1122,11 @@ function dsrom_mode()
id=$1
idx=${id/*(0)/}
if [[ ${idx} -gt ${loaded_cnt} ]]
then
break;
fi
# Get info from dat
title=${dat_title[${idx}]}
@ -1169,7 +1216,6 @@ cd ${TMP_DIR}
# Initialise stats variables
loaded_cnt=0
ok_cnt=0
ko_cnt=0
found_cnt=0