Exemplo n.º 1
0
        /// <summary>
        /// Uploads a file
        /// </summary>
        /// <param name="dropboxFilePath">The target location for the upload</param>
        /// <param name="localFilePath">The local file to upload</param>
        /// <returns>The result of the asynchronous operation</returns>
        internal async Task UploadFileUI(string dropboxFilePath, string localFilePath, bool overwrite)
        {
            try
            {
                lblAction.Text      = "Uploading:";
                lblFileName.Text    = Path.GetFileName(localFilePath);
                lblSource.Text      = Path.GetDirectoryName(localFilePath);
                lblDestination.Text = Path.GetDirectoryName(dropboxFilePath);
                this.Show();
                this.BringToFront();
                _cancellationTokenSource = new CancellationTokenSource();

                using (var dropbox = new DropboxFiles())
                {
                    dropbox.FileTransferProgress += Dropbox_FileTransferProgress;
                    await dropbox.UploadFile(dropboxFilePath, localFilePath, overwrite, _cancellationTokenSource.Token);
                }

                _cancellationTokenSource = null;

                this.Refresh();
                Thread.Sleep(300);
            }
            catch (Exception ex)
            {
                ErrorPanel.ShowError(this, ex);
            }
        }
Exemplo n.º 2
0
        private async void listview_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            try
            {
                listview.LabelEdit = false;
                if (e.Label == null)
                {
                    listview.Items.RemoveAt(e.Item);
                }
                else
                {
                    string path = _CurrentPath;
                    if (!path.EndsWith("/"))
                    {
                        path += "/";
                    }
                    path += e.Label;

                    using (var dropbox = new DropboxFiles())
                    {
                        await dropbox.CreateFolder(path);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorPanel.ShowError(this, ex);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Navigates to the required folder
        /// </summary>
        /// <param name="path">The path to navigate to</param>
        /// <returns>The result of the asynchronous operation</returns>
        internal async Task NavigateToFolder(OpenDialogType dialogType, string path, string searchTerm)
        {
            _CurrentPath = DropboxFiles.FixPath(path);
            _DialogType  = dialogType;
            _SearchTerm  = searchTerm;

            busyIcon1.Show();
            busyIcon1.BringToFront();

            try
            {
                // Clear the list for for common code path to make UI look correct
                listview.Items.Clear();

                using (var dropbox = new DropboxFiles())
                {
                    FileSystemObjects items;

                    if (string.IsNullOrEmpty(_SearchTerm))
                    {
                        items = await dropbox.GetFolderContents(_CurrentPath, _DialogType);
                    }
                    else
                    {
                        items = await dropbox.Search(_CurrentPath, _DialogType, _SearchTerm);
                    }

                    // We might have ended up in the async method multiple times so lets clear again just in case
                    listview.Items.Clear();

                    foreach (var item in items)
                    {
                        switch (item.ItemType)
                        {
                        case FileSystemObjectType.Folder:
                            var folder = CreateItem(item.Name, "Folder", "", "File folder", "", "", item);
                            listview.Items.Add(folder);
                            break;

                        case FileSystemObjectType.File:
                            if (IncludeFile(item))
                            {
                                var task = AddFile(dropbox, item);
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorPanel.ShowError(this, ex);
            }

            busyIcon1.Hide();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets the current path
        /// </summary>
        /// <param name="path">The path to configure the control for</param>
        internal void SetPath(string path, bool addToBackButton)
        {
            // Remember existing path in previous stack
            if (addToBackButton && string.Compare(path, _CurrentPath, true) != 0)
            {
                // Add previous path to start of list
                if (_CurrentPath.Length > 1 && _CurrentPath.StartsWith("/"))
                {
                    _PreviousPaths.Insert(0, _CurrentPath.Substring(1));
                }
                else
                {
                    _PreviousPaths.Insert(0, _CurrentPath);
                }
            }

            // Remove old buttons
            foreach (var btn in _BreadcrumbButtons)
            {
                this.Items.Remove(btn);
            }
            _BreadcrumbButtons.Clear();

            // If this isn't the root level, add a button for each folder in the path
            if (!string.IsNullOrEmpty(path))
            {
                string   fullPath = "";
                string[] parts    = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string part in parts)
                {
                    fullPath += "/" + part;
                    string caption = (part.Length > 1 ? part.Substring(0, 1).ToUpper() + part.Substring(1) : part.ToUpper());

                    ToolStripItem breadcrumbButton = AddButton(caption, string.Format("Return to '{0}' folder", fullPath.Substring(1)), Properties.Resources.Folder, true, breadcrumbButton_Click, fullPath);

                    _BreadcrumbButtons.Add(breadcrumbButton);
                    this.Items.Add(breadcrumbButton);
                }
            }

            RebuildDropBackPaths();

            _CurrentPath = path;

            _ButtonRoot.Enabled = true;
            _ButtonBack.Enabled = (_PreviousPaths.Count > 0);
            _ButtonUp.Enabled   = !DropboxFiles.IsRootPath(_CurrentPath);
        }
Exemplo n.º 5
0
        private void _ButtonUp_Click(object sender, EventArgs e)
        {
            if (DropboxFiles.IsRootPath(_CurrentPath))
            {
                return;
            }
            string path = System.IO.Path.GetDirectoryName(_CurrentPath);

            path = path.Replace('\\', '/');
            if (path == "/")
            {
                path = "";
            }

            ButtonClick(_ButtonUp, path, false);
        }
Exemplo n.º 6
0
        private async Task AddFile(DropboxFiles dropbox, FileSystemObject file)
        {
            const string THUMBNAILS = ".jpg.jpeg.png.tiff.tif.gif.bmp";

            string ext      = System.IO.Path.GetExtension(file.Name);
            string imageKey = ext;

            if (filetypes16.Images.ContainsKey(file.Path))
            {
                imageKey = file.Path;
            }
            else if (!filetypes16.Images.ContainsKey(imageKey))
            {
                Bitmap small = WinAPI.GetFileSmallIcon(file.Name);
                filetypes16.Images.Add(imageKey, small);

                Bitmap large = WinAPI.GetFileExtraLargeIcon(file.Name);
                filetypes48.Images.Add(imageKey, large);
            }

            var item = CreateItem(file.Name, imageKey, file.ClientModified.ToString(), WinAPI.GetFileTypeName(ext), WinAPI.FormatBytes(file.Size), file.Path, file);

            listview.Items.Add(item);

            // If current image is based on extension, get the thumbnail
            if (THUMBNAILS.Contains(ext) && imageKey.StartsWith(ext))
            {
                using (var image = await dropbox.GetThumbnail(file.Path))
                {
                    Bitmap thumbnail = GetThumbnail(image, filetypes48.ImageSize.Width);

                    Bitmap small = WinAPI.GetFileSmallIcon(file.Name);
                    filetypes16.Images.Add(file.Path, small);

                    filetypes48.Images.Add(file.Path, thumbnail);

                    item.ImageKey = file.Path;
                }
            }
        }