示例#1
0
        private bool IncludeFile(FileSystemObject file)
        {
            if (m_Filter == null || m_Filter.Count == 0)
            {
                return(true);
            }

            foreach (var item in m_Filter)
            {
                if (RegExCompare(file.Name, item))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#2
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;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Converts a collection Dropbox Metadata objects to our own file system type
        /// </summary>
        /// <param name="entries"></param>
        /// <param name="dialogType"></param>
        /// <returns></returns>
        private async Task <FileSystemObjects> MetadataToFileSystemObjects(IList <Metadata> entries, OpenDialogType dialogType)
        {
            FileSystemObjects items = new FileSystemObjects();

            Dictionary <string, SharedLinkMetadata> shares = new Dictionary <string, SharedLinkMetadata>();

            #region Get all shares if required
            if (dialogType != OpenDialogType.File)
            {
                IList <SharedLinkMetadata> links = null;
                var operationShares = Task.Factory.StartNew(() =>
                {
                    Task <ListSharedLinksResult> results = _Dropbox.Sharing.ListSharedLinksAsync(null);
                    links = results.Result.Links;
                });
                await operationShares;

                foreach (var link in links)
                {
                    // Only add one share per item
                    if (!shares.ContainsKey(link.PathLower))
                    {
                        // If we want public links and this is a public link then add it
                        if (dialogType == OpenDialogType.PublicShare && link.LinkPermissions.ResolvedVisibility.IsPublic)
                        {
                            shares.Add(link.PathLower, link);
                        }

                        // If we want team links and this is a public or team link then add it
                        else if (dialogType == OpenDialogType.TeamShare && (link.LinkPermissions.ResolvedVisibility.IsPublic || link.LinkPermissions.ResolvedVisibility.IsTeamOnly))
                        {
                            shares.Add(link.PathLower, link);
                        }
                    }
                }
            }
            #endregion

            #region Process folders
            foreach (var result in entries.Where(i => i.IsFolder))
            {
                FileSystemObject item = new FileSystemObject();
                item.ItemType = FileSystemObjectType.Folder;
                item.Name     = result.Name;
                item.Path     = result.PathLower;
                item.ShareUrl = "";
                items.Add(item);
            }
            #endregion

            #region Process files
            foreach (var result in entries.Where(i => i.IsFile))
            {
                FileSystemObject item = new FileSystemObject();
                item.ItemType       = FileSystemObjectType.File;
                item.Name           = result.Name;
                item.Path           = result.PathLower;
                item.ClientModified = result.AsFile.ClientModified;
                item.Size           = result.AsFile.Size;

                if (dialogType == OpenDialogType.File)
                {
                    item.ShareUrl = "";
                    items.Add(item);
                }
                else if (shares.ContainsKey(result.PathLower))
                {
                    item.ShareUrl = shares[result.PathLower].Url;
                    items.Add(item);
                }
            }
            #endregion

            return(items);
        }
示例#4
0
 public ItemSelectedArgs(FileSystemObject item)
 {
     Item = item;
 }