home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 November / PCWorld_2007-11_cd.bin / temacd / imtoodownyoutube / download-youtube-video.exe / script / taskmanager.js < prev    next >
Text File  |  2007-09-11  |  24KB  |  977 lines

  1. var TaskManager = new Object;
  2.  
  3. TaskManager.MaxtTask = 3;
  4. TaskManager.RunningCount = 0;
  5. TaskManager.DownThreadUsing = new Array();
  6. TaskManager.TaskList = new Array();
  7. TaskManager.lastDownSize = 0;
  8. TaskManager.lastTimeStamp = 0;
  9.  
  10. ItemSatausFlag = 
  11. [
  12.     ["downloadling",        "is_downloading.png"],
  13.     ["converting",            "is_converting.png"],
  14.     ["finished",            "is_finished.png"],
  15.     ["waiting",                "is_waiting.png"],
  16.     ["download_paused",        "is_download_paused.png"],
  17.     ["convert_paused",        "is_convert_paused.png"],
  18.     ["download_failed",        "is_download_failed.png"],
  19.     ["convert_failed",        "is_convert_failed.png"],
  20.     ["stopped",                "is_stopped.png"],
  21.     ["convert_local_stopped","is_stopped.png"],
  22.     ["convert_net_stopped", "is_stopped.png"],
  23.     
  24.     
  25.     ["",                     ""]
  26.     
  27. ];
  28.  
  29. TaskManager.GetUnusing = GetUnusing;
  30. TaskManager.AddTask = AddTask;
  31. TaskManager.TaskSetItemStatus = TaskSetItemStatus;
  32. TaskManager.RunTask = RunTask;
  33.  
  34. for (var i=0; i<TaskManager.MaxtTask; i++)
  35. {   
  36.     TaskManager.DownThreadUsing[i] = 0;
  37. }
  38.  
  39. function GetUnusing()
  40. {
  41.     var count = 0;
  42.     for (var i=0; i<this.DownThreadUsing.length; i++)
  43.     {
  44.         if (this.DownThreadUsing[i] == 0)
  45.         {
  46.             return i;
  47.         }
  48.         count ++;
  49.     }
  50.     if(count < TaskManager.MaxtTask)
  51.     {
  52.         TaskManager.DownThreadUsing[count++] =  0;
  53.         //this.DownThreadUsing.length;
  54.         return count;
  55.     }
  56.     return -1;
  57. }
  58. function renamefile(filepath)
  59. {
  60.     var nEnd=filepath.lastIndexOf(".")-1;
  61.     return filepath.substring(0,nEnd);
  62.     
  63. }
  64.  
  65.  
  66. function AddTask(upodurl, upodfilesize, upodprogress, upodpath, proftype, profopt, isconvert, srcfile, targetfile, realurl, bjrename, flvtmppath)
  67. {
  68.     var nmax = MainWindow.listctrlfiles.GetItemCount();
  69.         
  70.     var task = new Object;
  71.     task.st = "waiting";
  72.     task.last_st = "waiting";
  73.     task.taskid = -1;
  74.     task.filesize = -1;
  75.     task.filename = "";
  76.     task.lastProgress = 0;
  77.     task.lastDownSize = 0;
  78.     task.lastTimeStamp = 0;
  79.     //             0            1         2               3             4           5         6        7            8        9           10       11        12    
  80.     task.info = [isconvert, upodurl, upodfilesize, upodprogress, upodpath, proftype, profopt, isconvert, srcfile, targetfile, realurl, bjrename, ""];
  81.     
  82.     
  83.     if (bjrename==1 && upodurl.length>0)
  84.         task.filename = upodurl;
  85.     
  86. //    ShowMessageBox(task.info);
  87.     
  88.     var item1 = ["", upodurl, upodfilesize, upodprogress, upodpath];
  89.     MainWindow.listctrlfiles.InsertItem(nmax,item1);
  90.     MainWindow.listctrlfiles.SetItemData(nmax, task);
  91.             
  92.     if (TaskManager.RunningCount<TaskManager.MaxtTask)
  93.     {
  94.         if (isconvert==0)
  95.         {
  96.             
  97.             ProcessDownload(nmax, task);
  98.         }
  99.         else
  100.         {
  101.               ProcessConvert(nmax, task);
  102.         }
  103.     }
  104.     else
  105.     {
  106.         TaskSetItemStatus(nmax, "waiting");
  107.     }
  108. }
  109.  
  110. function TaskManagerProcess()
  111. {
  112.     var b_need_update_ui_status = false;
  113.     var this_total_size = 0;
  114.     
  115.     with(MainWindow)
  116.     {
  117.         if (listctrlfiles.GetItemCount()==0)
  118.         {
  119.             return;
  120.         }
  121.         
  122.         for (var j=0; j<listctrlfiles.GetItemCount(); j++)
  123.         {
  124.             var task = listctrlfiles.GetItemData(j);
  125.             if (task==null)
  126.             {
  127.                 continue;
  128.             }
  129.             if(task.st=="downloadling")
  130.             {  
  131.                 if(utb_down_class.UTB_IsError(task.taskid)==1)
  132.                 {   
  133.                     NewTaskSetItemStatus(j, task, "download_failed");
  134.                     TaskManager.DownThreadUsing[task.taskid] = 0;
  135.                     utb_down_class.UTB_UnInit(task.taskid); 
  136.                     TaskManager.RunningCount--;
  137.                     b_need_update_ui_status = true;
  138.                     listctrlfiles.SetText(j,3,LanguageStr("_fail"));
  139.                 }
  140.           }
  141.         }
  142.     }
  143.     with (MainWindow)
  144.     {
  145.         if (listctrlfiles.GetItemCount()==0)
  146.         {
  147.             return;
  148.         }
  149.         
  150.         for (var i=0; i<listctrlfiles.GetItemCount(); i++)
  151.         {
  152.             var task = listctrlfiles.GetItemData(i);
  153.             if (task==null)
  154.                 continue;
  155.                 
  156.             if (task.st=="waiting")
  157.             { 
  158.                 if (TaskManager.RunningCount<TaskManager.MaxtTask)
  159.                 {
  160.                     
  161.                     if (task.last_st=="waiting")
  162.                     {  
  163.                         if (task.info[0]==0)
  164.                         {
  165.                             ProcessDownload(i, task);
  166.                         }
  167.                         else
  168.                         {
  169.                             ProcessConvert(i, task);
  170.                         }
  171.                     }else if (task.last_st=="download_failed")
  172.                     {
  173.                         ProcessDownload(i, task);                            
  174.                     }else if (task.last_st=="download_paused")
  175.                     {
  176.                         ProcessDownload(i, task);
  177.                     }else if (task.last_st=="downloadling")
  178.                     {
  179.                         ProcessDownload(i, task);
  180.                     }else if (task.last_st=="converting")
  181.                     {
  182.                         ProcessConvert(i, task);
  183.                     }else if(task.last_st=="stopped")
  184.                     {  
  185.                         ProcessDownload(i, task);
  186.                     }
  187.                     
  188.                     b_need_update_ui_status = true;
  189.                 }
  190.             }
  191.             else if (task.st=="downloadling")
  192.             {    
  193.                 if (task.filesize==-1)
  194.                 {
  195.                     if (utb_down_class.UTB_GetFileSize(task.taskid)<=0)
  196.                         continue;
  197.                         
  198.                     task.filesize = utb_down_class.UTB_GetFileSize(task.taskid);
  199.                     task.lastDownSize = 0;
  200.                     task.lastTimeStamp = GetTickcount();
  201.                     
  202.                     var sz = task.filesize / (1024.0*1024.0);
  203.                     
  204.                     listctrlfiles.SetValue(i, 2, formatFloat(sz, 2)+"MB");
  205.                     
  206.                 }
  207.                 {
  208.                     if (task.info[11]==0 && task.filename=="")
  209.                     {
  210.                         var fileName = utb_down_class.UTB_GetFileName(task.taskid);
  211.                     
  212.                         if (fileName!="")
  213.                         {
  214.                             task.filename = fileName;
  215.                             listctrlfiles.SetValue(i, 1, fileName);                                
  216.                         }
  217.                     }
  218.                 }
  219.  
  220.                 var dl_size = utb_down_class.UTB_GetDLSize(task.taskid);
  221.                 if (dl_size>0)
  222.                 {
  223.                     this_total_size = this_total_size + dl_size - task.lastDownSize;
  224.                     task.lastDownSize = dl_size;
  225.                     
  226.                     if (dl_size<task.filesize)
  227.                     {
  228.                         var progress = dl_size * 100 / task.filesize;
  229.                         progress = formatFloat(progress, 0);
  230.                         if (task.lastProgress!=progress)
  231.                         {
  232.                             listctrlfiles.SetValue(i, 3, progress);
  233.                             listctrlfiles.SetText(i,3,LanguageStr("_download"));
  234.                             task.lastProgress = progress;
  235.                         }
  236.                         
  237.                         var d_time = GetTickcount() - task.lastTimeStamp;
  238.                         var d_rate = 0;                            
  239.                     }
  240.                     else    //    Dowload finished
  241.                     {
  242.                     //    if (task.info[5]=="flv")    //    only download but not converter, it means this tash is finished.
  243.                         //{
  244.                             listctrlfiles.SetValue(i, 3, 100);
  245.                             TaskSetItemStatus(i, "finished");
  246.                             listctrlfiles.SetText(i,3,LanguageStr("_finish"));
  247.                             utb_down_class.UTB_UnInit(task.taskid);
  248.                             TaskManager.DownThreadUsing[task.taskid] = 0;    
  249.                             
  250.                         //    i = 0;        //        Make a chance for the first waiting task
  251.                             TaskManager.RunningCount --;
  252.                             var b_auto_delete=cfgGetInt("general", "autodelete");    
  253.                             if(b_auto_delete)
  254.                             {  
  255.                                 listctrlfiles.DeleteItem(i);
  256.                                      if(listctrlfiles.GetItemCount()==0)
  257.                                     {  
  258.                                         MainWindow.listctrlfiles.height=0;
  259.                                         MainWindow.pel.height=332;
  260.                                     }
  261.                             }        
  262.                             b_need_update_ui_status = true;
  263.                             continue;
  264.                         //}
  265.                         
  266.                     }
  267.                 }
  268.             }
  269.             
  270.         }
  271.         
  272.         this_total_size = this_total_size / 1024.0;
  273.         this_total_size = this_total_size / ((GetTickcount()-TaskManager.lastTimeStamp)/10.0)
  274.         TaskManager.lastTimeStamp = GetTickcount();
  275.         
  276.         var speed = formatFloat(this_total_size, 2)+"KB";
  277.         downspeedtext.SetText(speed);
  278.         var speedwnd=parseInt(this_total_size);
  279.         popwin.panel1.curveline2.Add(speedwnd);
  280.         if(this_total_size<0)speed=0+"KB";
  281.         popwin.panel1.speed1.SetText(speed);
  282.         popwin.panel1.task1.SetText(TaskManager.RunningCount);        
  283.  
  284.        if(TaskManager.RunningCount>0&&bjfudong==1)
  285.        {
  286.                fudong_close();
  287.                showpopup(); 
  288.             var speedwnd=parseInt(this_total_size);
  289.             if(speedwnd<=0)
  290.                speedwnd=0;
  291.             popwin.panel1.curveline2.Add(speedwnd);
  292.             popwin.panel1.speed1.SetText(speed);
  293.             popwin.panel1.task1.SetText(TaskManager.RunningCount);
  294.         }
  295.         else if(TaskManager.RunningCount==0&&bjfudong==2)
  296.         {  
  297.             fudong_close();
  298.             downspeedtext.SetText("");
  299.                showpopup();
  300.         }
  301.         
  302.      
  303.         
  304.         if (b_need_update_ui_status)
  305.             UpdateUIStatus();        
  306.     }
  307. }
  308.  
  309. function ProcessDownload(i, task)
  310. {
  311.     var n = TaskManager.GetUnusing();
  312.     if (n!=-1)
  313.     {            
  314.         MainWindow.listctrlfiles.SetValue(i, 3, 0);
  315.         
  316.         TaskManager.RunningCount ++;
  317.         utb_down_class.UTB_Init(n);
  318.         TaskManager.DownThreadUsing[n] = 1;
  319.         TaskManager.TaskSetItemStatus(i, "downloadling");
  320.         
  321.         //             0            1         2               3             4           5         6        7            8        9           10       11        12    
  322.     //task.info = [isconvert, upodurl, upodfilesize, upodprogress, upodpath, proftype, profopt, isconvert, srcfile, targetfile, realurl, bjrename, flvtmppath];
  323.      
  324.         utb_down_class.UTB_DownLoad(task.info[10],"", task.filename, task.info[4], 32, 5, 0, n, 0);
  325.         task.taskid = n;
  326.     }
  327. }
  328.  
  329. function ProcessConvert(i, task)
  330. {
  331.     
  332.     n = TaskManager.GetUnusing();
  333.     if (n!=-1)
  334.     {
  335.         var itemtmp=MainWindow.listctrlfiles.GetItem(i);
  336.         if(itemtmp[4]=="flv")
  337.         {
  338.             helper.Helper_CopyFileZ(task.info[8], task.info[9]);
  339.             MainWindow.listctrlfiles.SetValue(i,3,100);
  340.             TaskSetItemStatus(i, "finished");
  341.             return;
  342.         }
  343.         
  344.         TaskManager.RunningCount ++;
  345.         
  346.         TaskManager.DownThreadUsing[n] = 1;
  347.         TaskManager.TaskSetItemStatus(i, "converting");
  348.         utb_down_class.UTB_Init(n); 
  349.         
  350.         if(task.info[11]==1)
  351.            task.info[9]=itemtmp[5]+itemtmp[1]+"."+itemtmp[4];
  352.         
  353.         
  354.         
  355.            utb_down_class.UTB_ConvertFileStart(task.info[8], task.info[9], task.info[6], task.info[5], n);
  356.         
  357.            task.taskid = n;
  358.     }
  359. }
  360.  
  361. function RunTask()
  362. {
  363.     this.lastTimeStamp = GetTickcount();
  364.     MainWindow.SetTimer(101, 1000, "TaskManagerProcess");     
  365. }
  366.  
  367. function TaskSetItemStatus(item, st)
  368. {
  369.     with (MainWindow.listctrlfiles)
  370.     {    
  371.         var pj = null;
  372.         for (var i=0; i<ItemSatausFlag.length; i++)
  373.         {
  374.             if (ItemSatausFlag[i][0]==st)
  375.             {
  376.                 pj = ItemSatausFlag[i][1];
  377.                 break;
  378.             }
  379.         }
  380.         if (pj==null)
  381.         {
  382. //            Msg("Load image failed for item sataus:"+st, "Error", 0);
  383.         }
  384.         
  385.         SetValue(item, 0, pj);
  386.         
  387.         var task = GetItemData(item);
  388.         task.st = st;
  389.     }
  390. }
  391.  
  392. function NewTaskSetItemStatus(item, task, st)
  393. {
  394.  
  395.     with (MainWindow.listctrlfiles)
  396.     {    
  397.         var pj = null;
  398.         for (var i=0; i<ItemSatausFlag.length; i++)
  399.         {
  400.             if (ItemSatausFlag[i][0]==st)
  401.             {
  402.                 pj = ItemSatausFlag[i][1];
  403.             
  404.                 break;
  405.             }
  406.         }
  407.         if (pj==null)
  408.         {
  409. //            Msg("Load image failed for item sataus:"+st, "Error", 0);
  410.         }
  411.         
  412.         SetValue(item, 0, pj);
  413.         
  414.         task.st = st;
  415.     }
  416. }
  417.  
  418. function UpdateUIStatus()
  419. {
  420.     var b_start = false;
  421.     var b_pause = false;
  422.     var b_stop = false;
  423.     var b_delete = false;
  424.     var b_fileinfo = false;
  425.     var b_play = false;
  426.     var b_delete_finished = false;
  427.     
  428.     var b_select_all = false;
  429.     var bj_fileinfo=0;
  430.     
  431.     
  432.     with (MainWindow)
  433.     {
  434.         var count = listctrlfiles.GetItemCount();
  435.         if (count>0)
  436.             b_select_all = true;
  437.             
  438.         for (var i=0; i<count; i++)
  439.         {
  440.             if (b_delete_finished==false)
  441.             {
  442.                 task = listctrlfiles.GetItemData(i);
  443.                 if (task.st=="finished")
  444.                 {
  445.                     b_delete_finished = true;
  446.                 }
  447.             }
  448.             
  449.             if (listctrlfiles.IsSelected(i))
  450.             {
  451.                 ++bj_fileinfo;
  452.                 var task = listctrlfiles.GetItemData(i);
  453.                 b_delete = true;
  454.                 if (task.st=="waiting")
  455.                 {
  456.                     b_stop = true;
  457.                 }else if (task.st=="downloadling")
  458.                 {
  459.                     b_stop = true;
  460.                 }else if(task.st=="convert_paused")
  461.                 {
  462.                     b_stop=true;
  463.                     b_start=true;
  464.                 }
  465.                 else if (task.st=="converting")
  466.                 {
  467.                     b_stop = true;
  468.                     b_pause = true;
  469.                 }else if (task.st=="finished")
  470.                 {
  471.                     b_play = true;
  472.                     b_fileinfo = true;
  473.                 }else if (     task.st=="convert_paused" 
  474.                             || task.st=="download_failed" 
  475.                             || task.st=="convert_failed"
  476.                             || task.st=="download_paused"
  477.                             || task.st=="stopped"
  478.                             || task.st=="convert_local_stopped"
  479.                             || task.st=="convert_net_stopped"
  480.                             )
  481.                 {
  482.                     b_start = true;
  483.                 }
  484.             }
  485.         }
  486.         
  487.         if(bj_fileinfo>1)
  488.         {
  489.             b_play=false;
  490.             b_fileinfo=false;
  491.         }
  492.  
  493.         buttonstart.SetEnable(b_start);
  494.         buttonstop.SetEnable(b_stop);
  495.         buttonpre.SetEnable(b_play);
  496.         buttonfileinfo.SetEnable(b_fileinfo);
  497.         buttondelete.SetEnable(b_delete);
  498.         buttonpause.SetEnable(b_pause);
  499.  
  500.         menubar.menuoffile.menuoffileinfo.SetEnable(b_fileinfo);
  501.         menubar.menuofedit.menuofselall.SetEnable(b_select_all);
  502.             
  503.         menubar.menuofedit.menuofdeltask.SetEnable(b_delete);
  504.         menubar.menuofedit.menuofdelfintask.SetEnable(b_delete_finished);        // ???
  505.                 
  506.         menubar.menuofaction.menuofstart.SetEnable(b_start);
  507.         menubar.menuofaction.menuofpause.SetEnable(b_pause);
  508.         menubar.menuofaction.menuofstop.SetEnable(b_stop);
  509.         menubar.menuofaction.menuofplayvideo.SetEnable(b_play);
  510.     }
  511. }
  512.  
  513. function DoStopWorking()
  514. {
  515.     with (MainWindow)
  516.     {
  517.         MainWindow.ShowMessageBox(LanguageStr("_flvmain_msg_stoptask"), GetProductName(), 2);
  518.         if(b_flag==0)
  519.             return;
  520.             
  521.         var count = listctrlfiles.GetItemCount();
  522.         if (count<=0)
  523.         {
  524.             UpdateUIStatus();
  525.             return 1;
  526.         }
  527.             
  528.         //    the variable of the for loop must be declare by var, otherwise the variable cannot be working correctly.
  529.         for (var i=0; i<count; i++)
  530.         {
  531.             if (listctrlfiles.IsSelected(i))
  532.             {
  533.             //    Msg(i, "", 0);
  534.                 //continue;
  535.                 
  536.                 task = listctrlfiles.GetItemData(i);
  537.                 StopTask(i, task);
  538.             }
  539.         }
  540.     }
  541.     UpdateUIStatus();
  542. }
  543.  
  544. function DoPauseConverting()
  545. {
  546.         with (MainWindow)
  547.     {
  548.         //if(ShowMessageBox(LanguageStr("_flvmain_msg_stoptask"), LanguageStr("_waring"), 4)==7)
  549.         //    return 1;
  550.             
  551.         var count = listctrlfiles.GetItemCount();
  552.         if (count<=0)
  553.         {
  554.             UpdateUIStatus();
  555.             return 1;
  556.         }
  557.             
  558.         //    the variable of the for loop must be declare by var, otherwise the variable cannot be working correctly.
  559.         for (var i=0; i<count; i++)
  560.         {
  561.             if (listctrlfiles.IsSelected(i))
  562.             {
  563.             //    Msg(i, "", 0);
  564.                 //continue;
  565.                 
  566.                 task = listctrlfiles.GetItemData(i);
  567.                 //StopTask(i, task);
  568.                 PauseTask(i,task);
  569.             }
  570.         }
  571.     }
  572.     UpdateUIStatus();
  573. }
  574.  
  575. function DoStartWorking()
  576. {
  577.     with (MainWindow)
  578.     {            
  579.         var count = listctrlfiles.GetItemCount();
  580.         if (count<=0)
  581.         {
  582.             UpdateUIStatus();
  583.             return 1;
  584.         }
  585.         
  586.         /*
  587.             "convert_paused" 
  588.             "download_failed" 
  589.             "convert_failed"
  590.             "download_paused"
  591.             "stopped"
  592.         */
  593.             
  594.         //    the variable of the for loop must be declare by var, otherwise the variable cannot be working correctly.
  595.         for (var i=0; i<count; i++)
  596.         {
  597.             if (listctrlfiles.IsSelected(i))
  598.             {                
  599.                 task = listctrlfiles.GetItemData(i);
  600.                 if (task.st=="stopped")
  601.                 {
  602.                     NewTaskSetItemStatus(i, task, "waiting");
  603.                     task.last_st = "stopped";
  604.                 }else if (task.st=="download_failed")
  605.                 {
  606.                     NewTaskSetItemStatus(i, task, "waiting");
  607.                     task.last_st = "download_failed";
  608.                 }else if (task.st=="convert_failed")
  609.                 {
  610.                     NewTaskSetItemStatus(i, task, "waiting");
  611.                     task.last_st = "convert_failed";
  612.                 }else if (task.st=="convert_paused")
  613.                 {
  614.                     //NewTaskSetItemStatus(i, task, "waiting");
  615.                     NewTaskSetItemStatus(i, task, "converting");
  616.                     utb_down_class.UTB_ConvertTheMedia(task.info[6], task.info[5], task.taskid);
  617.                         
  618.                     task.last_st = "convert_paused";
  619.                     
  620.                 }else if (task.st=="download_paused")
  621.                 {
  622.                     NewTaskSetItemStatus(i, task, "waiting");
  623.                     task.last_st = "download_paused";
  624.                 }else if(task.st=="convert_local_stopped")
  625.                 {  
  626.                     NewTaskSetItemStatus(i, task, "waiting");
  627.                     task.last_st = "convert_local_stopped";
  628.                 }else if(task.st=="convert_net_stopped")
  629.                 {
  630.                     NewTaskSetItemStatus(i, task, "waiting");
  631.                     task.last_st = "convert_net_stopped";
  632.                 }
  633.             }
  634.         }
  635.     }
  636.     UpdateUIStatus();
  637. }
  638.  
  639. function StopTask(n_item, task)
  640. {
  641.     if (task.st=="waiting")
  642.     {
  643.         NewTaskSetItemStatus(n_item, task, "stopped");
  644.         task.last_st = "waiting";
  645.     }else if (task.st=="downloadling")
  646.     {
  647.         // var itemtmp=MainWindow.listctrlfiles.GetItem(n_item);
  648.         utb_down_class.UTB_Stop(task.taskid); 
  649.         
  650.         //    Call UTB_UnInit after UTB_Stop will arouse the main program crashed. So it must be fixed. ???
  651.         utb_down_class.UTB_UnInit(task.taskid);        //delete obj;
  652.         NewTaskSetItemStatus(n_item, task, "stopped");
  653.         task.last_st = "downloadling";
  654.         
  655.         TaskManager.RunningCount --;
  656.         TaskManager.DownThreadUsing[task.taskid] = 0;
  657.     }else if (task.st=="converting")
  658.     { 
  659.     
  660.         if(task.info[8]!="")//local file
  661.         {
  662.             //delete obj;
  663.             
  664.              NewTaskSetItemStatus(n_item, task, "convert_local_stopped");
  665.              utb_down_class.UTB_ConvertStop(task.taskid);
  666.              utb_down_class.UTB_UnInit(task.taskid);        
  667.         }else
  668.         {
  669.          
  670.         
  671.          var itemtmp=MainWindow.listctrlfiles.GetItem(n_item);
  672.          task.info[8]=itemtmp[5]+itemtmp[1]+"."+"flv";
  673.          task.info[9]=itemtmp[5]+itemtmp[1]+"."+itemtmp[4];
  674.         
  675.          NewTaskSetItemStatus(n_item, task, "convert_net_stopped");
  676.          utb_down_class.UTB_ConvertStop(task.taskid);
  677.          utb_down_class.UTB_UnInit(task.taskid);    
  678.         }
  679.        
  680.         task.last_st = "converting";    
  681.         TaskManager.RunningCount --;
  682.         TaskManager.DownThreadUsing[task.taskid] = 0;
  683.         
  684.         //Msg("hello"); 
  685.     }else if (task.st=="convert_paused")
  686.     {
  687.         if(task.info[8]=="")
  688.         {    
  689.          NewTaskSetItemStatus(n_item, task, "convert_net_stopped");
  690.         utb_down_class.UTB_ConvertStop(task.taskid);
  691.         utb_down_class.UTB_UnInit(task.taskid);        //delete obj;
  692.     
  693.         task.last_st = "convert_paused";
  694.        }else
  695.        {
  696.             NewTaskSetItemStatus(n_item, task, "convert_local_stopped");
  697.          utb_down_class.UTB_ConvertStop(task.taskid);
  698.          utb_down_class.UTB_UnInit(task.taskid);        //delete obj;
  699.          task.last_st = "convert_paused";
  700.        }
  701.         
  702.         TaskManager.RunningCount --;
  703.         TaskManager.DownThreadUsing[task.taskid] = 0;
  704.     }else if (task.st=="download_failed")
  705.     {
  706.         /*
  707.         utb_down_class.UTB_Stop(task.taskid); 
  708.         utb_down_class.UTB_UnInit(task.taskid);        //delete obj;
  709.         NewTaskSetItemStatus(n_item, task, "stopped");
  710.         task.last_st = "download_failed";
  711.         
  712.         TaskManager.RunningCount --;
  713.         TaskManager.DownThreadUsing[task.taskid] = 0;
  714.         */
  715.     }
  716.     
  717.     if (task.st!="finished" && task.st!="download_failed")
  718.     {
  719.         MainWindow.listctrlfiles.SetText(n_item,3,LanguageStr("_stop"));
  720.     }
  721.     
  722.     if(task.st!="finished")
  723.     {
  724.         task.lastDownSize = 0;
  725.         task.lastTimeStamp = 0;
  726.     }
  727. }
  728.  
  729. function PauseTask(n_item, task)
  730. {
  731.     if(task.st=="converting")
  732.     {
  733.         if(task.info[9]=="")//net file
  734.         {
  735.          utb_down_class.UTB_ConvertPause(task.taskid);
  736.         }else
  737.         {
  738.             utb_down_class.UTB_ConvertFilePause(task.taskid);
  739.         
  740.         }
  741.         NewTaskSetItemStatus(n_item, task, "convert_paused");
  742.         task.last_st = "converting";    
  743.     }
  744. }
  745.  
  746. function DoDeleteTask()
  747. {
  748.     with (MainWindow)
  749.     {            
  750.         var count = listctrlfiles.GetItemCount();
  751.         if (count<=0)
  752.         {
  753.             UpdateUIStatus();
  754.             return 1;
  755.         }
  756.         
  757.         MainWindow.ShowMessageBox(LanguageStr("_flvmain_msg_deltask"), GetProductName(), 2);
  758.         if(b_flag==0)
  759.         return;
  760.         
  761.         SetWindowRedraw(listctrlfiles, false);
  762.         
  763.         for (var i=count-1; i>=0; i--)
  764.         {
  765.             if (listctrlfiles.IsSelected(i))
  766.             {
  767.                 task = listctrlfiles.GetItemData(i);
  768.                 var itemtmp=listctrlfiles.GetItem(i);
  769.                 
  770.                 if(task.st=="downloadling")
  771.                 {
  772.                 StopTask(i, task);
  773.                     if(helper.Helper_IsFileExist(itemtmp[4]+"\\"+itemtmp[1]+".flv")==1)
  774.                     {  
  775.                         helper.Helper_DeleteFile(itemtmp[4]+"\\"+itemtmp[1]+".flv");
  776.                     }
  777.                 listctrlfiles.DeleteItem(i);
  778.                 }else if(task.st=="download_failed"||task.st=="stopped")
  779.                 {    
  780.                     if(helper.Helper_IsFileExist(itemtmp[4]+"\\"+itemtmp[1]+".flv")==1)
  781.                     {  
  782.                         helper.Helper_DeleteFile(itemtmp[4]+"\\"+itemtmp[1]+".flv");
  783.                     }
  784.                     listctrlfiles.DeleteItem(i);
  785.                 }else
  786.                 {
  787.                     listctrlfiles.DeleteItem(i);
  788.                 }
  789.                
  790.             }
  791.         }
  792.          if(TaskManager.RunningCount==0&&bjfudong==2)
  793.         {  
  794.             fudong_close();
  795.                showpopup();
  796.         }
  797.         if(listctrlfiles.GetItemCount()==0)
  798.         {
  799.             MainWindow.listctrlfiles.height=0;
  800.             MainWindow.pel.height=332;
  801.         }
  802.         
  803.         
  804.         SetWindowRedraw(listctrlfiles, true);
  805.         
  806.         UpdateUIStatus();
  807.     }
  808. }
  809.  
  810. function DoDeleteFinishedTask()
  811. {
  812.     with (MainWindow)
  813.     {            
  814.         var count = listctrlfiles.GetItemCount();
  815.         if (count<=0)
  816.         {
  817.             UpdateUIStatus();
  818.             return 1;
  819.         }
  820.         
  821.         SetWindowRedraw(listctrlfiles, false);
  822.         for (var i=count-1; i>=0; i--)
  823.         {
  824.             task = listctrlfiles.GetItemData(i);
  825.             //ShowMessageBox(task);
  826.             if (task.st=="finished")
  827.             {
  828.                 listctrlfiles.DeleteItem(i);
  829.             }            
  830.         }
  831.          if(listctrlfiles.GetItemCount()==0)
  832.         {
  833.             MainWindow.listctrlfiles.height=0;
  834.             MainWindow.pel.height=332;
  835.         }
  836.         SetWindowRedraw(listctrlfiles, true);
  837.         UpdateUIStatus();
  838.     }
  839.     return 0;
  840. }
  841.  
  842. function TaskCanStart(task)
  843. {
  844.     if ( task.st=="convert_paused" 
  845.          || task.st=="download_failed" 
  846.          || task.st=="convert_failed"
  847.          || task.st=="download_paused"
  848.          || task.st=="stopped"
  849.          || task.st=="convert_local_stopped"
  850.          || task.st=="convert_net_stopped"
  851.         )
  852.         {
  853.             return true;
  854.         }
  855.     
  856.     return false;
  857. }
  858.  
  859. function TaskCanPause(task)
  860. {
  861.     if (task.st=="converting")
  862.     {
  863.         return true;
  864.     }
  865.     
  866.     return false;
  867. }
  868.  
  869. function TaskCanStop(task)
  870. {
  871.     if (task.st=="waiting")
  872.     {
  873.         return true;
  874.     }
  875.     
  876.     if (task.st=="downloadling")
  877.     {
  878.         return true;
  879.     }
  880.     
  881.     if (task.st=="converting")
  882.     {
  883.         return true;
  884.     }
  885.     if(task.st=="convert_paused")
  886.     {
  887.         return true;
  888.     }
  889.     return false;
  890. }
  891.  
  892.  
  893. ///////
  894.  
  895. function SaveTask(cfg, task, nIndex,filename,filesize,fileprogress)
  896. {
  897.     //Msg(task.info[1]+" "+task.info[2]+" "+task.info[3]+" "+task.info[4]);
  898.     //cfg.WriteString("Tasks", nIndex, task.info[1]+","+task.info[2]+","+task.info[3]);
  899.     //cfg.SetValue("task",nIndex,task.info[0]+","+task.info[1]+","+task.info[2]+","+task.info[3]+","+task.info[4]+","+task.info[8]+","+task.info[9]+
  900.     //","+filename+","+filesize+","+fileprogress);
  901.     //Msg("sadfasdf");
  902.     //Msg(filename+" "+filesize+" "+fileprogress);
  903.     cfg.SetValue("task",nIndex,task.info[0]+",/"+task.info[1]+",/"+task.info[2]+",/"+task.info[3]+",/"+task.info[4]+",/"+task.info[5]+",/"+task.info[6]+",/"+task.info[7]+",/"+task.info[8]+",/"+task.info[9]+",/"+task.info[10]+",/"+task.info[11]+",/"+task.info[12]+",/"+task.st+",/"+filename+",/"+filesize+",/"+fileprogress);
  904.     
  905.     
  906.     
  907. }
  908.  
  909. function SaveAllTasks()
  910. {
  911.     //var s_TaskSavedFile = GetPrivateConfigFolder() + "\\savedtask.ini";
  912.     //g_upodutil.DeleteFile(s_TaskSavedFile);
  913.  
  914.     var s_TaskSavedFile ="upod.ini";
  915.     g_upodutil.DeleteFile(s_TaskSavedFile);
  916.     
  917.     var TaskConfig = new JSIniFile();
  918.     TaskConfig.SetPath(s_TaskSavedFile);
  919.     
  920.  
  921.     var nCount = 0;
  922.     
  923.     with (MainWindow.listctrlfiles)
  924.     {
  925.         for (var i=0; i<GetItemCount(); i++)
  926.         {
  927.             var Task = GetItemData(i);
  928.             if (Task.st=="downloadling"||Task.st=="converting")
  929.             {
  930.                if(Task.info[9]!="")
  931.                {
  932.                 StopTask(i,Task);
  933.                 var itemtmp=GetItem(i);
  934.                 SaveTask(TaskConfig, Task, nCount,itemtmp[1],itemtmp[2],itemtmp[3]);
  935.                 nCount ++;
  936.                }else
  937.                {
  938.                    StopTask(i,Task);
  939.                 var itemtmp=GetItem(i);
  940.                 var tmppath=cfgGetString("general","tempfolder","c:\\");
  941.                 Task.info[8]=tmppath+"\\"+itemtmp[1]+"."+"flv";
  942.                 Task.info[9]=itemtmp[5]+"\\"+itemtmp[1]+"."+itemtmp[4];
  943.                 SaveTask(TaskConfig, Task, nCount,itemtmp[1],itemtmp[2],itemtmp[3]);
  944.                 nCount ++;
  945.                }
  946.             }
  947.             else if(Task.st=="stopped"||Task.st=="download_failed")
  948.             {
  949.                 var itemtmp=GetItem(i);
  950.                 SaveTask(TaskConfig, Task, nCount,itemtmp[1],itemtmp[2],itemtmp[3]);
  951.                 nCount ++;
  952.             }else if(Task.st=="convert_paused")
  953.             {
  954.                 StopTask(i,Task);
  955.                 var itemtmp=GetItem(i);
  956.                 SaveTask(TaskConfig, Task, nCount,itemtmp[1],itemtmp[2],itemtmp[3]);
  957.                 nCount ++;
  958.             }else if(Task.st=="convert_local_stopped"||Task.st=="convert_net_stopped")
  959.             {
  960.                 var itemtmp=GetItem(i);
  961.                 SaveTask(TaskConfig, Task, nCount,itemtmp[1],itemtmp[2],itemtmp[3]);
  962.                 nCount ++;
  963.             }else if(Task.st=="finished")
  964.             {    var itemtmp=GetItem(i);
  965.                 SaveTask(TaskConfig, Task, nCount,itemtmp[1],itemtmp[2],itemtmp[3]);
  966.                 nCount ++;
  967.             }
  968.         
  969.         }
  970.     }
  971.     
  972.     TaskConfig.SetValue("General", "TaskCount", nCount);
  973.     
  974.     TaskConfig.WriteFile();
  975.     
  976.     TaskConfig = null;    
  977. }