public async void RotateImageRight()
        {
            await BitmapHelper.Rotate(PathNormalization.NormalizePath(SlimContentPage?.SelectedItems.First().ItemPath), BitmapRotation.Clockwise90Degrees);

            SlimContentPage?.ItemManipulationModel.RefreshItemsThumbnail();
            SlimContentPage?.PreviewPaneViewModel.UpdateSelectedItemPreview();
        }
Пример #2
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);
        }
Пример #3
0
 public void SetSelectedPathOrNavigate(PathNavigationEventArgs e)
 {
     if (ColumnHost.ActiveBlades?.Count > 1)
     {
         foreach (var item in ColumnHost.ActiveBlades)
         {
             if ((item.Content as Frame)?.Content is ColumnShellPage s &&
                 PathNormalization.NormalizePath(s.FilesystemViewModel.WorkingDirectory) ==
                 PathNormalization.NormalizePath(e.ItemPath))
             {
                 DismissOtherBlades(item);
                 return;
             }
         }
     }
     if (PathNormalization.NormalizePath(ParentShellPageInstance.FilesystemViewModel.WorkingDirectory) !=
         PathNormalization.NormalizePath(e.ItemPath))
     {
         ParentShellPageInstance.NavigateToPath(e.ItemPath);
     }
     else
     {
         DismissOtherBlades(ColumnHost.ActiveBlades[0]);
     }
 }
Пример #4
0
 public static string NormalizePath(string path,
                                    PathNormalization leadingNormalization  = PathNormalization.IncludeSlash,
                                    PathNormalization trailingNormalization = PathNormalization.None,
                                    bool canonicalize = false)
 {
     return(NormalizePathSegment(path, leadingNormalization, trailingNormalization, canonicalize).Value);
 }
Пример #5
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;
            }));
        }
Пример #6
0
        public override IAsyncAction RenameAsync(string desiredName, NameCollisionOption option)
        {
            return(AsyncInfo.Run(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;
                }

                if (!await ftpClient.MoveDirectoryAsync(FtpPath,
                                                        $"{PathNormalization.GetParentDir(FtpPath)}/{desiredName}",
                                                        option == NameCollisionOption.ReplaceExisting ? FtpRemoteExists.Overwrite : FtpRemoteExists.Skip,
                                                        cancellationToken))
                {
                    if (option == NameCollisionOption.GenerateUniqueName)
                    {
                        // TODO: handle name generation
                    }
                }
            }));
        }
Пример #7
0
        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);
        }
Пример #8
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);
 }
Пример #9
0
        public async Task RotateImageRight()
        {
            foreach (var image in SlimContentPage.SelectedItems)
            {
                await BitmapHelper.Rotate(PathNormalization.NormalizePath(image.ItemPath), BitmapRotation.Clockwise90Degrees);
            }

            SlimContentPage.ItemManipulationModel.RefreshItemsThumbnail();
            App.PreviewPaneViewModel.UpdateSelectedItemPreview();
        }
Пример #10
0
        public static StringSegment NormalizePathSegment(StringSegment path,
                                                         PathNormalization leadingNormalization  = PathNormalization.IncludeSlash,
                                                         PathNormalization trailingNormalization = PathNormalization.None,
                                                         bool canonicalize = false)
        {
            if (!path.HasValue)
            {
                path = StringSegment.Empty;
            }

            if (canonicalize)
            {
                path = GetCanonicalPath(path.Value);
            }

            int pathLength = path.Length;

            switch (leadingNormalization)
            {
            case PathNormalization.IncludeSlash:
                if (pathLength == 0 || path[0] != '/')
                {
                    path = "/" + path;
                    pathLength++;
                }
                break;

            case PathNormalization.ExcludeSlash:
                if (pathLength > 0 && path[0] == '/' && (pathLength > 1 || trailingNormalization != PathNormalization.IncludeSlash))
                {
                    path = path.Subsegment(1);
                    pathLength--;
                }
                break;
            }

            switch (trailingNormalization)
            {
            case PathNormalization.IncludeSlash:
                if (pathLength == 0 || path[path.Length - 1] != '/')
                {
                    path = path + "/";
                }
                break;

            case PathNormalization.ExcludeSlash:
                if (pathLength > 0 && path[path.Length - 1] == '/' && (pathLength > 1 || leadingNormalization != PathNormalization.IncludeSlash))
                {
                    path = path.Subsegment(0, pathLength - 1);
                }
                break;
            }

            return(path);
        }
