godking.http + godking.vlistEx 实现批量进度下载+续传+失败重试

光庆 3月前 408

如果不能正常运行,请下载最新版本 vlistEx 和 http 库。

下载地址:光庆·程序·在线

import win.ui;
import godking.vlistEx;
import thread.works
/*DSG{{*/
var mainForm = win.form(text="aardio form";right=1031;bottom=469)
mainForm.add(
vlist={cls="vlistEx";left=10;top=10;right=1024;bottom=464;db=1;dl=1;dr=1;dt=1;edge=1;transparent=1;z=1}
)
/*}}*/

var t = { fields={"序号","url","保存文件","下载进度"} };
for(i=1;50;1){
    ..table.push(t,{"序号"="[@rowindex]"});
}

mainForm.vlist.setTable(t,/*列标题*/,{40,280,380,100}/*列宽*/,1/*对齐方式*/,/*字典转为数组*/,/*字符串转为Utf8*/,/*是否克隆新表*/)
mainForm.vlist.fillParent();
..io.createDir("\down");

import thread.command
thread.command.instance().r = function(row,v,url,file){
    if #url mainForm.vlist.setCellText(row,2,url);
    if #file mainForm.vlist.setCellText(row,3,file);
    mainForm.vlist.setCellText(row,4,v);
}

var work = thread.works(5,
    function(param) {
        import godking.http
        import thread.command
        thread.command.post("r",param.index,"开始",param.url)
        var callback = function(id,v,all,url,file){
            thread.command.post("r",id,..math.round(v*100/all,2)++"%",url,file)
        }
        var t,n={},0;
        do{ // 下载失败重试,共3次后结束。
            n++;
            if n>3 break;
             t = godking.http({
                url = param.url; 
                callback = callback; 
                callbackID = param.index;
                file = "\down\aardio_"+param.index+".7z"; 
                fileResume = true; 
            })
        } while ( !t.success )
        if ( t.success ) {
            thread.command.post("r",param.index,"下载完毕",param.url,t.file);
        } else {
            thread.command.post("r",param.index,"下载失败"++(t.info:"")++..math.round(t.downsize*100/t.allsize,2)++"%",param.url,t.file);
        }
        return true;
    } 
);

mainForm.show();

mainForm.onClose = function(hwnd,message,wParam,lParam){
    import process
    process().terminate();
} 

mainForm.vlist.autoRedraw = false;
mainForm.setInterval( 
    function(){
        mainForm.vlist.redraw(true)
    },200
)

for(i=1;50;1){
    work.push({index=i,url="https://d.aardio.com/ide/aardio.7z"});
}

win.loopMessage();


最新回复 (1)
  • Viewer8122 3月前
    0 2
    沙发!~@
返回