private void DoQueue()
        {
            while (!stop)
            {
                if (queueList.Count > 0)
                {
                    CopyQueue queue   = queueList[0];
                    FileInfo  fileInf = new FileInfo(queue.file);
                    queue.total  = fileInf.Length;
                    currentQueue = queue;

                    string     file      = this.usbDrive + fileInf.Name;//String.Format("/ux0:/{0}", fileInf.Name);
                    FileStream fs        = fileInf.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    FileStream target_fs = new FileStream(file, FileMode.Create);
                    byte[]     buffer    = new byte[20480];
                    int        recv      = fs.Read(buffer, 0, buffer.Length);
                    while (recv > 0)
                    {
                        target_fs.Write(buffer, 0, recv);
                        queue.uploaded += recv;
                        recv            = fs.Read(buffer, 0, buffer.Length);
                    }
                    target_fs.Close();
                    fs.Close();
                    queueList.RemoveAt(0);
                }
                Thread.Sleep(1000);
            }
        }
Example #2
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (SplitQueue != null)
     {
         long   total    = GetDirectoryLength(VitaPackageHelper.Helper.current);
         string fileSize = String.Format(new FileSizeFormatProvider(), "{0:fs}", total);
         ftpStatus.Text = "Processing ... " + fileSize;
         return;
     }
     if (connectionType.SelectedIndex == 1)
     {
         toolStripStatusLabel1.Text = "FTP Service:";
         if (manager != null)
         {
             if (manager.isWorking())
             {
                 if (manager.error != "" && manager.error != null)
                 {
                     ftpStatus.Text = manager.error;
                 }
                 else
                 {
                     if (manager.getQueueCount() > 0)
                     {
                         FTPQueue queue = manager.currentQueue;
                         String   text  = "";
                         if (queue != null)
                         {
                             if (last_uploaded == 0)
                             {
                                 last_uploaded = queue.uploaded;
                             }
                             long speed = queue.uploaded - last_uploaded;
                             last_uploaded = queue.uploaded;
                             String speed_text = String.Format(new FileSizeFormatProvider(), "{0:fs}/s", speed);
                             double progress   = (double)queue.uploaded / (double)queue.total * 100;
                             uploadProgress.Value = (int)progress > 100 ? 100 : (int)progress;
                             text = speed_text;
                             if (queue.obj != null)
                             {
                                 ListViewItem item = queue.obj as ListViewItem;
                                 if (item != null)
                                 {
                                     if (uploadProgress.Value == 100)
                                     {
                                         item.SubItems[5].Text = "Done";
                                     }
                                     else
                                     {
                                         item.SubItems[5].Text = uploadProgress.Value + "%";
                                     }
                                 }
                             }
                         }
                         ftpStatus.Text = String.Format("{0} Queue {1}", manager.getQueueCount(), text);
                     }
                     else
                     {
                         ftpStatus.Text = "Idle";
                     }
                 }
             }
             else
             {
                 ftpStatus.Text = "Stop";
             }
         }
     }
     else
     {
         toolStripStatusLabel1.Text = "USB Service:";
         if (copyManager != null)
         {
             if (copyManager.isWorking())
             {
                 if (copyManager.error != "" && copyManager.error != null)
                 {
                     ftpStatus.Text = copyManager.error;
                 }
                 else
                 {
                     if (copyManager.getQueueCount() > 0)
                     {
                         CopyQueue queue = copyManager.currentQueue;
                         String    text  = "";
                         if (queue != null)
                         {
                             if (last_uploaded == 0)
                             {
                                 last_uploaded = queue.uploaded;
                             }
                             long speed = queue.uploaded - last_uploaded;
                             last_uploaded = queue.uploaded;
                             String speed_text = String.Format(new FileSizeFormatProvider(), "{0:fs}/s", speed);
                             double progress   = (double)queue.uploaded / (double)queue.total * 100;
                             uploadProgress.Value = (int)progress > 100 ? 100 : (int)progress;
                             text = speed_text;
                             if (queue.obj != null)
                             {
                                 ListViewItem item = queue.obj as ListViewItem;
                                 if (item != null)
                                 {
                                     if (uploadProgress.Value == 100)
                                     {
                                         item.SubItems[5].Text = "Done";
                                     }
                                     else
                                     {
                                         item.SubItems[5].Text = uploadProgress.Value + "%";
                                     }
                                 }
                             }
                         }
                         ftpStatus.Text = String.Format("{0} Queue {1}", copyManager.getQueueCount(), text);
                     }
                     else
                     {
                         ftpStatus.Text = "Idle";
                     }
                 }
             }
             else
             {
                 ftpStatus.Text = "Stop";
             }
         }
     }
 }