cocos2dxlua一键资源管理PowerShell脚本实现

您所在的位置:网站首页 lua脚本资源网 cocos2dxlua一键资源管理PowerShell脚本实现

cocos2dxlua一键资源管理PowerShell脚本实现

2023-03-17 09:22| 来源: 网络整理| 查看: 265

特别说明 此管理脚本不包含图片资源加密,热更新资源文件列表是md5 和 文件路径构成的txt,如下

脚本文件是放在和res src 同级的文件夹里面

脚本内容如下

clear $PSDefaultParameterValues['Out-File:Encoding'] = 'utf8' $StartTime = Get-Date $CurrentPath = (Get-Location).Path + "\d" $CurrentPath Write-Host "start please wait !" ### step 1 删除目标资源生成目录 if (Test-Path -Path ./d/src ) { Remove-Item -Path ./d/src -Recurse } ### step2 加密lua文件并放到目标目录 cocos luacompile -s ..\src -d .\d\src -e -k GD432LXCVLXXXXXX -b mahjongxxxxxxxxx --disable-compile #3打印完成提示 Write-Host "compile and move src finish" ### step 3 移动资源文件 if (Test-Path -Path ./d/res ) { Remove-Item -Path ./d/res -Recurse } Copy-Item -Path ..\res -Destination .\d -Recurse -Force Write-Host "move res file finish" ### step 4 生成MD5文件 if (Test-Path -Path ./d/newUpdateResList1.txt ) { Remove-Item -Path ./d/newUpdateResList1.txt -Force } Get-ChildItem -Path ./d -Recurse | Get-FileHash -Algorithm MD5 | ForEach-Object{ $_.Hash + " "+ (($_.Path -replace ".*\\d\\","\") -replace "\\","/") >> ./d/newUpdateResList1.txt } Write-Host "make md5 finish" #把utf-8-bom 格式的md5文件转换成 utf-8 $Path = (Get-Location).Path+"\d\newUpdateResList1.txt" $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding($False) $MyFile = Get-Content -Path .\d\newUpdateResList1.txt [System.IO.File]::WriteAllLines($Path, $MyFile, $Utf8NoBomEncoding) ### step 5 导出差异文件 if ( Test-Path -Path .\newUpdateResList1.txt ) { $fileCounts = Get-Content -Path .\d\newUpdateResList1.txt Write-Host ("new md5 file total line " + $fileCounts.Count) $NewHashFiles = @{} for( $idx = 0 ; $idx -lt $fileCounts.Count ; $idx++ ) { $line = $fileCounts[$idx] -split " " $NewHashFiles[$line[1]] = $line[0] } Write-Host ("after hash mapping total line " + $NewHashFiles.Count) $fileCounts = Get-Content -Path .\newUpdateResList1.txt Write-Host ("old md5 file total line " + $fileCounts.Count) $OldHashFiles = @{} for( $idx = 0 ; $idx -lt $fileCounts.Count ; $idx++ ) { $line = $fileCounts[$idx] -split " " $OldHashFiles[$line[1]] = $line[0] } Write-Host ("after hash mapping total line " + $OldHashFiles.Count) $dirrentHash = @{} foreach($key in $NewHashFiles.Keys) { if ( $OldHashFiles.ContainsKey($key) ) { if ( $OldHashFiles[$key] -ne $NewHashFiles[$key] ) { $dirrentHash[$key] = $NewHashFiles[$key] } } else { $dirrentHash[$key] = $NewHashFiles[$key] } } if ( Test-Path -Path .\c ) { Remove-Item -Path .\c -Recurse -Force } $noOutPut = New-Item -ItemType directory ./c -Force Write-Host "" $dirPath = (Get-Location).ToString() + "\d" -replace "\\","/" foreach($key in $dirrentHash.Keys) { $sourcePath = $dirPath+$key $targetPath = ".\c"+$key $sourcePath $pathParent = Split-Path $targetPath -Parent if( -not (Test-Path -Path $pathParent) ) { $noOutPut = New-Item -ItemType directory $pathParent -Force } Copy-Item -Path $sourcePath -Destination $targetPath -Force } Write-Host "" Copy-Item -Path .\d\newUpdateResList1.txt -Destination .\c -Force } Write-Host ("total spend time "+ (((Get-Date) - $StartTime).TotalSeconds).ToString() +"s") pause

其它格式的热更新资源列表文件 改改应该也可以用,PowerShell还没入门,写的不好的地方请见谅。

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3