Пример #11
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)));
            }
        }
Пример #12
0
        public static async Task <FilesystemResult <BaseStorageFile> > Create(this ShellNewEntry shellEntry, BaseStorageFolder parentFolder, string filePath)
        {
            FilesystemResult <BaseStorageFile> createdFile = null;
            var fileName = Path.GetFileName(filePath);

            if (!fileName.EndsWith(shellEntry.Extension, StringComparison.Ordinal))
            {
                fileName += shellEntry.Extension;
            }
            if (shellEntry.Command != null)
            {
                var args = CommandLine.CommandLineParser.SplitArguments(shellEntry.Command);
                if (args.Any())
                {
                    var connection = await AppServiceConnectionHelper.Instance;
                    if (connection != null)
                    {
                        _ = await connection.SendMessageForResponseAsync(new ValueSet()
                        {
                            { "Arguments", "LaunchApp" },
                            { "WorkingDirectory", PathNormalization.GetParentDir(filePath) },
                            { "Application", args[0].Replace("\"", "", StringComparison.Ordinal) },
                            { "Parameters", string.Join(" ", args.Skip(1)).Replace("%1", filePath) }
                        });
                    }
                }
                createdFile = new FilesystemResult <BaseStorageFile>(null, Shared.Enums.FileSystemStatusCode.Success);
            }
            else if (shellEntry.Template == null)
            {
                createdFile = await FilesystemTasks.Wrap(() => parentFolder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName).AsTask());
            }
            else
            {
                createdFile = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileFromPathAsync(shellEntry.Template))
                              .OnSuccess(t => t.CopyAsync(parentFolder, fileName, NameCollisionOption.GenerateUniqueName).AsTask());
            }
            if (createdFile)
            {
                if (shellEntry.Data != null)
                {
                    //await FileIO.WriteBytesAsync(createdFile.Result, shellEntry.Data); // Calls unsupported OpenTransactedWriteAsync
                    await createdFile.Result.WriteBytesAsync(shellEntry.Data);
                }
            }
            return(createdFile);
        }
Пример #13
0
        public override IAsyncAction RenameAsync(string desiredName, NameCollisionOption option)
        {
            return(AsyncInfo.Run(async(cancellationToken) =>
            {
                using var ftpClient = GetFtpClient();
                if (!await ftpClient.EnsureConnectedAsync())
                {
                    return;
                }

                string destination = $"{PathNormalization.GetParentDir(FtpPath)}/{desiredName}";
                var remoteExists = option is NameCollisionOption.ReplaceExisting ? FtpRemoteExists.Overwrite : FtpRemoteExists.Skip;
                bool isSuccessful = await ftpClient.MoveFileAsync(FtpPath, destination, remoteExists, cancellationToken);
                if (!isSuccessful && option is NameCollisionOption.GenerateUniqueName)
                {
                    // TODO: handle name generation
                }
            }));
        }
Пример #14
0
        public static string NormalizePath(string path,
                                           PathNormalization leadingNormalization  = PathNormalization.IncludeSlash,
                                           PathNormalization trailingNormalization = PathNormalization.None,
                                           bool canonicalize = false)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (canonicalize)
            {
                path = s_getCanonicalPath.Value(path);
            }

            switch (leadingNormalization)
            {
            case PathNormalization.IncludeSlash:
                path = path.StartsWith("/") ? path : '/' + path;
                break;

            case PathNormalization.ExcludeSlash:
                path = path.StartsWith("/") ? path.Substring(1) : path;
                break;
            }

            switch (trailingNormalization)
            {
            case PathNormalization.IncludeSlash:
                path = path.EndsWith("/") ? path : path + '/';
                break;

            case PathNormalization.ExcludeSlash:
                path = path.EndsWith("/") ? path.Substring(0, path.Length - 1) : path;
                break;
            }

            return(path);
        }
        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);
        }
Пример #16
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());
        }
Пример #17
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());
 }
Пример #18
0
        public static async Task <FilesystemResult <BaseStorageFile> > Create(this ShellNewEntry shellEntry, string filePath, IShellPage associatedInstance)
        {
            var parentFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(PathNormalization.GetParentDir(filePath));

            if (parentFolder)
            {
                return(await Create(shellEntry, parentFolder, Path.GetFileName(filePath)));
            }
            return(new FilesystemResult <BaseStorageFile>(null, parentFolder.ErrorCode));
        }
        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);
        }