From 43dc7297d4c4b48b1dbcd1cd30620ee7ec020a43 Mon Sep 17 00:00:00 2001 From: agibert Date: Mon, 30 Mar 2009 22:57:13 +0000 Subject: [PATCH] - Add .xml file loading support, - Remove obsolete .dat file loading support, - Now nds2rm is independant and nds-gen useless ! - Redirect processing messages to stderr. --- nds2rm | 305 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 225 insertions(+), 80 deletions(-) diff --git a/nds2rm b/nds2rm index defdcf6..465a419 100644 --- a/nds2rm +++ b/nds2rm @@ -5,9 +5,9 @@ # (C) 2009 Arnaud G. Gibert #----------------------------------------------------------------------------------------------------------------------------------- # $RCSfile: nds2rm,v $ -# $Revision: 1.8 $ +# $Revision: 1.9 $ # $Name: $ -# $Date: 2009/03/29 23:46:42 $ +# $Date: 2009/03/30 22:57:13 $ # $Author: agibert $ #----------------------------------------------------------------------------------------------------------------------------------- @@ -31,6 +31,9 @@ +# User Config +#----------------------------------------------------------------------------------------------------------------------------------- + #NDS_REPOSITORY_IN=/opt/public/nds NDS_REPOSITORY_IN=/opt/public/nds.new #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_ROMS_IN=${NDS_REPOSITORY_IN}/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" @@ -51,6 +60,56 @@ NDS_VERSION="$Name: $" 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,54 +198,146 @@ function args_parse() -# Load Dat File +# Print Counter #----------------------------------------------------------------------------------------------------------------------------------- -function dat_load() +function count_print { - echo "loading dsrom.dat..." + idx=${1} + + + printf "%4d" ${idx} 1>&2 + + if [[ "${verbose}" == "yes" ]] + then + echo 1>&2 + else + 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 + + lang="${lang}${lang_tab[${bit}]}" + fi + + i=$(( ${i} + 1 )) + done + + echo "${lang}" +} + + + + + +# Load XML File +#----------------------------------------------------------------------------------------------------------------------------------- + +function xml_load() +{ + echo "loading dsrom.xml..." 1>&2 loaded_cnt=0 - IFS=';' + IFS='>' while read line do - set ${line} - - idx=${2/*(0)/} - - if [[ "${idx}" != "xxxx" ]] + if [[ "${line}" != "" ]] then - echo -ne "$2" + set ${line} - if [[ "${verbose}" == "yes" ]] - then - echo - else - printf "\r" - fi + tag=${1/*} + ;; - loaded_cnt=$((${loaded_cnt} + 1)) + ("saveType") + save_type=${value} + ;; - if [[ ${loaded_cnt} -ge ${max_idx} ]] - then - echo "max rom id reached: skipping loading !" - break; - fi + ("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_status[${idx}]="?" + dat_dup[${idx}]="0" + + loaded_cnt=$((${loaded_cnt} + 1)) + + if [[ ${loaded_cnt} -ge ${max_idx} ]] + then + echo "max rom id reached: skipping loading !" 1>&2 + break; + fi + fi + ;; + esac fi - done < ${NDS_DAT} + done < ${NDS_XML} } @@ -297,7 +448,7 @@ function print_verbose() if [[ "${verbose}" == "yes" ]] then - echo "${text}" + echo "${text}" 1>&2 fi } @@ -481,7 +632,7 @@ function arc_build() 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 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 ;; esac @@ -593,7 +744,7 @@ function rom_extract() function tmp_mv() { - echo "removing .tmp suffix..." + echo "removing .tmp suffix..." 1>&2 IFS=' ' mv_cnt=0 @@ -672,7 +823,7 @@ function arc_proceed() if [[ ${idx} -gt ${loaded_cnt} ]] then - echo "max rom id reached: skipping processing !" + echo "max rom id reached: skipping processing !" 1>&2 break; fi @@ -830,7 +981,7 @@ function arc_mng() # Initialize Job Control job_init - echo "processing rom repository..." + echo "processing rom repository..." 1>&2 IFS=' ' found_cnt=0 @@ -858,14 +1009,7 @@ function arc_mng() # Update stats found_cnt=$((${found_cnt} + 1)) - printf "found: %4d" ${found_cnt} - - if [[ "${verbose}" == "yes" ]] - then - echo - else - printf "\r" - fi + count_print ${found_cnt} done < ${tmp_file} @@ -893,7 +1037,7 @@ function arc_mng() function suffix_mng() { - echo "managing duplicate archives..." + echo "managing duplicate archives..." 1>&2 IFS=' ' found_cnt=0 @@ -954,14 +1098,8 @@ function suffix_mng() fi found_cnt=$((${found_cnt} + 1)) - printf "found: %4d" ${found_cnt} - if [[ "${verbose}" == "yes" ]] - then - echo - else - printf "\r" - fi + count_print ${found_cnt} done < ${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 ;; esac @@ -1079,25 +1217,25 @@ function stats_proceed() 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 - printf "%4d roms set to OK\n" ${ss_ok_cnt} - printf "%4d roms changed to OK\n" ${cs_ok_cnt} - printf "%4d roms kept to OK\n" ${ks_ok_cnt} - printf "%4d roms are OK\n" ${ok_cnt} + printf "%4d roms set to KO\n" ${ss_ko_cnt} 1>&2 + printf "%4d roms changed to KO\n" ${cs_ko_cnt} 1>&2 + printf "%4d roms kept to KO\n" ${ks_ko_cnt} 1>&2 + printf "%4d roms are KO\n" ${ko_cnt} 1>&2 echo - printf "%4d roms set to KO\n" ${ss_ko_cnt} - printf "%4d roms changed to KO\n" ${cs_ko_cnt} - printf "%4d roms kept to KO\n" ${ks_ko_cnt} - printf "%4d roms are KO\n" ${ko_cnt} - 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} + printf "%4d roms are in dsrom.dat\n" ${loaded_cnt} 1>&2 + printf "%4d roms are found\n" ${found_cnt} 1>&2 + printf "%4d roms are ignored\n" ${ignored_cnt} 1>&2 + printf "%4d roms are proceeded\n" ${proceeded_cnt} 1>&2 + printf "%4d roms are renumbered\n" ${renum_cnt} 1>&2 + printf "%4d roms are duplicated\n" ${dup_cnt} 1>&2 + printf "%4d roms are missing\n" ${missing_cnt} 1>&2 } @@ -1108,8 +1246,10 @@ function stats_print() function dsrom_mode() { - echo "scanning rom repository..." - IFS=' ' + echo "scanning rom repository..." 1>&2 + + IFS=' ' + found_cnt=0 tmp_file=$(mktemp) @@ -1144,6 +1284,10 @@ function dsrom_mode() dat_fp[${idx}]=${fp} dat_status[${idx}]=${status} fi + + found_cnt=$((${found_cnt} + 1)) + + count_print ${found_cnt} done < ${tmp_file} \rm -f ${tmp_file} @@ -1242,7 +1386,7 @@ fi if [[ ! -f ${NDS_DAT} ]] then - echo "error: dsrom.dat not found !" + echo "error: dsrom.dat not found !" 1>&2 exit 1 fi @@ -1250,7 +1394,8 @@ fi #----------------------------------------------------------------------------------------------------------------------------------- -dat_load +#dat_load +xml_load