- Add .xml file loading support,

- Remove obsolete .dat file loading support,
- Now nds2rm is independant and nds-gen useless !
- Redirect processing messages to stderr.
This commit is contained in:
agibert 2009-03-30 22:57:13 +00:00
parent 17864a7329
commit 43dc7297d4

287
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.8 $ # $Revision: 1.9 $
# $Name: $ # $Name: $
# $Date: 2009/03/29 23:46:42 $ # $Date: 2009/03/30 22:57:13 $
# $Author: agibert $ # $Author: agibert $
#----------------------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------------------
@ -31,6 +31,9 @@
# User Config
#-----------------------------------------------------------------------------------------------------------------------------------
#NDS_REPOSITORY_IN=/opt/public/nds #NDS_REPOSITORY_IN=/opt/public/nds
NDS_REPOSITORY_IN=/opt/public/nds.new NDS_REPOSITORY_IN=/opt/public/nds.new
#NDS_REPOSITORY_IN=/opt/public/nds.new/nds.old #NDS_REPOSITORY_IN=/opt/public/nds.new/nds.old
@ -39,7 +42,13 @@ NDS_REPOSITORY_OUT=/opt/public/nds.new
#NDS_REPOSITORY_OUT=/opt/public/nds.new/nds.new #NDS_REPOSITORY_OUT=/opt/public/nds.new/nds.new
NDS_ROMS_IN=${NDS_REPOSITORY_IN}/roms NDS_ROMS_IN=${NDS_REPOSITORY_IN}/roms
NDS_ROMS_OUT=${NDS_REPOSITORY_OUT}/roms NDS_ROMS_OUT=${NDS_REPOSITORY_OUT}/roms
NDS_DAT=${NDS_REPOSITORY_IN}/misc/dsrom.dat NDS_XML=${NDS_REPOSITORY_IN}/misc/dsrom.xml
# System Constants
#-----------------------------------------------------------------------------------------------------------------------------------
STATS_FILE="stats.txt" STATS_FILE="stats.txt"
@ -51,6 +60,56 @@ NDS_VERSION="$Name: $"
RNFH_REGEX=".... - .* \(.*:.*\) \[..\] \{.*\} <.*>[-]*[0-9]*\.zip$" RNFH_REGEX=".... - .* \(.*:.*\) \[..\] \{.*\} <.*>[-]*[0-9]*\.zip$"
reg_tab[0]="E"; # Europe
reg_tab[1]="U"; # USA
reg_tab[2]="G"; # Germany
reg_tab[3]="C"; # China
reg_tab[4]="S"; # Spain
reg_tab[5]="F"; # France
reg_tab[6]="I"; # Italy
reg_tab[7]="J"; # Japan
reg_tab[8]="Nl"; # Nederland
reg_tab[9]="En"; # England
reg_tab[10]="Dn"; # Denmark
reg_tab[11]="Fi"; # Finland
reg_tab[12]="No"; # Norway
reg_tab[13]="Pl"; # Poland
reg_tab[14]="Pr"; # Portugal
reg_tab[15]="Sw"; # Sweden
reg_tab[16]="UE"; # USA and Europe
reg_tab[17]="JUE"; # Japan, USA and Europe
reg_tab[18]="JU"; # Japan and USA
reg_tab[19]="Au"; # Australia
reg_tab[20]="nK"; # North Korea
reg_tab[21]="Br"; # Brazil
reg_tab[22]="K"; # South Korea
reg_tab[23]="EB"; # Europe and Brazil
reg_tab[24]="EUB"; # Europe, USA and Brazil
reg_tab[25]="UB"; # USA and Brazil
reg_tab[26]="R"; # Russia
reg_tab[27]="R"; # Russia
reg_tab[28]="Gr"; # Greece
lang_tab[1]="Fr"; # French
lang_tab[2]="En"; # English
lang_tab[4]="Zh"; # Chinese
lang_tab[8]="da"; # Danish
lang_tab[16]="Nl"; # Dutch
lang_tab[32]="Fi"; # Finnish
lang_tab[64]="De"; # German
lang_tab[128]="It"; # Italian
lang_tab[256]="Ja"; # Japanese
lang_tab[512]="Nn"; # Norwegian
lang_tab[1024]="Pl"; # Polish
lang_tab[2048]="Pt"; # Portuguese
lang_tab[4096]="Es"; # Spanish
lang_tab[8192]="Sv"; # Swedish
lang_tab[16384]="En"; # English
lang_tab[32768]="Pt"; # Portuguese
lang_tab[65536]="Ko"; # Korean
lang_tab[131072]="Ru"; # Russian
lang_tab[262144]="El"; # Greek
@ -139,40 +198,129 @@ function args_parse()
# Load Dat File # Print Counter
#----------------------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------------------
function dat_load() function count_print
{ {
echo "loading dsrom.dat..." idx=${1}
loaded_cnt=0
IFS=';'
while read line printf "%4d" ${idx} 1>&2
do
set ${line}
idx=${2/*(0)/}
if [[ "${idx}" != "xxxx" ]]
then
echo -ne "$2"
if [[ "${verbose}" == "yes" ]] if [[ "${verbose}" == "yes" ]]
then then
echo echo 1>&2
else else
printf "\r" printf "\r" 1>&2
fi
}
# Convert Language to Lang
#-----------------------------------------------------------------------------------------------------------------------------------
function lang_conv
{
language=${1}
i=0
lang=""
while [[ ${i} -le 20 ]]
do
bit=$(( 2 ** i ))
if [[ $(( ${language} & ${bit} )) != 0 ]]
then
if [[ "${lang}" != "" ]]
then
lang="${lang}-"
fi fi
dat_rn[${idx}]="${1}" lang="${lang}${lang_tab[${bit}]}"
dat_id[${idx}]="${2}" fi
dat_title[${idx}]="${3}"
dat_region[${idx}]="${4}" i=$(( ${i} + 1 ))
dat_lang[${idx}]="${5}" done
dat_save_type[${idx}]="${6}"
dat_crc[${idx}]="${7}" echo "${lang}"
}
# Load XML File
#-----------------------------------------------------------------------------------------------------------------------------------
function xml_load()
{
echo "loading dsrom.xml..." 1>&2
loaded_cnt=0
IFS='>'
while read line
do
if [[ "${line}" != "" ]]
then
set ${line}
tag=${1/*</}
value=${2/<*/}
case "${tag}" in
("releaseNumber")
rn=${value}
;;
("title")
title=${value}
title=${title//&amp;/&}
title=${title//&lt;/<}
title=${title//&gt;/>}
;;
("saveType")
save_type=${value}
;;
("location")
location=${value}
;;
("language")
language=${value}
;;
("romCRC extension=\".nds\"")
crc=${value}
;;
("comment")
id=${value}
;;
("/game")
idx=${id/*(0)/}
if [[ "${idx}" != "xxxx" ]]
then
count_print ${idx}
dat_rn[${idx}]="${rn}"
dat_id[${idx}]="${id}"
dat_title[${idx}]="${title}"
dat_region[${idx}]="${reg_tab[${location}]}"
dat_lang[${idx}]=$(lang_conv "${language}")
dat_save_type[${idx}]="${save_type}"
dat_crc[${idx}]="${crc}"
dat_fp[${idx}]="????" dat_fp[${idx}]="????"
dat_status[${idx}]="?" dat_status[${idx}]="?"
@ -182,11 +330,14 @@ function dat_load()
if [[ ${loaded_cnt} -ge ${max_idx} ]] if [[ ${loaded_cnt} -ge ${max_idx} ]]
then then
echo "max rom id reached: skipping loading !" echo "max rom id reached: skipping loading !" 1>&2
break; break;
fi fi
fi fi
done < ${NDS_DAT} ;;
esac
fi
done < ${NDS_XML}
} }
@ -297,7 +448,7 @@ function print_verbose()
if [[ "${verbose}" == "yes" ]] if [[ "${verbose}" == "yes" ]]
then then
echo "${text}" echo "${text}" 1>&2
fi fi
} }
@ -481,7 +632,7 @@ function arc_build()
print_verbose "zipping ${rom} into ${file_name}" print_verbose "zipping ${rom} into ${file_name}"
zip -m9 "${NDS_ROMS_OUT}/${file_name}" "${rom}" >/dev/null 2>&1 zip -m9 "${NDS_ROMS_OUT}/${file_name}" "${rom}" >/dev/null 1>&2
else else
print_verbose "removing ${rom}" print_verbose "removing ${rom}"
@ -578,7 +729,7 @@ function rom_extract()
;; ;;
(*) (*)
echo "rom_extract internal error [$1] !"; echo "rom_extract internal error [$1] !" 1>&2
exit 1 exit 1
;; ;;
esac esac
@ -593,7 +744,7 @@ function rom_extract()
function tmp_mv() function tmp_mv()
{ {
echo "removing .tmp suffix..." echo "removing .tmp suffix..." 1>&2
IFS=' ' IFS=' '
mv_cnt=0 mv_cnt=0
@ -672,7 +823,7 @@ function arc_proceed()
if [[ ${idx} -gt ${loaded_cnt} ]] if [[ ${idx} -gt ${loaded_cnt} ]]
then then
echo "max rom id reached: skipping processing !" echo "max rom id reached: skipping processing !" 1>&2
break; break;
fi fi
@ -830,7 +981,7 @@ function arc_mng()
# Initialize Job Control # Initialize Job Control
job_init job_init
echo "processing rom repository..." echo "processing rom repository..." 1>&2
IFS=' ' IFS=' '
found_cnt=0 found_cnt=0
@ -858,14 +1009,7 @@ function arc_mng()
# Update stats # Update stats
found_cnt=$((${found_cnt} + 1)) found_cnt=$((${found_cnt} + 1))
printf "found: %4d" ${found_cnt} count_print ${found_cnt}
if [[ "${verbose}" == "yes" ]]
then
echo
else
printf "\r"
fi
done < ${tmp_file} done < ${tmp_file}
@ -893,7 +1037,7 @@ function arc_mng()
function suffix_mng() function suffix_mng()
{ {
echo "managing duplicate archives..." echo "managing duplicate archives..." 1>&2
IFS=' ' IFS=' '
found_cnt=0 found_cnt=0
@ -954,14 +1098,8 @@ function suffix_mng()
fi fi
found_cnt=$((${found_cnt} + 1)) found_cnt=$((${found_cnt} + 1))
printf "found: %4d" ${found_cnt}
if [[ "${verbose}" == "yes" ]] count_print ${found_cnt}
then
echo
else
printf "\r"
fi
done < ${tmp_file} done < ${tmp_file}
\rm -f ${tmp_file} \rm -f ${tmp_file}
@ -1016,7 +1154,7 @@ function stats_update()
;; ;;
*) *)
echo "stats_update internal error [$1] !"; echo "stats_update internal error [$1] !" 1>&2
exit 1 exit 1
;; ;;
esac esac
@ -1079,25 +1217,25 @@ function stats_proceed()
function stats_print() function stats_print()
{ {
echo " " echo " " 1>&2
echo 1>&2
printf "%4d roms set to OK\n" ${ss_ok_cnt} 1>&2
printf "%4d roms changed to OK\n" ${cs_ok_cnt} 1>&2
printf "%4d roms kept to OK\n" ${ks_ok_cnt} 1>&2
printf "%4d roms are OK\n" ${ok_cnt} 1>&2
echo echo
printf "%4d roms set to OK\n" ${ss_ok_cnt} printf "%4d roms set to KO\n" ${ss_ko_cnt} 1>&2
printf "%4d roms changed to OK\n" ${cs_ok_cnt} printf "%4d roms changed to KO\n" ${cs_ko_cnt} 1>&2
printf "%4d roms kept to OK\n" ${ks_ok_cnt} printf "%4d roms kept to KO\n" ${ks_ko_cnt} 1>&2
printf "%4d roms are OK\n" ${ok_cnt} printf "%4d roms are KO\n" ${ko_cnt} 1>&2
echo echo
printf "%4d roms set to KO\n" ${ss_ko_cnt} printf "%4d roms are in dsrom.dat\n" ${loaded_cnt} 1>&2
printf "%4d roms changed to KO\n" ${cs_ko_cnt} printf "%4d roms are found\n" ${found_cnt} 1>&2
printf "%4d roms kept to KO\n" ${ks_ko_cnt} printf "%4d roms are ignored\n" ${ignored_cnt} 1>&2
printf "%4d roms are KO\n" ${ko_cnt} printf "%4d roms are proceeded\n" ${proceeded_cnt} 1>&2
echo printf "%4d roms are renumbered\n" ${renum_cnt} 1>&2
printf "%4d roms are in dsrom.dat\n" ${loaded_cnt} printf "%4d roms are duplicated\n" ${dup_cnt} 1>&2
printf "%4d roms are found\n" ${found_cnt} printf "%4d roms are missing\n" ${missing_cnt} 1>&2
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}
} }
@ -1108,8 +1246,10 @@ function stats_print()
function dsrom_mode() function dsrom_mode()
{ {
echo "scanning rom repository..." echo "scanning rom repository..." 1>&2
IFS=' ' IFS=' '
found_cnt=0
tmp_file=$(mktemp) tmp_file=$(mktemp)
@ -1144,6 +1284,10 @@ function dsrom_mode()
dat_fp[${idx}]=${fp} dat_fp[${idx}]=${fp}
dat_status[${idx}]=${status} dat_status[${idx}]=${status}
fi fi
found_cnt=$((${found_cnt} + 1))
count_print ${found_cnt}
done < ${tmp_file} done < ${tmp_file}
\rm -f ${tmp_file} \rm -f ${tmp_file}
@ -1242,7 +1386,7 @@ fi
if [[ ! -f ${NDS_DAT} ]] if [[ ! -f ${NDS_DAT} ]]
then then
echo "error: dsrom.dat not found !" echo "error: dsrom.dat not found !" 1>&2
exit 1 exit 1
fi fi
@ -1250,7 +1394,8 @@ fi
#----------------------------------------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------------------------------------
dat_load #dat_load
xml_load