public static string GetDriveTypeIcon(System.IO.DriveInfo drive)
        {
            string type;

            switch (drive.DriveType)
            {
            case System.IO.DriveType.CDRom:
                type = "\xE958";
                break;

            case System.IO.DriveType.Fixed:
                type = "\xEDA2";
                break;

            case System.IO.DriveType.Network:
                type = "\xE8CE";
                break;

            case System.IO.DriveType.NoRootDirectory:
                type = "\xED25";
                break;

            case System.IO.DriveType.Ram:
                type = "\xE950";
                break;

            case System.IO.DriveType.Removable:
                type = "\xE88E";
                break;

            case System.IO.DriveType.Unknown:
                if (PathNormalization.NormalizePath(drive.Name) != PathNormalization.NormalizePath("A:") && PathNormalization.NormalizePath(drive.Name) != PathNormalization.NormalizePath("B:"))
                {
                    type = "\xEDA2";
                }
                else
                {
                    type = "\xE74E";     // Floppy icon
                }
                break;

            default:
                type = "\xEDA2";     // Drive icon
                break;
            }

            return(type);
        }
Example #2
0
 public static Func <ListedItem, string> GetItemGroupKeySelector(GroupOption option)
 {
     return(option switch
     {
         GroupOption.Name => x => new string(x.ItemName.Take(1).ToArray()).ToUpperInvariant(),
         GroupOption.Size => x => x.PrimaryItemAttribute != StorageItemTypes.Folder ? GetGroupSizeKey(x.FileSizeBytes) : x.FileSizeDisplay,
         GroupOption.DateCreated => x => x.ItemDateCreatedReal.GetUserSettingsFriendlyTimeSpan().text,
         GroupOption.DateModified => x => x.ItemDateModifiedReal.GetUserSettingsFriendlyTimeSpan().text,
         GroupOption.FileType => x => x.PrimaryItemAttribute == StorageItemTypes.Folder && !x.IsShortcutItem ? x.ItemType : x.FileExtension?.ToLowerInvariant() ?? " ",
         GroupOption.SyncStatus => x => x.SyncStatusString,
         GroupOption.FileTag => x => x.FileTag,
         GroupOption.OriginalFolder => x => (x as RecycleBinItem)?.ItemOriginalFolder,
         GroupOption.DateDeleted => x => (x as RecycleBinItem)?.ItemDateDeletedReal.GetUserSettingsFriendlyTimeSpan().text,
         GroupOption.FolderPath => x => PathNormalization.GetParentDir(x.ItemPath.TrimPath()),
         _ => null,
     });
Example #3
0
        public static PostedStatusBanner PostBanner_Move(IEnumerable <IStorageItemWithPath> source, IEnumerable <string> destination, ReturnResult returnStatus, bool canceled, int itemsMoved)
        {
            var sourceDir      = PathNormalization.GetParentDir(source.FirstOrDefault()?.Path);
            var destinationDir = PathNormalization.GetParentDir(destination.FirstOrDefault());

            if (canceled)
            {
                return(OngoingTasksViewModel.PostBanner(
                           "StatusMoveCanceled".GetLocalized(),
                           string.Format(source.Count() > 1 ?
                                         itemsMoved > 1 ? "StatusMoveCanceledDetails_Plural".GetLocalized() : "StatusMoveCanceledDetails_Plural2".GetLocalized()
                        : "StatusMoveCanceledDetails_Singular".GetLocalized(), source.Count(), sourceDir, destinationDir, itemsMoved),
                           0,
                           ReturnResult.Cancelled,
                           FileOperationType.Move));
            }
            else if (returnStatus == ReturnResult.InProgress)
            {
                return(OngoingTasksViewModel.PostOperationBanner(
                           string.Empty,
                           string.Format(source.Count() > 1 ? "StatusMovingItemsDetails_Plural".GetLocalized() : "StatusMovingItemsDetails_Singular".GetLocalized(), source.Count(), sourceDir, destinationDir),
                           0,
                           ReturnResult.InProgress,
                           FileOperationType.Move, new CancellationTokenSource()));
            }
            else if (returnStatus == ReturnResult.Success)
            {
                return(OngoingTasksViewModel.PostBanner(
                           "StatusMoveComplete".GetLocalized(),
                           string.Format(source.Count() > 1 ? "StatusMovedItemsDetails_Plural".GetLocalized() : "StatusMovedItemsDetails_Singular".GetLocalized(), source.Count(), sourceDir, destinationDir, itemsMoved),
                           0,
                           ReturnResult.Success,
                           FileOperationType.Move));
            }
            else
            {
                return(OngoingTasksViewModel.PostBanner(
                           "StatusMoveFailed".GetLocalized(),
                           string.Format(source.Count() > 1 ? "StatusMoveFailedDetails_Plural".GetLocalized() : "StatusMoveFailedDetails_Singular".GetLocalized(), source.Count(), sourceDir, destinationDir),
                           0,
                           ReturnResult.Failed,
                           FileOperationType.Move));
            }
        }
Example #4
0
        public static async Task <IStorageItem> CreateFileFromDialogResultTypeForResult(AddItemType itemType, ShellNewEntry itemInfo, IShellPage associatedInstance)
        {
            string currentPath = null;

            if (associatedInstance.SlimContentPage != null)
            {
                currentPath = associatedInstance.FilesystemViewModel.WorkingDirectory;
                if (App.LibraryManager.TryGetLibrary(currentPath, out var library))
                {
                    if (!library.IsEmpty && library.Folders.Count == 1) // TODO: handle libraries with multiple folders
                    {
                        currentPath = library.Folders.First();
                    }
                }
            }

            // Show rename dialog
            DynamicDialog dialog = DynamicDialogFactory.GetFor_RenameDialog();
            await dialog.ShowAsync();

            if (dialog.DynamicResult != DynamicDialogResult.Primary)
            {
                return(null);
            }

            // Create file based on dialog result
            string userInput = dialog.ViewModel.AdditionalData as string;
            var    folderRes = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(currentPath);

            var created = new FilesystemResult <(ReturnResult, IStorageItem)>((ReturnResult.Failed, null), FileSystemStatusCode.Generic);

            if (folderRes)
            {
                switch (itemType)
                {
                case AddItemType.Folder:
                    userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized();
                    created   = await FilesystemTasks.Wrap(async() =>
                    {
                        return(await associatedInstance.FilesystemHelpers.CreateAsync(
                                   StorageHelpers.FromPathAndType(PathNormalization.Combine(folderRes.Result.Path, userInput), FilesystemItemType.Directory),
                                   true));
                    });

                    break;

                case AddItemType.File:
                    userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : itemInfo?.Name ?? "NewFile".GetLocalized();
                    created   = await FilesystemTasks.Wrap(async() =>
                    {
                        return(await associatedInstance.FilesystemHelpers.CreateAsync(
                                   StorageHelpers.FromPathAndType(PathNormalization.Combine(folderRes.Result.Path, userInput + itemInfo?.Extension), FilesystemItemType.File),
                                   true));
                    });

                    break;
                }
            }

            if (created == FileSystemStatusCode.Unauthorized)
            {
                await DialogDisplayHelper.ShowDialogAsync("AccessDenied".GetLocalized(), "AccessDeniedCreateDialog/Text".GetLocalized());
            }

            return(created.Result.Item2);
        }
Example #5
0
        private static async Task <FilesystemResult> OpenFile(string path, IShellPage associatedInstance, IEnumerable <string> selectItems, ShortcutItem shortcutInfo, bool openViaApplicationPicker = false, string args = default)
        {
            var  opened         = (FilesystemResult)false;
            bool isHiddenItem   = NativeFileOperationsHelper.HasFileAttribute(path, System.IO.FileAttributes.Hidden);
            bool isShortcutItem = path.EndsWith(".lnk") || path.EndsWith(".url"); // Determine

            if (isShortcutItem)
            {
                if (string.IsNullOrEmpty(shortcutInfo.TargetPath))
                {
                    await Win32Helpers.InvokeWin32ComponentAsync(path, associatedInstance, args);
                }
                else
                {
                    if (!path.EndsWith(".url"))
                    {
                        StorageFileWithPath childFile = await associatedInstance.FilesystemViewModel.GetFileWithPathFromPathAsync(shortcutInfo.TargetPath);

                        if (childFile != null)
                        {
                            // Add location to MRU List
                            if (childFile.File is SystemStorageFile)
                            {
                                var mostRecentlyUsed = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList;
                                mostRecentlyUsed.Add(await childFile.File.ToStorageFileAsync(), childFile.Path);
                            }
                        }
                    }
                    await Win32Helpers.InvokeWin32ComponentAsync(shortcutInfo.TargetPath, associatedInstance, $"{args} {shortcutInfo.Arguments}", shortcutInfo.RunAsAdmin, shortcutInfo.WorkingDirectory);
                }
                opened = (FilesystemResult)true;
            }
            else if (isHiddenItem)
            {
                await Win32Helpers.InvokeWin32ComponentAsync(path, associatedInstance, args);
            }
            else
            {
                opened = await associatedInstance.FilesystemViewModel.GetFileWithPathFromPathAsync(path)
                         .OnSuccess(async childFile =>
                {
                    // Add location to MRU List
                    if (childFile.File is SystemStorageFile)
                    {
                        var mostRecentlyUsed = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList;
                        mostRecentlyUsed.Add(await childFile.File.ToStorageFileAsync(), childFile.Path);
                    }

                    if (openViaApplicationPicker)
                    {
                        LauncherOptions options = new LauncherOptions
                        {
                            DisplayApplicationPicker = true
                        };
                        if (!await Launcher.LaunchFileAsync(childFile.File, options))
                        {
                            var connection = await AppServiceConnectionHelper.Instance;
                            if (connection != null)
                            {
                                await connection.SendMessageAsync(new ValueSet()
                                {
                                    { "Arguments", "InvokeVerb" },
                                    { "FilePath", path },
                                    { "Verb", "openas" }
                                });
                            }
                        }
                    }
                    else
                    {
                        //try using launcher first
                        bool launchSuccess = false;

                        BaseStorageFileQueryResult fileQueryResult = null;

                        //Get folder to create a file query (to pass to apps like Photos, Movies & TV..., needed to scroll through the folder like what Windows Explorer does)
                        BaseStorageFolder currentFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(PathNormalization.GetParentDir(path));

                        if (currentFolder != null)
                        {
                            QueryOptions queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, null);

                            //We can have many sort entries
                            SortEntry sortEntry = new SortEntry()
                            {
                                AscendingOrder = associatedInstance.InstanceViewModel.FolderSettings.DirectorySortDirection == SortDirection.Ascending
                            };

                            //Basically we tell to the launched app to follow how we sorted the files in the directory.
                            var sortOption = associatedInstance.InstanceViewModel.FolderSettings.DirectorySortOption;

                            switch (sortOption)
                            {
                            case Enums.SortOption.Name:
                                sortEntry.PropertyName = "System.ItemNameDisplay";
                                queryOptions.SortOrder.Clear();
                                queryOptions.SortOrder.Add(sortEntry);
                                break;

                            case Enums.SortOption.DateModified:
                                sortEntry.PropertyName = "System.DateModified";
                                queryOptions.SortOrder.Clear();
                                queryOptions.SortOrder.Add(sortEntry);
                                break;

                            case Enums.SortOption.DateCreated:
                                sortEntry.PropertyName = "System.DateCreated";
                                queryOptions.SortOrder.Clear();
                                queryOptions.SortOrder.Add(sortEntry);
                                break;

                            //Unfortunately this is unsupported | Remarks: https://docs.microsoft.com/en-us/uwp/api/windows.storage.search.queryoptions.sortorder?view=winrt-19041
                            //case Enums.SortOption.Size:

                            //sortEntry.PropertyName = "System.TotalFileSize";
                            //queryOptions.SortOrder.Clear();
                            //queryOptions.SortOrder.Add(sortEntry);
                            //break;

                            //Unfortunately this is unsupported | Remarks: https://docs.microsoft.com/en-us/uwp/api/windows.storage.search.queryoptions.sortorder?view=winrt-19041
                            //case Enums.SortOption.FileType:

                            //sortEntry.PropertyName = "System.FileExtension";
                            //queryOptions.SortOrder.Clear();
                            //queryOptions.SortOrder.Add(sortEntry);
                            //break;

                            //Handle unsupported
                            default:
                                //keep the default one in SortOrder IList
                                break;
                            }

                            var options = new LauncherOptions();
                            if (currentFolder.AreQueryOptionsSupported(queryOptions))
                            {
                                fileQueryResult = currentFolder.CreateFileQueryWithOptions(queryOptions);
                                options.NeighboringFilesQuery = fileQueryResult.ToStorageFileQueryResult();
                            }

                            // Now launch file with options.
                            launchSuccess = await Launcher.LaunchFileAsync(await childFile.File.ToStorageFileAsync(), options);
                        }

                        if (!launchSuccess)
                        {
                            await Win32Helpers.InvokeWin32ComponentAsync(path, associatedInstance, args);
                        }
                    }
                });
            }
            return(opened);
        }
