[EmuElec]根据游戏名查询gamelist中的配置信息

 通过关键字查询游戏的配置,方便从其他gamelist中提取配置,以定制gamelist.xml

#!/bin/bash
## filename: queryGame.sh
## 使用: ./queryGame.sh <gamelist.xml搜索目录> <游戏名>
## 功能:在目录下搜索gamelist.xml,并查找对应游戏的配置信息
## 举例:./queryGame.sh "/Volumes/EEROMS"  超级玛丽
## 注意:需要安装xmlstarlet

function pickgamelist(){
    gamelistxml="${1:-gamelist.xml}"
    game=$2

    gamelistdir="$( cd "$(dirname "${gamelistxml}")" && pwd )"
    gamelistpath="${gamelistdir}/gamelist.xml"

    echo "处理文件:""${gamelistpath}"
    # 修改编码为utf-8,以支持中文, macos请使用gsed,安装方法:brew install gsed
    gsed -i '1c <?xml version="1.0" encoding="utf-8"?>' "${gamelistxml}"
    gameList=`xmlstarlet sel -t \
    -v "/gameList/game[contains(name, \"${game}\")]/name" \
    --nl "${gamelistxml}"`

    OLDIFS="$IFS"  #备份旧的IFS变量
    IFS=$'\n' #处理游戏名中带空格的情况
    # 逐个修改name的值
    for game in ${gameList}
    do
        echo "处理游戏:"${game}
        gameconfig=$( xmlstarlet sel -t \
                -c "/gameList/game[name = \"${game}\"]" \
                --nl \
                "${gamelistxml}" )
	_path=$( echo $gameconfig | xmlstarlet sel -t \
	       	-v "//path" \
	       	--nl )
	gpath=${gamelistdir}/$_path
	_image=$( echo $gameconfig | xmlstarlet sel -t \
	       	-v "//image" \
	       	--nl )
	gimage=${gamelistdir}/$_image
        echo $gameconfig | xml fo -o -s 4 #缩进
        echo cp \"$gpath\"  ${_path%/*}
        echo cp \"$gimage\" ${_image%/*}
    done
    IFS="$OLDIFS"  #还原IFS变量
}


searchdir=$1 # 搜索目标目录
searchgame=$2 # 游戏名
for f in $( find "${searchdir}" -type f -name "gamelist.xml")
do
    pickgamelist $f ${searchgame}
done

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值