关闭

批处理调用VBS脚本,一键打包时修改app名称

标签: android批处理
511人阅读 评论(0) 收藏 举报
分类:

1、现在有这么个需求,打包的app名称也可以配置,那就需要替换strings里面的"<string name="app_name">数字化实习实训系统 </string>"这个属性。

2、研究了半天发现批处理只支持ANSI 和 Unicode两种类型字符,批处理修改替换xml中的字符后其他的中文字符也变成了乱码。

3、没办法了,既然批处理对中文的支持有限,那就只能另辟蹊径了。

4利用vbs修改xml里面的数据,发现没问题。

5批处理调用vbs脚本时将中文字符传过去,发现传不过去,传英文就好使。

6然后就将要修改的app名称存入临时txt文件(ANSI格式),在vbs中读取txt中的名称,然后将临时txt删掉。

7vbs读取ANSI格式的中文字符时还是乱码,崩溃中~~~~。

8偶然看到一篇文章,windows中的ANSI在简体中文版windows时是Big5模式。就用big5模式读取txt字符串,发现还是不好使。

9那就试试gbk、gb2312好不好使,GBK好使,泪奔中。

10将这个功能加入到原来的批处理中,中间有个知识点:用call ChangAppName.vbs命令调用vbs脚本。意思为当vbs脚本执行完成后继续执行批处理接下来的内容。

11、贴出完整的一键打包批处理代码及vbs脚本代码供大家参考:
批处理:

@echo off
REM 此文件要放到与HomeWorkForBuild同级目录下
set sp=%cd%\HomeWorkForBuild
set cf=systemCommon.txt
set cf2=qinhanCommon.txt
set st=WWWWWWWWWW
REM dt:要更换的地址    http://192.168.200.1/、http://221.212.251.230:807/、http://192.168.0.2:806/
set dt=http://221.212.251.230:807/
REM 生成保存appname的临时文件
set filename=AppName.txt
REM dt:生成app的名称,如果改变则填入名称,如果不改变则为空
set appname=屁屁啊屁屁

xcopy /y /e /h %cd%\HomeWork\* %cd%\HomeWorkForBuild
if exist %cd%\HomeWorkForBuild\systemCommon.txt (
 goto changeSystemCommon
) else (
 copy %cd%\HomeWorkForBuild\src\com\system\HomeWork\common\common.java  %cd%\HomeWorkForBuild\systemCommon.txt /y
 goto changeSystemCommon
)

:changeSystemCommon
setlocal enabledelayedexpansion
pushd %1
for /f "tokens=1-4* delims=:" %%i in ('findstr /n ".*" %sp%\%cf%') do (
set txt=%%j%%k%%l
if "!txt!" == "" (
 echo .>>%1root.tmp
) else (
echo !txt:%st%=%dt%!>>%1root.tmp
)
)
move /y root.tmp %sp%\src\com\system\HomeWork\common\common.java
echo =================华丽的分割线=================
goto moveImage

:moveImage
if exist %cd%\ReplaceImage\drawable-hdpi\ic_launcher.png (
 move /y %cd%\ReplaceImage\drawable-hdpi\ic_launcher.png C:\SOFT\adt-bundle-windows-x86-20140624\HomeWorkForBuild\res\drawable-hdpi
)
if exist %cd%\ReplaceImage\drawable-hdpi\loading_act.png (
 move /y %cd%\ReplaceImage\drawable-hdpi\loading_act.png C:\SOFT\adt-bundle-windows-x86-20140624\HomeWorkForBuild\res\drawable-hdpi
)
if exist %cd%\ReplaceImage\drawable-ldpi\ic_launcher.png (
 move /y  %cd%\ReplaceImage\drawable-ldpi\ic_launcher.png C:\SOFT\adt-bundle-windows-x86-20140624\HomeWorkForBuild\res\drawable-ldpi
)
if exist %cd%\ReplaceImage\drawable-mdpi\ic_launcher.png (
 move /y  %cd%\ReplaceImage\drawable-mdpi\ic_launcher.png C:\SOFT\adt-bundle-windows-x86-20140624\HomeWorkForBuild\res\drawable-mdpi
)
if exist %cd%\ReplaceImage\drawable-xhdpi\ic_launcher.png (
 move /y  %cd%\ReplaceImage\drawable-xhdpi\ic_launcher.png C:\SOFT\adt-bundle-windows-x86-20140624\HomeWorkForBuild\res\drawable-xhdpi
)
if exist %cd%\ReplaceImage\drawable-xxhdpi\ic_launcher.png (
 move /y  %cd%\ReplaceImage\drawable-xxhdpi\ic_launcher.png C:\SOFT\adt-bundle-windows-x86-20140624\HomeWorkForBuild\res\drawable-xxhdpi
)
goto changeAppname

