Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4737380
  • 博文数量: 206
  • 博客积分: 5240
  • 博客等级: 大校
  • 技术积分: 3224
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-12 21:40
文章分类

全部博文(206)

文章存档

2013年(13)

2012年(8)

2011年(33)

2010年(152)

我的朋友

分类:

2010-09-09 17:48:41

当需要向快手项目中添加大量资源文件时,使用此工具可以方便你的操作.

//资源文件批量添加工具
//通过修改快手项目文件向项目中批量添加资源
import win.ui;
import fsys;
import fsys.dlg;
/*DSG{{*/
var winform = win.form(parent=...; min=1;bottom=206;right=473;text="快手项目资源文件批量添加工具" )
winform.add(
static2={ text="1、手动把所有需要添加到项目中的资源文件拷贝到项目文件夹的res子文件夹下;
2、使用本工具浏览打开要处理的项目文件,按“添加资源”按钮
注意:使用前关闭任何操作项目文件的应用程序。原项目文件会自动备份。"
;bottom=172;right=434;left=36;top=120;font=LOGFONT( name="SimSun";h=-12 );transparent=1;z=5;cls="static" };
static={ text="项目文件:";bottom=55;right=112;left=15;top=31;font=LOGFONT( name="SimSun";h=-12 );z=0;transparent=1;cls="static" };
btnMake={ disabled=1;bottom=87;right=284;left=194;top=61;font=LOGFONT( name="SimSun";h=-12 );z=3;text="添加资源";cls="button" };
txtProjectFile={ bottom=48;text="";left=88;top=26;font=LOGFONT( name="SimSun";h=-12 );z=1;right=385;readonly=1;edge=1;cls="edit" };
groupbox={ bottom=196;right=456;left=18;top=89;font=LOGFONT( name="SimSun";h=-12 );z=4;text="使用说明";edge=1;cls="groupbox" };
btnBrowse={ bottom=47;right=465;left=392;top=23;font=LOGFONT( name="SimSun";h=-12 );z=2;text="浏览...";cls="button" }
)
/*}}*/

