Esempio n. 1
0
        public override IAsyncOperation <IStorageItem> GetItemAsync(string name)
        {
            return(AsyncInfo.Run <IStorageItem>(async(cancellationToken) =>
            {
                using var ftpClient = new FtpClient();
                ftpClient.Host = FtpHelpers.GetFtpHost(Path);
                ftpClient.Port = FtpHelpers.GetFtpPort(Path);
                ftpClient.Credentials = FtpManager.Credentials.Get(ftpClient.Host, FtpManager.Anonymous);

                if (!await ftpClient.EnsureConnectedAsync())
                {
                    return null;
                }

                var item = await ftpClient.GetObjectInfoAsync(FtpHelpers.GetFtpPath(PathNormalization.Combine(Path, name)));
                if (item != null)
                {
                    if (item.Type == FtpFileSystemObjectType.File)
                    {
                        return new FtpStorageFile(Path, item);
                    }
                    else if (item.Type == FtpFileSystemObjectType.Directory)
                    {
                        return new FtpStorageFolder(Path, item);
                    }
                }
                return null;
            }));
        }
Esempio n. 2
0
 public FtpStorageFolder(string folder, FtpListItem ftpItem)
 {
     DateCreated = ftpItem.RawCreated < DateTime.FromFileTimeUtc(0) ? DateTimeOffset.MinValue : ftpItem.RawCreated;
     Name        = ftpItem.Name;
     Path        = PathNormalization.Combine(folder, ftpItem.Name);
     FtpPath     = FtpHelpers.GetFtpPath(Path);
 }
        private static async Task <ListedItem> AddFileAsync(
            BaseStorageFile file,
            StorageFolderWithPath currentStorageFolder,
            string dateReturnFormat,
            CancellationToken cancellationToken
            )
        {
            var basicProperties = await file.GetBasicPropertiesAsync();

            // Display name does not include extension
            var itemName            = file.Name;
            var itemModifiedDate    = basicProperties.DateModified;
            var itemCreatedDate     = file.DateCreated;
            var itemPath            = string.IsNullOrEmpty(file.Path) ? PathNormalization.Combine(currentStorageFolder.Path, file.Name) : file.Path;
            var itemSize            = basicProperties.Size.ToSizeString();
            var itemSizeBytes       = basicProperties.Size;
            var itemType            = file.DisplayType;
            var itemFileExtension   = file.FileType;
            var itemThumbnailImgVis = false;

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            if (file.Name.EndsWith(".lnk", StringComparison.Ordinal) || file.Name.EndsWith(".url", StringComparison.Ordinal))
            {
                // This shouldn't happen, StorageFile api does not support shortcuts
                Debug.WriteLine("Something strange: StorageFile api returned a shortcut");
            }
            // TODO: is this needed to be handled here?
            else if (App.LibraryManager.TryGetLibrary(file.Path, out LibraryLocationItem library))
            {
                return(new LibraryItem(library)
                {
                    ItemDateModifiedReal = itemModifiedDate,
                    ItemDateCreatedReal = itemCreatedDate,
                });
            }
            else
            {
                return(new ListedItem(file.FolderRelativeId, dateReturnFormat)
                {
                    PrimaryItemAttribute = StorageItemTypes.File,
                    FileExtension = itemFileExtension,
                    IsHiddenItem = false,
                    Opacity = 1,
                    FileImage = null,
                    LoadFileIcon = itemThumbnailImgVis,
                    ItemNameRaw = itemName,
                    ItemDateModifiedReal = itemModifiedDate,
                    ItemDateCreatedReal = itemCreatedDate,
                    ItemType = itemType,
                    ItemPath = itemPath,
                    FileSize = itemSize,
                    FileSizeBytes = (long)itemSizeBytes,
                });
            }
            return(null);
        }
Esempio n. 4
0
        private static async Task <ListedItem> AddFolderAsync(BaseStorageFolder folder, StorageFolderWithPath currentStorageFolder, string dateReturnFormat, CancellationToken cancellationToken)
        {
            var basicProperties = await folder.GetBasicPropertiesAsync();

            if (!cancellationToken.IsCancellationRequested)
            {
                return(new ListedItem(folder.FolderRelativeId, dateReturnFormat)
                {
                    PrimaryItemAttribute = StorageItemTypes.Folder,
                    ItemName = folder.DisplayName,
                    ItemDateModifiedReal = basicProperties.DateModified,
                    ItemDateCreatedReal = folder.DateCreated,
                    ItemType = folder.DisplayType,
                    IsHiddenItem = false,
                    Opacity = 1,
                    LoadFolderGlyph = true,
                    FileImage = null,
                    LoadFileIcon = false,
                    ItemPath = string.IsNullOrEmpty(folder.Path) ? PathNormalization.Combine(currentStorageFolder.Path, folder.Name) : folder.Path,
                    LoadUnknownTypeGlyph = false,
                    FileSize = null,
                    FileSizeBytes = 0
                });
            }
            return(null);
        }
