Add basic duplicate ROM support,

Add verbose message support.
This release should be usable but needs more testing...
This commit is contained in:
agibert 2009-03-22 22:31:58 +00:00
parent e4f08e2dcc
commit 48d1f42f3b

201
nds2rm
View File

@ -5,9 +5,9 @@
# (C) 2009 Arnaud G. Gibert # (C) 2009 Arnaud G. Gibert
#----------------------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------------------
# $RCSfile: nds2rm,v $ # $RCSfile: nds2rm,v $
# $Revision: 1.2 $ # $Revision: 1.3 $
# $Name: $ # $Name: $
# $Date: 2009/03/22 01:18:12 $ # $Date: 2009/03/22 22:31:58 $
# $Author: agibert $ # $Author: agibert $
#----------------------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------------------
@ -83,8 +83,9 @@ function args_parse()
lok="no" lok="no"
lko="no" lko="no"
lmiss="no" lmiss="no"
verbose="no"
tmp_args=$(getopt -o CTDhVrn --long correct,test,dsrom,help,version,rebuild,renum,list_ok,list_ko,list_miss -n 'nds_rom_mng' -- "$@") tmp_args=$(getopt -o CTDhVrnv --long correct,test,dsrom,help,version,rebuild,renum,list_ok,list_ko,list_miss,verbose -n 'nds_rom_mng' -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
@ -103,6 +104,7 @@ function args_parse()
--list_ok) lok="yes"; shift;; --list_ok) lok="yes"; shift;;
--list_ko) lko="yes"; shift;; --list_ko) lko="yes"; shift;;
--list_miss) lmiss="yes"; shift;; --list_miss) lmiss="yes"; shift;;
-v|--verbose) verbose="yes"; shift;;
--) shift; break;; --) shift; break;;
*) echo "Internal error [$1] !"; exit 1;; *) echo "Internal error [$1] !"; exit 1;;
esac esac
@ -118,7 +120,8 @@ function args_parse()
function crc_lookup() function crc_lookup()
{ {
crc=${1} idx_ptr=${1}
crc=${2}
i=1 i=1
@ -130,11 +133,27 @@ function crc_lookup()
if [[ ${i} -le ${loaded_cnt} ]] if [[ ${i} -le ${loaded_cnt} ]]
then then
# eval ${idx_ptr}=${i} eval ${idx_ptr}=${i}
echo ${i}
else else
# eval ${idx_ptr}="" eval ${idx_ptr}=""
echo "" fi
}
# Dump Rom List
#-----------------------------------------------------------------------------------------------------------------------------------
function print_verbose()
{
text=${1}
if [[ "${verbose}" == "yes" ]]
then
echo "${text}"
fi fi
} }
@ -317,6 +336,109 @@ function stats_update()
# Lookup Duplicate Arc
#-----------------------------------------------------------------------------------------------------------------------------------
function arc_dup_lookup()
{
dup_name_ptr=${1}
file_prefix=${2}
file_suffix=${3}
if [[ -f "${file_prefix}${file_suffix}" ]]
then
i=1
while [[ -f "${file_prefix}-${i}.{file_suffix}" ]]
do
i=$((${i} + 1))
done
dup_name="-${i}"
dup_cnt=$((${dup_cnt} + 1))
else
dup_name=""
fi
eval ${dup_name_ptr}=${dup_name}
}
# Add Arc
#-----------------------------------------------------------------------------------------------------------------------------------
function arc_add()
{
file_name_ptr=${1}
dir=${2}
id=${3}
title=${4}
reg=${5}
lang=${6}
crc=${7}
fp=${8}
status=${9}
file_prefix="${dir}/${id} - ${title} (${reg}) [${lang}] {${crc}} <${fp}> ${status}"
file_suffix=".zip"
if [[ -f "${file_prefix}${file_suffix}" ]]
then
arc_dup_lookup "dup_name" "${file_prefix}" "${file_suffix}"
if [[ "${status}" == "OK" ]]
then
print_verbose "moving ${file_prefix}${file_suffix} to ${file_prefix}${dup_name}${file_suffix}"
mv "${file_prefix}${file_suffix}" "${file_prefix}${dup_name}${file_suffix}"
dup_name=""
fi
else
dup_name=""
fi
eval ${file_name_ptr}=\"${file_prefix}${dup_name}${file_suffix}\"
}
# Remove Arc
#-----------------------------------------------------------------------------------------------------------------------------------
#function arc_remove()
#{
# file=${1}
#
#
# prefix=${file/\> ??*.zip/>}
#
# arc_list=$(mktemp)
# ls ${prefix}* > ${arc_list}
#
# arc_mode="scan"
#
# while read arc
# do
# case "${arc_mode}"
# in
#
# esac
# done < ${arc_list}
#
# \rm -f ${arc_list}
#}
# Build Arc # Build Arc
#----------------------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------------------
@ -338,11 +460,21 @@ function arc_build()
then then
if [[ ${in_place} == "yes" ]] if [[ ${in_place} == "yes" ]]
then then
print_verbose "removing ${file}"
\rm -f "${NDS_ROMS_IN}/${file}" \rm -f "${NDS_ROMS_IN}/${file}"
# arc_remove "${file}"
fi fi
zip -m9 "${NDS_ROMS_OUT}/${id} - ${title} (${reg}) [${lang}] {${crc}} <${fp}> ${status}.zip" "${rom}" >/dev/null 2>&1 & arc_add "file_name" "${NDS_ROMS_OUT}" "${id}" "${title}" "${reg}" "${lang}" "${crc}" "${fp}" "${status}"
print_verbose "zipping ${rom} into ${file_name}"
zip -m9 "${file_name}" "${rom}" >/dev/null 2>&1
else else
print_verbose "removing ${rom}"
\rm -f "${rom}" \rm -f "${rom}"
fi fi
} }
@ -372,11 +504,17 @@ function arc_rename()
then then
if [[ ${action} != "keep_status" ]] if [[ ${action} != "keep_status" ]]
then then
arc_add "file_name" "${NDS_ROMS_OUT}" "${id}" "${title}" "${reg}" "${lang}" "${crc}" "${fp}" "${status}"
if [[ ${in_place} == "yes" ]] if [[ ${in_place} == "yes" ]]
then then
mv "${NDS_ROMS_IN}/${file}" "${NDS_ROMS_OUT}/${id} - ${title} (${reg}) [${lang}] {${crc}} <${fp}> ${status}.zip" print_verbose "moving ${file} to ${file_name}"
mv "${NDS_ROMS_IN}/${file}" "${file_name}"
else else
cp "${NDS_ROMS_IN}/${file}" "${NDS_ROMS_OUT}/${id} - ${title} (${reg}) [${lang}] {${crc}} <${fp}> ${status}.zip" print_verbose "copying ${file} to ${file_name}"
cp "${NDS_ROMS_IN}/${file}" "${file_name}"
fi fi
fi fi
fi fi
@ -398,14 +536,20 @@ function rom_extract()
case "${file}" case "${file}"
in in
(*.nds) (*.nds)
print_verbose "copying ${file} to ${rom}"
cp "${NDS_ROMS_IN}/${file}" "${rom}" cp "${NDS_ROMS_IN}/${file}" "${rom}"
;; ;;
(*.rar) (*.rar)
print_verbose "extracting ${rom} from ${file}"
unrar p "${NDS_ROMS_IN}/${file}" > "${rom}" unrar p "${NDS_ROMS_IN}/${file}" > "${rom}"
;; ;;
(*.zip) (*.zip)
print_verbose "extracting ${rom} from ${file}"
unzip -p "${NDS_ROMS_IN}/${file}" > "${rom}" unzip -p "${NDS_ROMS_IN}/${file}" > "${rom}"
;; ;;
@ -567,7 +711,8 @@ do
if [[ ( ${status} == "KO" ) && ( "${renum}" == "yes" ) ]] if [[ ( ${status} == "KO" ) && ( "${renum}" == "yes" ) ]]
then then
idx2=$( crc_lookup "${crc2}" ) crc_lookup "idx2" "${crc2}"
if [[ "${idx2}" != "" ]] if [[ "${idx2}" != "" ]]
then then
idx=${idx2} idx=${idx2}
@ -577,6 +722,14 @@ do
lang=${dat_lang[${idx}]} lang=${dat_lang[${idx}]}
crc=${dat_crc[${idx}]} crc=${dat_crc[${idx}]}
# Rename the ROM file
rom2="${id} - ${title} (${reg}) [${lang}].nds"
print_verbose "moving ${rom} to ${rom2}"
mv "${rom}" "${rom2}"
rom=${rom2}
if [[ "${arc_type}" == "rx3" ]] if [[ "${arc_type}" == "rx3" ]]
then then
status=${file/* /}; status=${status/.zip/} status=${file/* /}; status=${status/.zip/}
@ -601,16 +754,8 @@ do
# Update Dat Info # Update Dat Info
if [[ ${dat_status[${idx}]} != "?" ]] if [[ "${dat_status[${idx}]}" != "OK" ]]
then then
if [[ "${mode}" == "test" ]]
then
dup_cnt=$((${dup_cnt} + 1))
else
echo "Error: Duplicate roms not yet supported !";
exit 1
fi
else
dat_fp[${idx}]=${fp} dat_fp[${idx}]=${fp}
dat_status[${idx}]=${status} dat_status[${idx}]=${status}
fi fi
@ -634,7 +779,14 @@ do
printf "found: %4d OK: %4d KO: %4d renumbered: %4d duplicated: %4d missing: %4d\r" ${found_cnt} ${ok_cnt} ${ko_cnt} ${renum_cnt} ${dup_cnt} ${missing_cnt} printf "found: %4d OK: %4d KO: %4d renumbered: %4d duplicated: %4d missing: %4d" ${found_cnt} ${ok_cnt} ${ko_cnt} ${renum_cnt} ${dup_cnt} ${missing_cnt}
if [[ "${verbose}" == "yes" ]]
then
echo
else
printf "\r"
fi
done < ${tmp_file} done < ${tmp_file}
@ -642,7 +794,10 @@ done < ${tmp_file}
wait wait
echo " " if [[ "${verbose}" != "yes" ]]
then
echo " "
fi