winform.btnMake.oncommand = function(id,event){
    var resRoot = ""; //资源根文件夹
    var t = {}; //用于存储文件夹结构的栈
    var prjFile = winform.txtProjectFile.text; //项目文件的文件名
    
    resRoot = string.sub(prjFile,1,string.lastIndexAny(prjFile,"\")) + "res";
    table.push(t,resRoot);

    var getPathDepth = function(dir){/*获得文件夹路径层次深度*/
        if(!string.endWith(dir,"
\")){
            dir =dir + "
\";
        }
        return #string.replace(dir,"
[^\\]","") -1;
    }
    
    var s = "
";
    s+='<目录 name="
资源文件" path="res">\n';
    
    fsys.enum(resRoot,"
*.*",
        function(dir,filename){
            var parent = table.pop(t);
            table.push(t,parent);
        
            if(filename){//是文件
                s+='<文件 name="
' + filename + '" path="res' + string.replace(dir,"@" + resRoot,"") + filename + '">\n';
            }
            else{//是文件夹
                var depthDir = getPathDepth(dir);
                var depthParent = getPathDepth(parent);
                if(depthDir>depthParent){ //栈顶文件夹的子文件夹
                    parent = dir;
                    table.push(t,dir);
                }
                elseif(depthDir==depthParent){//栈顶文件夹的同级文件夹
                    table.pop(t);
                    parent = dir;
                    table.push(t,dir);
                    s+='\n';
                }
                else{//栈顶文件夹已全部处理完,返回到某个上级文件夹
                    for(i=1;depthParent-depthDir+1;1){
                        table.pop(t);
                        s+='\n';
                    }
                    parent = dir;
                    table.push(t,dir);
                }
                var dirName = string.sub(dir,string.lastIndexAny(dir,"
\")+1);
                s+='<目录 name="
' + dirName + '" path="' + dir + '">\n';
            }
        }
    );
    for(i=1;#t;1){
        s+='\n';
    }
    s = string.replace(s,"
(\\)","\1\1");
    var content = string.load(prjFile);
    string.save(prjFile + "
.bak",content);
    content = string.replace(content,"
\<目录 name=""资源文件"" path=""res""\>.*\<目录 name="""" path=""lib""\>",s + '<目录 name="" path="lib">');
    string.save(prjFile,content);
    win.msgbox("
向项目文件中批量添加资源完毕!","提示");
    
}//endproc

winform.btnBrowse.oncommand = function(id,event){
    var file = fsys.dlg.open("
AAuto项目文件|*.aproj||","打开项目文件");
    if(file){
        winform.txtProjectFile.text = file;
    }
    winform.btnMake.disabled = !(winform.txtProjectFile.text=="




解释

当需要向快手项目中添加大量资源文件时,使用此工具可以方便你的操作.

//资源文件批量添加工具
//通过修改快手项目文件向项目中批量添加资源
//第一步 创建windows窗口文件,然后导入相关库,用分号结束
import
 win.ui; 
import
 fsys;
import
 fsys.dlg;
/*DSG{{*/

var winform = win.form(parent=...; min=1;bottom=206;right=473;text="快手项目资源文件批量添加工具" )// 定义 wniform窗口变量
winform.add( 
static2={ text=
"1、手动把所有需要添加到项目中的资源文件拷贝到项目文件夹的res子文件夹下;
2、使用本工具浏览打开要处理的项目文件,按“添加资源”按钮
注意:使用前关闭任何操作项目文件的应用程序。原项目文件会自动备份。"
;bottom=172;right=434;left=36;top=120;font=LOGFONT( name="SimSun";h=-12 );transparent=1;z=5;cls="static"
 };//winform窗口添加static2控件命名SimSun
static={ text=
"项目文件:";bottom=55;right=112;left=15;top=31;font=LOGFONT( name="SimSun";h=-12 );z=0;transparent=1;cls="static"
 };//winform窗口添加static控件
btnMake={ disabled=1;bottom=87;right=284;left=194;top=61;font=LOGFONT( name=
"SimSun";h=-12 );z=3;text="添加资源";cls="button"
 };
txtProjectFile={ bottom=48;text=
"";left=88;top=26;font=LOGFONT( name="SimSun";h=-12 );z=1;right=385;readonly=1;edge=1;cls="edit"
 };
groupbox={ bottom=196;right=456;left=18;top=89;font=LOGFONT( name=
"SimSun";h=-12 );z=4;text="使用说明";edge=1;cls="groupbox"
 };//winform窗口添加groupbox组件控件
btnBrowse={ bottom=47;right=465;left=392;top=23;font=LOGFONT( name=
"SimSun";h=-12 );z=2;text="浏览...";cls="button"
 }
)
/*}}*/


//定义添加资源控件(btnMake)执行语句
winform.btnMake.oncommand = 
function(id,event){
    
var resRoot = "";  
//资源根文件夹
    var t = {};  
//用于存储文件夹结构的栈
    var prjFile = winform.txtProjectFile.text;  
//项目文件的文件名
    
    resRoot = string.sub(prjFile,1,string.lastIndexAny(prjFile,
"\")) + "res"
;
    table.push(t,resRoot);

    
var getPathDepth = function(dir){/*获得文件夹路径层次深度*/

        
if(!string.endWith(dir,"\")){
            dir =dir + 
"\"
;
        }
        
return #string.replace(dir,"[^\\]",""
) -1;
    }
    
    
var s = ""
;
    s+=
'<目录 name="资源文件" path="res">\n'
;
    
    fsys.enum(resRoot,
"*.*"

        
function
(dir,filename){ 
            
var
 parent = table.pop(t);
            table.push(t,parent);
        
            
if(filename){
//是文件
                s+='<文件 name="' + filename + '" path="res' + string.replace(dir,"@" + resRoot,"") + filename +'">\n'
;
            }
            
else{
//是文件夹
                var
 depthDir = getPathDepth(dir);
                
var
 depthParent = getPathDepth(parent);
                
if(depthDir>depthParent){ 
//栈顶文件夹的子文件夹
                    parent = dir;
                    table.push(t,dir);
                }
                
elseif(depthDir==depthParent){
//栈顶文件夹的同级文件夹
                    table.pop(t);
                    parent = dir;
                    table.push(t,dir);
                    s+=
'\n'
;
                }
                
else{
//栈顶文件夹已全部处理完,返回到某个上级文件夹
                    for
(i=1;depthParent-depthDir+1;1){
                        table.pop(t);
                        s+=
'\n'
;
                    }
                    parent = dir;
                    table.push(t,dir);
                }
                
var dirName = string.sub(dir,string.lastIndexAny(dir,"\"
)+1);
                s+=
'<目录 name="' + dirName + '" path="' + dir + '">\n'
;
            }
        } 
    );
    
for
(i=1;#t;1){
        s+=
'\n'
;
    }
    s = string.replace(s,
"(\\)","\1\1"
);
    
var
 content = string.load(prjFile);
    string.save(prjFile + 
".bak"
,content);
    content = string.replace(content,
"\<目录 name=""资源文件"" path=""res""\>.*\<目录 name=""库"" path=""lib""\>",s + '<目录 name="库" path="lib">'
);
    string.save(prjFile,content);
    win.msgbox(
"向项目文件中批量添加资源完毕!","提示"
);
    
}
//endproc

winform.btnBrowse.oncommand = 
function(id,event){
    
var file = fsys.dlg.open("AAuto项目文件|*.aproj||","打开项目文件"
);
    
if
(file){
        winform.txtProjectFile.text = file;
    }
    winform.btnMake.disabled = !(winform.txtProjectFile.text==
""
);
}
//endproc

winform.show(
true
win.loopMessage();
return
 winform;
最后编辑roking 最后编辑于 2010-09-09 09:25:54

阅读(2696) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~