Ejemplo n.º 1
0
        //*************************************************************************************************************
        private async void this_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            string CurDir = CurrentDirectory;

            try
            {
                if (e.Label != null)
                {
                    if (Regex.IsMatch(e.Label, @"[:\*\\/\?""<>|]"))
                    {
                        MessageBox.Show("The provided name has some invalid characters", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Items[e.Item].BeginEdit();
                        return;
                    }

                    LabelEdit    = false;
                    e.CancelEdit = true;

                    string newDir = Path.Combine(CurrentDirectory, e.Label);

                    if (Items[e.Item].Tag == null) //new folder
                    {
                        if (!await remoteIO.Exists(newDir))
                        {
                            var result = await remoteIO.CreateDirectory(newDir);

                            form.Log(result.Message);
                        }
                    }
                    else
                    {
                        DiskItem disk = (DiskItem)Items[e.Item].Tag;
                        if (await remoteIO.Exists(newDir))
                        {
                            MessageBox.Show(string.Format("There is already a {0} with that name",
                                                          (disk.IsDirectory) ? "folder" : "file"), "Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            var result = await remoteIO.Rename(disk.path, newDir);

                            form.Log(result.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                form.Log(ex.Message, Color.Red);
            }

            await LoadList(CurDir);
        }
Ejemplo n.º 2
0
        //*************************************************************************************************************
        public async Task ProcessQueue()
        {
            while (Items.Count > 0)
            {
                Update();
                form.TotalQueueText.Text = string.Format("{0} Items in queue", Items.Count);
                QueueItem item         = new QueueItem();
                bool      refreshLists = true;
                bool      alldone      = true;
                foreach (ListViewItem listitem in Items)
                {
                    if (((QueueItem)listitem.Tag).Status == QueueStatus.Queue)
                    {
                        SetSubItemImage(listitem, 0, "Processing...", Resources.play);
                        item = (QueueItem)listitem.Tag;
                        listitem.EnsureVisible();
                        refreshLists = false;
                        alldone      = false;
                        break;
                    }
                }

                if (alldone)
                {
                    QueueRunning = false;
                    return;
                }

                if (refreshLists)
                {
                    QueueRunning = false;
                    RefreshLists();
                }

                if (item.TransferID != null)
                {
                    try
                    {
                        if (item.Download)        //Download
                        {
                            if (item.SourceIsdir) //Create Directory
                            {
                                Directory.CreateDirectory(item.DestinationPath);
                                DeleteByKey(item.TransferID);
                            }
                            else //Get File
                            {
                                XwFileAction action = XwFileAction.Overwrite;
                                if (File.Exists(item.DestinationPath))
                                {
                                    if (DoToAllFiles == XwFileAction.Ask)
                                    {
                                        Exists exists = new Exists();

                                        exists.SourceFileName.Text      = item.SourcePath;
                                        exists.DestinationFileName.Text = item.DestinationPath;

                                        exists.SourceIcon.Image      = ShellImageList.GetIcon(item.ImageIndex, false).ToBitmap();
                                        exists.DestinationIcon.Image = ShellImageList.GetIcon(item.ImageIndex, false).ToBitmap();

                                        exists.SourceFileSize.Text = string.Format("{0:#,#}", item.Size);
                                        FileInfo fi = new FileInfo(item.DestinationPath);
                                        exists.DestinationFileSize.Text = string.Format("{0:#,#}", fi.Length);
                                        exists.DestinationFileDate.Text = File.GetLastWriteTime(item.DestinationPath).ToStringUI();

                                        if (exists.ShowDialog(this) == DialogResult.Cancel)
                                        {
                                            DeleteAll();
                                            return;
                                        }
                                        else
                                        {
                                            if (exists.DoToAllFiles != XwFileAction.Ask)
                                            {
                                                DoToAllFiles = exists.DoToAllFiles;
                                                action       = exists.DoToAllFiles;
                                            }
                                            else
                                            {
                                                action = exists.DoToFile;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        action = DoToAllFiles;
                                    }
                                }

                                if (action == XwFileAction.Skip)
                                {
                                    DeleteByKey(item.TransferID);
                                }
                                else
                                {
                                    int index = Items.IndexOfKey(item.TransferID);
                                    if (index != -1)
                                    {
                                        item.Transferred = 0;
                                        item.Status      = QueueStatus.Progress;
                                        Items.IndexOfKey(item.TransferID);
                                        Items[index].Tag = item;
                                    }
                                    var result = await remoteIO.DownloadFile(item.DestinationPath, item.SourcePath,
                                                                             item.TransferID, action == XwFileAction.Resume, item.CancelTokenSource.Token);

                                    if (result.Success)
                                    {
                                        DeleteByKey(item.TransferID);
                                        form.TotalQueueText.Text = string.Format("{0} Items in queue", Items.Count);
                                    }
                                    else
                                    {
                                        form.Log(result.Message, Color.Red);
                                        int idx = Items.IndexOfKey(item.TransferID);
                                        if (idx >= 0)
                                        {
                                            ListViewItem litem = Items[index];
                                            QueueItem    queue = (QueueItem)litem.Tag;
                                            queue.Status      = QueueStatus.Error;
                                            litem.Tag         = queue;
                                            litem.ToolTipText = result.Message;
                                            SetSubItemImage(litem, 0, "Error", Resources.error);
                                        }
                                    }
                                }
                            }
                        }
                        else //Upload
                        {
                            if (item.SourceIsdir) // Create Directory
                            {
                                if (!SkipExistsValidation.Contains(item.DestinationPath))
                                {
                                    if (!await remoteIO.Exists(item.DestinationPath))
                                    {
                                        var result = await remoteIO.CreateDirectory(item.DestinationPath);

                                        if (!result.Success)
                                        {
                                            form.Log(result.Message, Color.Red);
                                        }
                                        SkipExistsValidation.Add(item.DestinationPath);
                                    }
                                }
                                DeleteByKey(item.TransferID);
                            }
                            else //Put File
                            {
                                XwFileAction action = XwFileAction.Overwrite;
                                string       dir    = item.DestinationPath.Substring(0, item.DestinationPath.LastIndexOf('/'));
                                if (dir == "")
                                {
                                    dir = "/";
                                }

                                if (await remoteIO.Exists(item.DestinationPath))
                                {
                                    if (DoToAllFiles == XwFileAction.Ask)
                                    {
                                        Exists exists = new Exists();

                                        exists.SourceFileName.Text      = item.SourcePath;
                                        exists.DestinationFileName.Text = item.DestinationPath;

                                        exists.SourceIcon.Image      = ShellImageList.GetIcon(item.ImageIndex, false).ToBitmap();
                                        exists.DestinationIcon.Image = ShellImageList.GetIcon(item.ImageIndex, false).ToBitmap();

                                        exists.SourceFileSize.Text = string.Format("{0:#,#}", item.Size);
                                        var result = await remoteIO.GetFileSize(item.DestinationPath);

                                        if (!result.Success)
                                        {
                                            form.Log(result.Message, Color.Red);
                                        }
                                        exists.DestinationFileSize.Text = string.Format("{0:#,#}", result.Size);

                                        exists.SourceFileDate.Text = File.GetLastWriteTime(item.SourcePath).ToStringUI();
                                        result = await remoteIO.GetDateModified(item.DestinationPath);

                                        if (!result.Success)
                                        {
                                            form.Log(result.Message, Color.Red);
                                        }
                                        exists.DestinationFileDate.Text = result.Modified.ToStringUI();

                                        if (exists.ShowDialog(this) == DialogResult.Cancel)
                                        {
                                            DeleteAll();
                                            QueueRunning = false;
                                            DoToAllFiles = XwFileAction.Ask;
                                            RefreshLists();
                                            return;
                                        }
                                        else
                                        {
                                            if (exists.DoToAllFiles != XwFileAction.Ask)
                                            {
                                                DoToAllFiles = exists.DoToAllFiles;
                                                action       = exists.DoToAllFiles;
                                            }
                                            else
                                            {
                                                action = exists.DoToFile;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        action = DoToAllFiles;
                                    }
                                }

                                if (action == XwFileAction.Skip)
                                {
                                    DeleteByKey(item.TransferID);
                                }
                                else
                                {
                                    int index = Items.IndexOfKey(item.TransferID);
                                    if (index != -1)
                                    {
                                        item.Transferred = 0;
                                        item.Status      = QueueStatus.Progress;
                                        Items.IndexOfKey(item.TransferID);
                                        Items[index].Tag = item;
                                    }

                                    var result = await remoteIO.UploadFile(item.SourcePath, item.DestinationPath,
                                                                           item.TransferID, action == XwFileAction.Resume, item.CancelTokenSource.Token);

                                    if (result.Success)
                                    {
                                        DeleteByKey(item.TransferID);
                                        form.TotalQueueText.Text = string.Format("{0} Items in queue", Items.Count);
                                    }
                                    else
                                    {
                                        form.Log(result.Message, Color.Red);
                                        int idx = Items.IndexOfKey(item.TransferID);
                                        if (idx >= 0)
                                        {
                                            ListViewItem litem = Items[index];
                                            QueueItem    queue = (QueueItem)litem.Tag;
                                            queue.Status      = QueueStatus.Error;
                                            litem.Tag         = queue;
                                            litem.ToolTipText = result.Message;
                                            SetSubItemImage(litem, 0, "Error", Resources.error);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.Contains("InnerException"))
                        {
                            form.Log(ex.InnerException.Message, Color.Red);
                        }
                        else
                        {
                            form.Log(ex.Message, Color.Red);
                        }
                        int index = Items.IndexOfKey(item.TransferID);
                        if (index != -1)
                        {
                            QueueItem qi = (QueueItem)Items[index].Tag;
                            qi.Status        = QueueStatus.Error;
                            Items[index].Tag = qi;
                            SetSubItemImage(Items[index], 0, "Error", Resources.exclamation);
                            Items[index].ToolTipText = ex.Message;
                        }
                    }
                }
            }

            SkipExistsValidation.Clear();
            QueueRunning = false;
            DoToAllFiles = XwFileAction.Ask;
            RefreshLists();
        }