Esempio n. 5
0
        public async static Task <StorageFileWithPath> DangerousGetFileWithPathFromPathAsync(string value,
                                                                                             StorageFolderWithPath rootFolder   = null,
                                                                                             StorageFolderWithPath parentFolder = null)
        {
            if (rootFolder != null)
            {
                var currComponents = GetDirectoryPathComponents(value);

                if (parentFolder != null && value.IsSubPathOf(parentFolder.Path))
                {
                    var folder         = parentFolder.Folder;
                    var prevComponents = GetDirectoryPathComponents(parentFolder.Path);
                    var path           = parentFolder.Path;
                    foreach (var component in currComponents.ExceptBy(prevComponents, c => c.Path).SkipLast(1))
                    {
                        folder = await folder.GetFolderAsync(component.Title);

                        path = PathNormalization.Combine(path, folder.Name);
                    }
                    var file = await folder.GetFileAsync(currComponents.Last().Title);

                    path = PathNormalization.Combine(path, file.Name);
                    return(new StorageFileWithPath(file, path));
                }
                else if (value.IsSubPathOf(rootFolder.Path))
                {
                    var folder = rootFolder.Folder;
                    var path   = rootFolder.Path;
                    foreach (var component in currComponents.Skip(1).SkipLast(1))
                    {
                        folder = await folder.GetFolderAsync(component.Title);

                        path = PathNormalization.Combine(path, folder.Name);
                    }
                    var file = await folder.GetFileAsync(currComponents.Last().Title);

                    path = PathNormalization.Combine(path, file.Name);
                    return(new StorageFileWithPath(file, path));
                }
            }

            if (parentFolder != null && !Path.IsPathRooted(value))
            {
                // Relative path
                var fullPath = Path.GetFullPath(Path.Combine(parentFolder.Path, value));
                return(new StorageFileWithPath(await BaseStorageFile.GetFileFromPathAsync(fullPath)));
            }
            else
            {
                return(new StorageFileWithPath(await BaseStorageFile.GetFileFromPathAsync(value)));
            }
        }
Esempio n. 6
0
        public async static Task <IList <StorageFolderWithPath> > GetFoldersWithPathAsync(this StorageFolderWithPath parentFolder, string nameFilter, uint maxNumberOfItems = uint.MaxValue)
        {
            if (parentFolder == null)
            {
                return(null);
            }

            var queryOptions = new QueryOptions();

            queryOptions.ApplicationSearchFilter = $"System.FileName:{nameFilter}*";
            BaseStorageFolderQueryResult queryResult = parentFolder.Folder.CreateFolderQueryWithOptions(queryOptions);

            return((await queryResult.GetFoldersAsync(0, maxNumberOfItems)).Select(x => new StorageFolderWithPath(x, PathNormalization.Combine(parentFolder.Path, x.Name))).ToList());
        }