:changeAppname
if "%appname%" NEQ "" (
 echo %appname%>>%filename% 
 call ChangeAppName.vbs
)
goto build

:build
cd HomeWorkForBuild
ant
@pause

vbs脚本:

Call Main 
Sub Main()
	appname = LoadGBK("AppName.txt")
	
	set fso=createobject("scripting.filesystemobject")
	fso.deleteFile "AppName.txt"
	
	allcontent = LoadUTF8("C:\SOFT\adt-bundle-windows-x86-20140624\HomeWorkForBuild\strings.xml")
	allcontent = Replace(allcontent, "AAAAAAAAAA", appname)
	msgbox(allcontent)
	Call WriteFileUTF8("C:\SOFT\adt-bundle-windows-x86-20140624\HomeWorkForBuild\res\values\strings.xml", allcontent) 
End Sub 
  
''''''''''''''''''''''''以下是函数定义'''''''''''''''''''''''''''''''''''''' 

' Valid Charset values for ADODB.Stream 
Const CdoBIG5        = "big5" 
Const CdoEUC_JP      = "euc-jp" 
Const CdoEUC_KR      = "euc-kr" 
Const CdoGB2312      = "gb2312" 
Const CdoISO_2022_JP = "iso-2022-jp" 
Const CdoISO_2022_KR = "iso-2022-kr" 
Const CdoISO_8859_1  = "iso-8859-1" 
Const CdoISO_8859_2  = "iso-8859-2" 
Const CdoISO_8859_3  = "iso-8859-3" 
Const CdoISO_8859_4  = "iso-8859-4" 
Const CdoISO_8859_5  = "iso-8859-5" 
Const CdoISO_8859_6  = "iso-8859-6" 
Const CdoISO_8859_7  = "iso-8859-7" 
Const CdoISO_8859_8  = "iso-8859-8" 
Const CdoISO_8859_9  = "iso-8859-9" 
Const cdoKOI8_R      = "koi8-r" 
Const cdoShift_JIS   = "shift-jis" 
Const CdoUS_ASCII    = "us-ascii" 
Const CdoUTF_7       = "utf-7" 
Const CdoUTF_8       = "utf-8" 
  
' ADODB.Stream file I/O constants 
Const adTypeBinary          = 1 
Const adTypeText            = 2 
Const adSaveCreateNotExist  = 1 
Const adSaveCreateOverWrite = 2 
 
Function WriteFileUTF8(FileName, str) 
    dim adodbStream 
    Set adodbStream = CreateObject("ADODB.Stream") 
    adodbStream.Type = adTypeText 
    adodbStream.Open 
    adodbStream.Charset = CdoUTF_8 
    adodbStream.WriteText(str) 
    adodbStream.SaveToFile FileName & flnm, 2 
    adodbStream.Close() 
    set adodbStream = nothing 
End Function 

Function LoadUTF8( FileName )
	Set stm = CreateObject("Adodb.Stream") 
	stm.Type = 2 
	stm.mode = 3 
	stm.charset = "utf-8" 
	stm.Open 
	stm.LoadFromFile FileName 
	LoadUTF8 = stm.readtext() 
	stm.close 
End Function

Function LoadGBK( FileName )
	Set stm = CreateObject("Adodb.Stream") 
	stm.Type = 2 
	stm.mode = 3 
	stm.charset = "gbk" 
	stm.Open 
	stm.LoadFromFile FileName 
	LoadGBK = stm.readtext() 
	stm.close 
End Function


 

 

 

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:149303次
    • 积分:2600
    • 等级:
    • 排名:第14582名
    • 原创:108篇
    • 转载:16篇
    • 译文:1篇
    • 评论:16条
    最新评论