Example #1
0
        public void LoadItems()
        {
            while (myWorker != null && myWorker.ThreadState == ThreadState.AbortRequested)
            {
            }
            //BeginUpdate();
            //Items.Clear();
            LargeImageList.Images.Clear();
            SmallImageList.Images.Clear();
            AddDefaultThumb(this.LargeImageList);
            AddDefaultThumb(this.SmallImageList);

            string[] fileList = new string[this.Items.Count];
            for (int i = 0; i < this.Items.Count; i++)
            //foreach (string fileName in fileList)
            {
                this.Items[i].ImageIndex = 0;
                Bitmap image = ShellImageList.GetIcon(((ShellItem)this.Items[i].Tag).ImageIndex, true).ToBitmap();
                this.SmallImageList.Images.Add(image);

                fileList[i] = ShellItem.GetRealPath((ShellItem)this.Items[i].Tag);
            }

            //EndUpdate();

            ParameterizedThreadStart threadStart = new ParameterizedThreadStart(this.bwLoadImages_DoWork);

            myWorker = new Thread(threadStart);
            myWorker.CurrentCulture   = Thread.CurrentThread.CurrentCulture;
            myWorker.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
            myWorker.IsBackground     = true;
            myWorker.Start(fileList);
            //this.AnimateTime.Start();
        }
        private void AddNavBackFordwardItem(ToolStripSplitButton button, TreeNode item)
        {
            Bitmap        image   = imageList.GetIcon(item.ImageIndex, true).ToBitmap();
            ToolStripItem navItem = new ToolStripMenuItem(item.Text, image);

            navItem.Name         = item.Text;
            navItem.Tag          = item;
            navItem.ImageScaling = ToolStripItemImageScaling.None;

            if (button.DropDownItems.Count == maxBackFordward)
            {
                button.DropDownItems.RemoveAt(maxBackFordward - 1);
            }
            if ((button.DropDownItems.Count == 0) ||
                (button.DropDownItems.Count > 0 &&
                 button.DropDownItems[0] != navItem))
            {
                button.DropDownItems.Insert(0, navItem);
                button.Enabled = true;
            }
        }
Example #3
0
        private void fileBrowser_SelectedFolderChanged(object sender, SelectedFolderChangedEventArgs e)
        {
            Icon icon = ShellImageList.GetIcon(e.Node.ImageIndex, true);

            if (icon != null)
            {
                currentDirInfo.Image = icon.ToBitmap();
                this.Icon            = icon;
            }
            else
            {
                currentDirInfo.Image = null;
                this.Icon            = null;
            }

            currentDirInfo.Text = e.Node.Text;
            this.Text           = e.Node.Text;
        }
Example #4
0
        //*************************************************************************************************************
        public void InsertOnQueue(QueueItem queue)
        {
            if (queue.SourcePath == "." ||
                queue.SourcePath == "..")
            {
                return;
            }

            queue.TransferID = Guid.NewGuid().ToString();

            Image        image    = ShellImageList.GetIcon(queue.ImageIndex, true).ToBitmap();
            ListViewItem listitem = InsertItem();

            SetSubItemImage(listitem, 0, "In queue", Resources.bullet_arrow_up);
            SetSubItemImage(listitem, 1, (queue.Download) ? queue.DestinationPath : queue.SourcePath, image);
            SetSubItemImage(listitem, 2, string.Empty, (queue.Download) ? Resources.download : Resources.upload);
            SetSubItemImage(listitem, 3, (queue.Download) ? queue.SourcePath : queue.DestinationPath, image);
            SetSubItemText(listitem, 4, XwMaxLib.IO.Drive.GetFileSize(queue.Size));
            listitem.Tag             = queue;
            listitem.Name            = queue.TransferID;
            form.TotalQueueText.Text = string.Format("{0} Items in queue", Items.Count);
        }
Example #5
0
 public BrowserComboItem(ShellItem shellItem, int indent)
 {
     this.shellItem = shellItem;
     this.indent    = indent;
     this.image     = ShellImageList.GetIcon(shellItem.ImageIndex, true);
 }
Example #6
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();
        }