Esempio n. 7
0
 public async static Task <IList <StorageFileWithPath> > GetFilesWithPathAsync(this StorageFolderWithPath parentFolder, uint maxNumberOfItems = uint.MaxValue)
 {
     return((await parentFolder.Folder.GetFilesAsync(CommonFileQuery.DefaultQuery, 0, maxNumberOfItems))
            .Select(x => new StorageFileWithPath(x, PathNormalization.Combine(parentFolder.Path, x.Name))).ToList());
 }
        public static async Task <ListedItem> AddFileAsync(
            BaseStorageFile file,
            StorageFolderWithPath currentStorageFolder,
            CancellationToken cancellationToken
            )
        {
            var basicProperties = await file.GetBasicPropertiesAsync();

            // Display name does not include extension
            var itemName            = file.Name;
            var itemModifiedDate    = basicProperties.DateModified;
            var itemCreatedDate     = file.DateCreated;
            var itemPath            = string.IsNullOrEmpty(file.Path) ? PathNormalization.Combine(currentStorageFolder.Path, file.Name) : file.Path;
            var itemSize            = basicProperties.Size.ToSizeString();
            var itemSizeBytes       = basicProperties.Size;
            var itemType            = file.DisplayType;
            var itemFileExtension   = file.FileType;
            var itemThumbnailImgVis = false;

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            // TODO: is this needed to be handled here?
            if (App.LibraryManager.TryGetLibrary(file.Path, out LibraryLocationItem library))
            {
                return(new LibraryItem(library)
                {
                    ItemDateModifiedReal = itemModifiedDate,
                    ItemDateCreatedReal = itemCreatedDate,
                });
            }
            else
            {
                if (file is ShortcutStorageFile linkFile)
                {
                    var isUrl = linkFile.Name.EndsWith(".url", StringComparison.OrdinalIgnoreCase);
                    return(new ShortcutItem(file.FolderRelativeId)
                    {
                        PrimaryItemAttribute = StorageItemTypes.File,
                        FileExtension = itemFileExtension,
                        IsHiddenItem = false,
                        Opacity = 1,
                        FileImage = null,
                        LoadFileIcon = itemThumbnailImgVis,
                        LoadWebShortcutGlyph = isUrl,
                        ItemNameRaw = itemName,
                        ItemDateModifiedReal = itemModifiedDate,
                        ItemDateCreatedReal = itemCreatedDate,
                        ItemType = itemType,
                        ItemPath = itemPath,
                        FileSize = itemSize,
                        FileSizeBytes = (long)itemSizeBytes,
                        TargetPath = linkFile.TargetPath,
                        Arguments = linkFile.Arguments,
                        WorkingDirectory = linkFile.WorkingDirectory,
                        RunAsAdmin = linkFile.RunAsAdmin,
                        IsUrl = isUrl,
                    });
                }
                else if (file is BinStorageFile binFile)
                {
                    return(new RecycleBinItem(file.FolderRelativeId)
                    {
                        PrimaryItemAttribute = StorageItemTypes.File,
                        FileExtension = itemFileExtension,
                        IsHiddenItem = false,
                        Opacity = 1,
                        FileImage = null,
                        LoadFileIcon = itemThumbnailImgVis,
                        ItemNameRaw = itemName,
                        ItemDateModifiedReal = itemModifiedDate,
                        ItemDateCreatedReal = itemCreatedDate,
                        ItemType = itemType,
                        ItemPath = itemPath,
                        FileSize = itemSize,
                        FileSizeBytes = (long)itemSizeBytes,
                        ItemDateDeletedReal = binFile.DateDeleted,
                        ItemOriginalPath = binFile.OriginalPath
                    });
                }
                else
                {
                    return(new ListedItem(file.FolderRelativeId)
                    {
                        PrimaryItemAttribute = StorageItemTypes.File,
                        FileExtension = itemFileExtension,
                        IsHiddenItem = false,
                        Opacity = 1,
                        FileImage = null,
                        LoadFileIcon = itemThumbnailImgVis,
                        ItemNameRaw = itemName,
                        ItemDateModifiedReal = itemModifiedDate,
                        ItemDateCreatedReal = itemCreatedDate,
                        ItemType = itemType,
                        ItemPath = itemPath,
                        FileSize = itemSize,
                        FileSizeBytes = (long)itemSizeBytes,
                    });
                }
            }
            return(null);
        }
        public static async Task <ListedItem> AddFolderAsync(BaseStorageFolder folder, StorageFolderWithPath currentStorageFolder, CancellationToken cancellationToken)
        {
            var basicProperties = await folder.GetBasicPropertiesAsync();

            if (!cancellationToken.IsCancellationRequested)
            {
                if (folder is ShortcutStorageFolder linkFolder)
                {
                    return(new ShortcutItem(folder.FolderRelativeId)
                    {
                        PrimaryItemAttribute = StorageItemTypes.Folder,
                        IsHiddenItem = false,
                        Opacity = 1,
                        FileImage = null,
                        LoadFileIcon = false,
                        ItemNameRaw = folder.DisplayName,
                        ItemDateModifiedReal = basicProperties.DateModified,
                        ItemDateCreatedReal = folder.DateCreated,
                        ItemType = folder.DisplayType,
                        ItemPath = folder.Path,
                        FileSize = null,
                        FileSizeBytes = 0,
                        TargetPath = linkFolder.TargetPath,
                        Arguments = linkFolder.Arguments,
                        WorkingDirectory = linkFolder.WorkingDirectory,
                        RunAsAdmin = linkFolder.RunAsAdmin
                    });
                }
                else if (folder is BinStorageFolder binFolder)
                {
                    return(new RecycleBinItem(folder.FolderRelativeId)
                    {
                        PrimaryItemAttribute = StorageItemTypes.Folder,
                        ItemNameRaw = folder.DisplayName,
                        ItemDateModifiedReal = basicProperties.DateModified,
                        ItemDateCreatedReal = folder.DateCreated,
                        ItemType = folder.DisplayType,
                        IsHiddenItem = false,
                        Opacity = 1,
                        FileImage = null,
                        LoadFileIcon = false,
                        ItemPath = string.IsNullOrEmpty(folder.Path) ? PathNormalization.Combine(currentStorageFolder.Path, folder.Name) : folder.Path,
                        FileSize = null,
                        FileSizeBytes = 0,
                        ItemDateDeletedReal = binFolder.DateDeleted,
                        ItemOriginalPath = binFolder.OriginalPath,
                    });
                }
                else
                {
                    return(new ListedItem(folder.FolderRelativeId)
                    {
                        PrimaryItemAttribute = StorageItemTypes.Folder,
                        ItemNameRaw = folder.DisplayName,
                        ItemDateModifiedReal = basicProperties.DateModified,
                        ItemDateCreatedReal = folder.DateCreated,
                        ItemType = folder.DisplayType,
                        IsHiddenItem = false,
                        Opacity = 1,
                        FileImage = null,
                        LoadFileIcon = false,
                        ItemPath = string.IsNullOrEmpty(folder.Path) ? PathNormalization.Combine(currentStorageFolder.Path, folder.Name) : folder.Path,
                        FileSize = null,
                        FileSizeBytes = 0
                    });
                }
            }
            return(null);
        }