Example #6
0
        public static PostedStatusBanner PostBanner_Delete(IEnumerable <IStorageItemWithPath> source, ReturnResult returnStatus, bool permanently, bool canceled, int itemsDeleted)
        {
            var sourceDir = PathNormalization.GetParentDir(source.FirstOrDefault()?.Path);

            if (canceled)
            {
                if (permanently)
                {
                    return(OngoingTasksViewModel.PostBanner(
                               "StatusDeletionCancelled".GetLocalized(),
                               string.Format(source.Count() > 1 ?
                                             itemsDeleted > 1 ? "StatusDeleteCanceledDetails_Plural".GetLocalized() : "StatusDeleteCanceledDetails_Plural2".GetLocalized()
                            : "StatusDeleteCanceledDetails_Singular".GetLocalized(), source.Count(), sourceDir, null, itemsDeleted),
                               0,
                               ReturnResult.Cancelled,
                               FileOperationType.Delete));
                }
                else
                {
                    return(OngoingTasksViewModel.PostBanner(
                               "StatusRecycleCancelled".GetLocalized(),
                               string.Format(source.Count() > 1 ?
                                             itemsDeleted > 1 ? "StatusMoveCanceledDetails_Plural".GetLocalized() : "StatusMoveCanceledDetails_Plural2".GetLocalized()
                            : "StatusMoveCanceledDetails_Singular".GetLocalized(), source.Count(), sourceDir, "TheRecycleBin".GetLocalized(), itemsDeleted),
                               0,
                               ReturnResult.Cancelled,
                               FileOperationType.Recycle));
                }
            }
            else if (returnStatus == ReturnResult.InProgress)
            {
                if (permanently)
                {
                    // deleting items from <x>
                    return(OngoingTasksViewModel.PostOperationBanner(string.Empty,
                                                                     string.Format(source.Count() > 1 ? "StatusDeletingItemsDetails_Plural".GetLocalized() : "StatusDeletingItemsDetails_Singular".GetLocalized(), source.Count(), sourceDir),
                                                                     0,
                                                                     ReturnResult.InProgress,
                                                                     FileOperationType.Delete,
                                                                     new CancellationTokenSource()));
                }
                else
                {
                    // "Moving items from <x> to recycle bin"
                    return(OngoingTasksViewModel.PostOperationBanner(string.Empty,
                                                                     string.Format(source.Count() > 1 ? "StatusMovingItemsDetails_Plural".GetLocalized() : "StatusMovingItemsDetails_Singular".GetLocalized(), source.Count(), sourceDir, "TheRecycleBin".GetLocalized()),
                                                                     0,
                                                                     ReturnResult.InProgress,
                                                                     FileOperationType.Recycle,
                                                                     new CancellationTokenSource()));
                }
            }
            else if (returnStatus == ReturnResult.Success)
            {
                if (permanently)
                {
                    return(OngoingTasksViewModel.PostBanner(
                               "StatusDeletionComplete".GetLocalized(),
                               string.Format(source.Count() > 1 ? "StatusDeletedItemsDetails_Plural".GetLocalized() : "StatusDeletedItemsDetails_Singular".GetLocalized(), source.Count(), sourceDir, itemsDeleted),
                               0,
                               ReturnResult.Success,
                               FileOperationType.Delete));
                }
                else
                {
                    return(OngoingTasksViewModel.PostBanner(
                               "StatusRecycleComplete".GetLocalized(),
                               string.Format(source.Count() > 1 ? "StatusMovedItemsDetails_Plural".GetLocalized() : "StatusMovedItemsDetails_Singular".GetLocalized(), source.Count(), sourceDir, "TheRecycleBin".GetLocalized()),
                               0,
                               ReturnResult.Success,
                               FileOperationType.Recycle));
                }
            }
            else
            {
                if (permanently)
                {
                    return(OngoingTasksViewModel.PostBanner(
                               "StatusDeletionFailed".GetLocalized(),
                               string.Format(source.Count() > 1 ? "StatusDeletionFailedDetails_Plural".GetLocalized() : "StatusDeletionFailedDetails_Singular".GetLocalized(), source.Count(), sourceDir),
                               0,
                               ReturnResult.Failed,
                               FileOperationType.Delete));
                }
                else
                {
                    return(OngoingTasksViewModel.PostBanner(
                               "StatusRecycleFailed".GetLocalized(),
                               string.Format(source.Count() > 1 ? "StatusMoveFailedDetails_Plural".GetLocalized() : "StatusMoveFailedDetails_Singular".GetLocalized(), source.Count(), sourceDir, "TheRecycleBin".GetLocalized()),
                               0,
                               ReturnResult.Failed,
                               FileOperationType.Recycle));
                }
            }
        }