Ejemplo n.º 1
0
        public static async Task <FilesystemResult <IStorageItem> > ToStorageItemResult(this IStorageItemWithPath item, IShellPage associatedInstance = null)
        {
            var returnedItem = new FilesystemResult <IStorageItem>(null, FileSystemStatusCode.Generic);

            if (!string.IsNullOrEmpty(item.Path))
            {
                returnedItem = (item.ItemType == FilesystemItemType.File) ?
                               ToType <IStorageItem, StorageFile>(associatedInstance != null ?
                                                                  await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(item.Path) :
                                                                  await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileFromPathAsync(item.Path))) :
                               ToType <IStorageItem, StorageFolder>(associatedInstance != null ?
                                                                    await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(item.Path) :
                                                                    await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(item.Path)));
            }
            if (returnedItem.Result == null && item.Item != null)
            {
                returnedItem = new FilesystemResult <IStorageItem>(item.Item, FileSystemStatusCode.Success);
            }
            return(returnedItem);
        }
 public FilesystemOperations(IShellPage associatedInstance)
 {
     this.associatedInstance = associatedInstance;
     recycleBinHelpers       = new RecycleBinHelpers(this.associatedInstance);
 }
Ejemplo n.º 3
0
        private async Task <string> GetHashForFileAsync(ListedItem fileItem, string nameOfAlg, CancellationToken token, ProgressBar progress, IShellPage associatedInstance)
        {
            HashAlgorithmProvider algorithmProvider = HashAlgorithmProvider.OpenAlgorithm(nameOfAlg);
            StorageFile           file = await StorageItemHelpers.ToStorageItem <StorageFile>((fileItem as ShortcutItem)?.TargetPath ?? fileItem.ItemPath, associatedInstance);

            if (file == null)
            {
                return("");
            }

            Stream stream = await FilesystemTasks.Wrap(() => file.OpenStreamForReadAsync());

            if (stream == null)
            {
                return("");
            }

            var  inputStream = stream.AsInputStream();
            var  str         = inputStream.AsStreamForRead();
            var  cap         = (long)(0.5 * str.Length) / 100;
            uint capacity;

            if (cap >= uint.MaxValue)
            {
                capacity = uint.MaxValue;
            }
            else
            {
                capacity = Convert.ToUInt32(cap);
            }

            Windows.Storage.Streams.Buffer buffer = new Windows.Storage.Streams.Buffer(capacity);
            var hash = algorithmProvider.CreateHash();

            while (!token.IsCancellationRequested)
            {
                await inputStream.ReadAsync(buffer, capacity, InputStreamOptions.None);

                if (buffer.Length > 0)
                {
                    hash.Append(buffer);
                }
                else
                {
                    break;
                }
                if (progress != null)
                {
                    progress.Value = (double)str.Position / str.Length * 100;
                }
            }
            inputStream.Dispose();
            stream.Dispose();
            if (token.IsCancellationRequested)
            {
                return("");
            }
            return(CryptographicBuffer.EncodeToHexString(hash.GetValueAndReset()).ToLower());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Navigates to a directory or opens file
        /// </summary>
        /// <param name="path">The path to navigate to or open</param>
        /// <param name="associatedInstance">The instance associated with view</param>
        /// <param name="itemType"></param>
        /// <param name="openSilent">Determines whether history of opened item is saved (... to Recent Items/Windows Timeline/opening in background)</param>
        /// <param name="openViaApplicationPicker">Determines whether open file using application picker</param>
        /// <param name="selectItems">List of filenames that are selected upon navigation</param>
        /// <param name="forceOpenInNewTab">Open folders in a new tab regardless of the "OpenFoldersInNewTab" option</param>
        public static async Task <bool> OpenPath(string path, IShellPage associatedInstance, FilesystemItemType?itemType = null, bool openSilent = false, bool openViaApplicationPicker = false, IEnumerable <string> selectItems = null, string args = default, bool forceOpenInNewTab = false)
        {
            string           previousDir    = associatedInstance.FilesystemViewModel.WorkingDirectory;
            bool             isHiddenItem   = NativeFileOperationsHelper.HasFileAttribute(path, System.IO.FileAttributes.Hidden);
            bool             isDirectory    = NativeFileOperationsHelper.HasFileAttribute(path, System.IO.FileAttributes.Directory);
            bool             isReparsePoint = NativeFileOperationsHelper.HasFileAttribute(path, System.IO.FileAttributes.ReparsePoint);
            bool             isShortcutItem = path.EndsWith(".lnk", StringComparison.Ordinal) || path.EndsWith(".url", StringComparison.Ordinal);
            FilesystemResult opened         = (FilesystemResult)false;

            var shortcutInfo = new ShellLinkItem();

            if (itemType == null || isShortcutItem || isHiddenItem || isReparsePoint)
            {
                if (isShortcutItem)
                {
                    var connection = await AppServiceConnectionHelper.Instance;
                    if (connection == null)
                    {
                        return(false);
                    }
                    var(status, response) = await connection.SendMessageForResponseAsync(new ValueSet()
                    {
                        { "Arguments", "FileOperation" },
                        { "fileop", "ParseLink" },
                        { "filepath", path }
                    });

                    if (status == AppServiceResponseStatus.Success && response.ContainsKey("ShortcutInfo"))
                    {
                        var shInfo = JsonConvert.DeserializeObject <ShellLinkItem>((string)response["ShortcutInfo"]);
                        if (shInfo != null)
                        {
                            shortcutInfo = shInfo;
                        }
                        itemType = shInfo != null && shInfo.IsFolder ? FilesystemItemType.Directory : FilesystemItemType.File;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (isReparsePoint)
                {
                    if (!isDirectory)
                    {
                        if (NativeFindStorageItemHelper.GetWin32FindDataForPath(path, out var findData))
                        {
                            if (findData.dwReserved0 == NativeFileOperationsHelper.IO_REPARSE_TAG_SYMLINK)
                            {
                                shortcutInfo.TargetPath = NativeFileOperationsHelper.ParseSymLink(path);
                            }
                        }
                    }
                    itemType ??= isDirectory ? FilesystemItemType.Directory : FilesystemItemType.File;
                }
                else if (isHiddenItem)
                {
                    itemType = NativeFileOperationsHelper.HasFileAttribute(path, System.IO.FileAttributes.Directory) ? FilesystemItemType.Directory : FilesystemItemType.File;
                }
                else
                {
                    itemType = await StorageHelpers.GetTypeFromPath(path);
                }
            }

            if (itemType == FilesystemItemType.Library)
            {
                opened = await OpenLibrary(path, associatedInstance, selectItems, forceOpenInNewTab);
            }
            else if (itemType == FilesystemItemType.Directory)
            {
                opened = await OpenDirectory(path, associatedInstance, selectItems, shortcutInfo, forceOpenInNewTab);
            }
            else if (itemType == FilesystemItemType.File)
            {
                opened = await OpenFile(path, associatedInstance, selectItems, shortcutInfo, openViaApplicationPicker, args);
            }

            if (opened.ErrorCode == FileSystemStatusCode.NotFound && !openSilent)
            {
                await DialogDisplayHelper.ShowDialogAsync("FileNotFoundDialog/Title".GetLocalized(), "FileNotFoundDialog/Text".GetLocalized());

                associatedInstance.ToolbarViewModel.CanRefresh = false;
                associatedInstance.FilesystemViewModel?.RefreshItems(previousDir);
            }

            return(opened);
        }
Ejemplo n.º 5
0
        private static async Task <FilesystemResult> OpenFile(string path, IShellPage associatedInstance, IEnumerable <string> selectItems, ShellLinkItem 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", StringComparison.Ordinal) || path.EndsWith(".url", StringComparison.Ordinal) || !string.IsNullOrEmpty(shortcutInfo.TargetPath);

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

                        if (childFile != null)
                        {
                            // Add location to Recent Items List
                            if (childFile.Item is SystemStorageFile)
                            {
                                await App.RecentItemsManager.AddToRecentItems(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 Recent Items List
                    if (childFile.Item is SystemStorageFile)
                    {
                        await App.RecentItemsManager.AddToRecentItems(childFile.Path);
                    }

                    if (openViaApplicationPicker)
                    {
                        LauncherOptions options = new LauncherOptions
                        {
                            DisplayApplicationPicker = true
                        };
                        if (!await Launcher.LaunchFileAsync(childFile.Item, 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 SortOption.Name:
                                sortEntry.PropertyName = "System.ItemNameDisplay";
                                queryOptions.SortOrder.Clear();
                                queryOptions.SortOrder.Add(sortEntry);
                                break;

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

                            case 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.
                            var storageItem = (StorageFile)await FilesystemTasks.Wrap(() => childFile.Item.ToStorageFileAsync().AsTask());
                            if (storageItem != null)
                            {
                                launchSuccess = await Launcher.LaunchFileAsync(storageItem, options);
                            }
                        }

                        if (!launchSuccess)
                        {
                            await Win32Helpers.InvokeWin32ComponentAsync(path, associatedInstance, args);
                        }
                    }
                });
            }
            return(opened);
        }
Ejemplo n.º 6
0
        public static async Task <TRequested> ToStorageItem <TRequested>(string path, IShellPage associatedInstance = null) where TRequested : IStorageItem
        {
            FilesystemResult <BaseStorageFile>   file   = null;
            FilesystemResult <BaseStorageFolder> folder = null;

            if (path.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase) || path.EndsWith(".url", StringComparison.OrdinalIgnoreCase))
            {
                // TODO: In the future, when IStorageItemWithPath will inherit from IStorageItem,
                // we could implement this code here for getting .lnk files
                // for now, we can't
                return(default);
Ejemplo n.º 7
0
 public void ChangeAppInstance(IShellPage associatedInstance)
 {
     this.associatedInstance = associatedInstance;
 }
Ejemplo n.º 8
0
        public LibraryProperties(SelectedItemsPropertiesViewModel viewModel, CancellationTokenSource tokenSource, CoreDispatcher coreDispatcher, LibraryItem item, IShellPage instance)
        {
            ViewModel   = viewModel;
            TokenSource = tokenSource;
            Dispatcher  = coreDispatcher;
            Library     = item;
            AppInstance = instance;

            GetBaseProperties();
            ViewModel.PropertyChanged += ViewModel_PropertyChanged;
        }
Ejemplo n.º 9
0
 public RecycleBinHelpers(IShellPage associatedInstance)
 {
     this.associatedInstance = associatedInstance;
 }
Ejemplo n.º 10
0
 public static void PostBanner_Delete(ReturnResult status, FileOperationType operation, Stopwatch sw, IShellPage associatedInstance)
 {
     if (status == ReturnResult.Failed ||
         status == ReturnResult.UnknownException ||
         status == ReturnResult.IntegrityCheckFailed ||
         status == ReturnResult.AccessUnauthorized)
     {
         if (status == ReturnResult.AccessUnauthorized)
         {
             associatedInstance.StatusCenterActions.PostBanner(
                 "AccessDeniedDeleteDialog/Title".GetLocalized(),
                 "AccessDeniedDeleteDialog/Text".GetLocalized(),
                 0,
                 status,
                 operation);
         }
         else if (status == ReturnResult.IntegrityCheckFailed)
         {
             associatedInstance.StatusCenterActions.PostBanner(
                 "FileNotFoundDialog/Title".GetLocalized(),
                 "FileNotFoundDialog/Text".GetLocalized(),
                 0,
                 status,
                 operation);
         }
         else if (status == ReturnResult.Failed || status == ReturnResult.UnknownException)
         {
             associatedInstance.StatusCenterActions.PostBanner(
                 "StatusDeletionFailed".GetLocalized(),
                 "StatusUnknownError".GetLocalized(),
                 0,
                 status,
                 operation);
         }
         else if (sw.Elapsed.TotalSeconds >= 10)
         {
             if (operation == FileOperationType.Delete)
             {
                 associatedInstance.StatusCenterActions.PostBanner(
                     "StatusDeletionComplete".GetLocalized(),
                     "StatusOperationCompleted".GetLocalized(),
                     0,
                     ReturnResult.Success,
                     operation);
             }
             else if (operation == FileOperationType.Recycle)
             {
                 associatedInstance.StatusCenterActions.PostBanner(
                     "StatusRecycleComplete".GetLocalized(),
                     "StatusOperationCompleted".GetLocalized(),
                     0,
                     ReturnResult.Success,
                     operation);
             }
         }
     }
 }
Ejemplo n.º 11
0
        public FileSystemProperties(SelectedItemsPropertiesViewModel viewModel, CancellationTokenSource tokenSource, CoreDispatcher coreDispatcher, ListedItem item, IShellPage instance)
        {
            ViewModel   = viewModel;
            TokenSource = tokenSource;
            Dispatcher  = coreDispatcher;
            Item        = item;
            AppInstance = instance;

            GetBaseProperties();

            ViewModel.EditOwnerCommand          = new RelayCommand(() => EditOwner(), () => ViewModel.FilePermissions != null);
            ViewModel.AddRulesForUserCommand    = new RelayCommand(() => AddRulesForUser(), () => ViewModel.FilePermissions != null && ViewModel.FilePermissions.CanReadFilePermissions);
            ViewModel.RemoveRulesForUserCommand = new RelayCommand(() => RemoveRulesForUser(), () => ViewModel.FilePermissions != null && ViewModel.FilePermissions.CanReadFilePermissions && ViewModel.SelectedRuleForUser != null);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Navigates to a directory or opens file
        /// </summary>
        /// <param name="path">The path to navigate to or open</param>
        /// <param name="associatedInstance">The instance associated with view</param>
        /// <param name="itemType"></param>
        /// <param name="openSilent">Determines whether history of opened item is saved (... to Recent Items/Windows Timeline/opening in background)</param>
        /// <param name="openViaApplicationPicker">Determines whether open file using application picker</param>
        /// <param name="selectItems">List of filenames that are selected upon navigation</param>
        public static async Task <bool> OpenPath(string path, IShellPage associatedInstance, FilesystemItemType?itemType = null, bool openSilent = false, bool openViaApplicationPicker = false, IEnumerable <string> selectItems = null, string args = default)
        // TODO: This function reliability has not been extensively tested
        {
            string           previousDir    = associatedInstance.FilesystemViewModel.WorkingDirectory;
            bool             isHiddenItem   = NativeFileOperationsHelper.HasFileAttribute(path, System.IO.FileAttributes.Hidden);
            bool             isShortcutItem = path.EndsWith(".lnk") || path.EndsWith(".url"); // Determine
            FilesystemResult opened         = (FilesystemResult)false;

            // Shortcut item variables
            string shortcutTargetPath       = null;
            string shortcutArguments        = null;
            string shortcutWorkingDirectory = null;
            bool   shortcutRunAsAdmin       = false;
            bool   shortcutIsFolder         = false;

            if (itemType == null || isShortcutItem || isHiddenItem)
            {
                if (isShortcutItem)
                {
                    if (associatedInstance.ServiceConnection == null)
                    {
                        return(false);
                    }
                    var(status, response) = await associatedInstance.ServiceConnection.SendMessageForResponseAsync(new ValueSet()
                    {
                        { "Arguments", "FileOperation" },
                        { "fileop", "ParseLink" },
                        { "filepath", path }
                    });

                    if (status == AppServiceResponseStatus.Success)
                    {
                        shortcutTargetPath       = response.Get("TargetPath", string.Empty);
                        shortcutArguments        = response.Get("Arguments", string.Empty);
                        shortcutWorkingDirectory = response.Get("WorkingDirectory", string.Empty);
                        shortcutRunAsAdmin       = response.Get("RunAsAdmin", false);
                        shortcutIsFolder         = response.Get("IsFolder", false);

                        itemType = shortcutIsFolder ? FilesystemItemType.Directory : FilesystemItemType.File;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (isHiddenItem)
                {
                    itemType = NativeFileOperationsHelper.HasFileAttribute(path, System.IO.FileAttributes.Directory) ? FilesystemItemType.Directory : FilesystemItemType.File;
                }
                else
                {
                    itemType = await StorageItemHelpers.GetTypeFromPath(path);
                }
            }

            var mostRecentlyUsed = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList;

            if (itemType == FilesystemItemType.Library) // OpenLibrary
            {
                if (isHiddenItem)
                {
                    associatedInstance.NavigationToolbar.PathControlDisplayText = path;
                    associatedInstance.NavigateWithArguments(associatedInstance.InstanceViewModel.FolderSettings.GetLayoutType(path), new NavigationArguments()
                    {
                        NavPathParam          = path,
                        AssociatedTabInstance = associatedInstance
                    });
                    return(true);
                }
                else if (App.LibraryManager.TryGetLibrary(path, out LibraryLocationItem library))
                {
                    opened = (FilesystemResult)await library.CheckDefaultSaveFolderAccess();

                    if (opened)
                    {
                        associatedInstance.NavigationToolbar.PathControlDisplayText = library.Text;
                        associatedInstance.NavigateWithArguments(associatedInstance.InstanceViewModel.FolderSettings.GetLayoutType(path), new NavigationArguments()
                        {
                            NavPathParam          = path,
                            AssociatedTabInstance = associatedInstance,
                            SelectItems           = selectItems,
                        });
                    }
                }
            }
            else if (itemType == FilesystemItemType.Directory) // OpenDirectory
            {
                if (isShortcutItem)
                {
                    if (string.IsNullOrEmpty(shortcutTargetPath))
                    {
                        await Win32Helpers.InvokeWin32ComponentAsync(path, associatedInstance);

                        return(true);
                    }
                    else
                    {
                        associatedInstance.NavigationToolbar.PathControlDisplayText = shortcutTargetPath;
                        associatedInstance.NavigateWithArguments(associatedInstance.InstanceViewModel.FolderSettings.GetLayoutType(shortcutTargetPath), new NavigationArguments()
                        {
                            NavPathParam          = shortcutTargetPath,
                            AssociatedTabInstance = associatedInstance,
                            SelectItems           = selectItems
                        });

                        return(true);
                    }
                }
                else if (isHiddenItem)
                {
                    associatedInstance.NavigationToolbar.PathControlDisplayText = path;
                    associatedInstance.NavigateWithArguments(associatedInstance.InstanceViewModel.FolderSettings.GetLayoutType(path), new NavigationArguments()
                    {
                        NavPathParam          = path,
                        AssociatedTabInstance = associatedInstance
                    });

                    return(true);
                }
                else
                {
                    opened = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(path)
                             .OnSuccess(childFolder =>
                    {
                        // Add location to MRU List
                        mostRecentlyUsed.Add(childFolder.Folder, childFolder.Path);
                    });

                    if (!opened)
                    {
                        opened = (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path);
                    }
                    if (!opened)
                    {
                        opened = (FilesystemResult)path.StartsWith("ftp:");
                    }
                    if (opened)
                    {
                        associatedInstance.NavigationToolbar.PathControlDisplayText = path;
                        associatedInstance.NavigateWithArguments(associatedInstance.InstanceViewModel.FolderSettings.GetLayoutType(path), new NavigationArguments()
                        {
                            NavPathParam          = path,
                            AssociatedTabInstance = associatedInstance,
                            SelectItems           = selectItems
                        });
                    }
                }
            }
            else if (itemType == FilesystemItemType.File) // OpenFile
            {
                if (isShortcutItem)
                {
                    if (string.IsNullOrEmpty(shortcutTargetPath))
                    {
                        await Win32Helpers.InvokeWin32ComponentAsync(path, associatedInstance, args);
                    }
                    else
                    {
                        if (!path.EndsWith(".url"))
                        {
                            StorageFileWithPath childFile = await associatedInstance.FilesystemViewModel.GetFileWithPathFromPathAsync(shortcutTargetPath);

                            if (childFile != null)
                            {
                                // Add location to MRU List
                                mostRecentlyUsed.Add(childFile.File, childFile.Path);
                            }
                        }
                        await Win32Helpers.InvokeWin32ComponentAsync(shortcutTargetPath, associatedInstance, $"{args} {shortcutArguments}", shortcutRunAsAdmin, shortcutWorkingDirectory);
                    }
                    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
                        mostRecentlyUsed.Add(childFile.File, childFile.Path);

                        if (openViaApplicationPicker)
                        {
                            LauncherOptions options = new LauncherOptions
                            {
                                DisplayApplicationPicker = true
                            };
                            await Launcher.LaunchFileAsync(childFile.File, options);
                        }
                        else
                        {
                            //try using launcher first
                            bool launchSuccess = false;

                            StorageFileQueryResult 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)
                            StorageFolder currentFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(System.IO.Path.GetDirectoryName(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 == Microsoft.Toolkit.Uwp.UI.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;
                                }

                                fileQueryResult = currentFolder.CreateFileQueryWithOptions(queryOptions);

                                var options = new LauncherOptions
                                {
                                    NeighboringFilesQuery = fileQueryResult
                                };

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

                            if (!launchSuccess)
                            {
                                await Win32Helpers.InvokeWin32ComponentAsync(path, associatedInstance, args);
                            }
                        }
                    });
                }
            }

            if (opened.ErrorCode == FileSystemStatusCode.NotFound && !openSilent)
            {
                await DialogDisplayHelper.ShowDialogAsync("FileNotFoundDialog/Title".GetLocalized(), "FileNotFoundDialog/Text".GetLocalized());

                associatedInstance.NavigationToolbar.CanRefresh = false;
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var ContentOwnedViewModelInstance = associatedInstance.FilesystemViewModel;
                    ContentOwnedViewModelInstance?.RefreshItems(previousDir);
                });
            }

            return(opened);
        }
Ejemplo n.º 13
0
        public static async Task <bool> Exists(string path, IShellPage associatedInstance = null)
        {
            IStorageItem item = await ToStorageItem <IStorageItem>(path, associatedInstance);

            return(item != null);
        }
Ejemplo n.º 14
0
        public static async Task <FilesystemItemType> GetTypeFromPath(string path, IShellPage associatedInstance = null)
        {
            IStorageItem item = await ToStorageItem <IStorageItem>(path, associatedInstance);

            return(item == null ? FilesystemItemType.File : (item.IsOfType(StorageItemTypes.Folder) ? FilesystemItemType.Directory : FilesystemItemType.File));
        }
Ejemplo n.º 15
0
        private async Task <string> GetHashForFileAsync(ListedItem fileItem, string nameOfAlg, CancellationToken token, IProgress <float> progress, IShellPage associatedInstance)
        {
            HashAlgorithmProvider algorithmProvider = HashAlgorithmProvider.OpenAlgorithm(nameOfAlg);
            BaseStorageFile       file = await StorageItemHelpers.ToStorageItem <BaseStorageFile>((fileItem as ShortcutItem)?.TargetPath ?? fileItem.ItemPath, associatedInstance);

            if (file == null)
            {
                return("");
            }

            Stream stream = await FilesystemTasks.Wrap(() => file.OpenStreamForReadAsync());

            if (stream == null)
            {
                return("");
            }

            uint capacity;
            var  inputStream         = stream.AsInputStream();
            bool isProgressSupported = false;

            try
            {
                var cap = (long)(0.5 * stream.Length) / 100;
                if (cap >= uint.MaxValue)
                {
                    capacity = uint.MaxValue;
                }
                else
                {
                    capacity = Convert.ToUInt32(cap);
                }
                isProgressSupported = true;
            }
            catch (NotSupportedException)
            {
                capacity = 64 * 1024;
            }

            Windows.Storage.Streams.Buffer buffer = new Windows.Storage.Streams.Buffer(capacity);
            var hash = algorithmProvider.CreateHash();

            while (!token.IsCancellationRequested)
            {
                await inputStream.ReadAsync(buffer, capacity, InputStreamOptions.None);

                if (buffer.Length > 0)
                {
                    hash.Append(buffer);
                }
                else
                {
                    break;
                }
                if (stream.Length > 0)
                {
                    progress?.Report(isProgressSupported ? (float)stream.Position / stream.Length * 100.0f : 20);
                }
            }
            inputStream.Dispose();
            stream.Dispose();
            if (token.IsCancellationRequested)
            {
                return("");
            }
            return(CryptographicBuffer.EncodeToHexString(hash.GetValueAndReset()).ToLower());
        }
Ejemplo n.º 16
0
        public static async void CopyItem(IShellPage associatedInstance)
        {
            DataPackage dataPackage = new DataPackage()
            {
                RequestedOperation = DataPackageOperation.Copy
            };
            List <IStorageItem> items = new List <IStorageItem>();

            string           copySourcePath = associatedInstance.FilesystemViewModel.WorkingDirectory;
            FilesystemResult result         = (FilesystemResult)false;

            if (associatedInstance.SlimContentPage.IsItemSelected)
            {
                foreach (ListedItem listedItem in associatedInstance.SlimContentPage.SelectedItems)
                {
                    if (listedItem.PrimaryItemAttribute == StorageItemTypes.File)
                    {
                        result = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(listedItem.ItemPath)
                                 .OnSuccess(t => items.Add(t));

                        if (!result)
                        {
                            break;
                        }
                    }
                    else
                    {
                        result = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(listedItem.ItemPath)
                                 .OnSuccess(t => items.Add(t));

                        if (!result)
                        {
                            break;
                        }
                    }
                }
                if (result.ErrorCode == FileSystemStatusCode.Unauthorized)
                {
                    // Try again with fulltrust process
                    if (associatedInstance.ServiceConnection != null)
                    {
                        string filePaths = string.Join('|', associatedInstance.SlimContentPage.SelectedItems.Select(x => x.ItemPath));
                        await associatedInstance.ServiceConnection.SendMessageAsync(new ValueSet()
                        {
                            { "Arguments", "FileOperation" },
                            { "fileop", "Clipboard" },
                            { "filepath", filePaths },
                            { "operation", (int)DataPackageOperation.Copy }
                        });
                    }
                    return;
                }
            }

            if (items?.Count > 0)
            {
                dataPackage.SetStorageItems(items);
                try
                {
                    Clipboard.SetContent(dataPackage);
                    Clipboard.Flush();
                }
                catch
                {
                    dataPackage = null;
                }
            }
        }
Ejemplo n.º 17
0
 public static async Task <IStorageItem> ToStorageItem(this IStorageItemWithPath item, IShellPage associatedInstance = null)
 {
     return((await item.ToStorageItemResult(associatedInstance)).Result);
 }
Ejemplo n.º 18
0
        public static async Task <bool> RenameFileItemAsync(ListedItem item, string oldName, string newName, IShellPage associatedInstance)
        {
            if (oldName == newName)
            {
                return(true);
            }

            ReturnResult renamed = ReturnResult.InProgress;

            if (item.PrimaryItemAttribute == StorageItemTypes.Folder)
            {
                renamed = await associatedInstance.FilesystemHelpers.RenameAsync(StorageItemHelpers.FromPathAndType(item.ItemPath, FilesystemItemType.Directory),
                                                                                 newName, NameCollisionOption.FailIfExists, true);
            }
            else
            {
                if (item.IsShortcutItem || !App.AppSettings.ShowFileExtensions)
                {
                    newName += item.FileExtension;
                }

                renamed = await associatedInstance.FilesystemHelpers.RenameAsync(StorageItemHelpers.FromPathAndType(item.ItemPath, FilesystemItemType.File),
                                                                                 newName, NameCollisionOption.FailIfExists, true);
            }

            if (renamed == ReturnResult.Success)
            {
                associatedInstance.NavigationToolbar.CanGoForward = false;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 19
0
 public static void PostBanner_Delete(ReturnResult status, FileOperationType operation, Stopwatch sw, IShellPage associatedInstance)
 {
     if (status == ReturnResult.Failed ||
         status == ReturnResult.UnknownException ||
         status == ReturnResult.IntegrityCheckFailed ||
         status == ReturnResult.AccessUnauthorized)
     {
         if (status == ReturnResult.AccessUnauthorized)
         {
             associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
                 "AccessDeniedDeleteDialog/Title".GetLocalized(),
                 "AccessDeniedDeleteDialog/Text".GetLocalized(),
                 0,
                 status,
                 operation);
         }
         else if (status == ReturnResult.IntegrityCheckFailed)
         {
             associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
                 "FileNotFoundDialog/Title".GetLocalized(),
                 "FileNotFoundDialog/Text".GetLocalized(),
                 0,
                 status,
                 operation);
         }
         else if (status == ReturnResult.Failed || status == ReturnResult.UnknownException)
         {
             associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
                 "Deletion Failed",
                 "An unknown error has occured.",
                 0,
                 status,
                 operation);
         }
         else if (sw.Elapsed.TotalSeconds >= 10)
         {
             if (operation == FileOperationType.Delete)
             {
                 associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
                     "Deletion Complete",
                     "The operation has completed.",
                     0,
                     ReturnResult.Success,
                     operation);
             }
             else if (operation == FileOperationType.Recycle)
             {
                 associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
                     "Recycle Complete",
                     "The operation has completed.",
                     0,
                     ReturnResult.Success,
                     operation);
             }
         }
     }
 }
Ejemplo n.º 20
0
        public static async void CutItem(IShellPage associatedInstance)
        {
            DataPackage dataPackage = new DataPackage
            {
                RequestedOperation = DataPackageOperation.Move
            };
            List <IStorageItem> items  = new List <IStorageItem>();
            FilesystemResult    result = (FilesystemResult)false;

            if (associatedInstance.SlimContentPage.IsItemSelected)
            {
                // First, reset DataGrid Rows that may be in "cut" command mode
                associatedInstance.SlimContentPage.ItemManipulationModel.RefreshItemsOpacity();

                foreach (ListedItem listedItem in associatedInstance.SlimContentPage.SelectedItems)
                {
                    // Dim opacities accordingly
                    listedItem.Opacity = Constants.UI.DimItemOpacity;

                    if (listedItem.PrimaryItemAttribute == StorageItemTypes.File)
                    {
                        result = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(listedItem.ItemPath)
                                 .OnSuccess(t => items.Add(t));

                        if (!result)
                        {
                            break;
                        }
                    }
                    else
                    {
                        result = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(listedItem.ItemPath)
                                 .OnSuccess(t => items.Add(t));

                        if (!result)
                        {
                            break;
                        }
                    }
                }
                if (result.ErrorCode == FileSystemStatusCode.NotFound)
                {
                    associatedInstance.SlimContentPage.ItemManipulationModel.RefreshItemsOpacity();
                    return;
                }
                else if (result.ErrorCode == FileSystemStatusCode.Unauthorized)
                {
                    // Try again with fulltrust process
                    if (associatedInstance.ServiceConnection != null)
                    {
                        string filePaths = string.Join('|', associatedInstance.SlimContentPage.SelectedItems.Select(x => x.ItemPath));
                        AppServiceResponseStatus status = await associatedInstance.ServiceConnection.SendMessageAsync(new ValueSet()
                        {
                            { "Arguments", "FileOperation" },
                            { "fileop", "Clipboard" },
                            { "filepath", filePaths },
                            { "operation", (int)DataPackageOperation.Move }
                        });

                        if (status == AppServiceResponseStatus.Success)
                        {
                            return;
                        }
                    }
                    associatedInstance.SlimContentPage.ItemManipulationModel.RefreshItemsOpacity();
                    return;
                }
            }

            if (!items.Any())
            {
                return;
            }
            dataPackage.SetStorageItems(items);
            try
            {
                Clipboard.SetContent(dataPackage);
                Clipboard.Flush();
            }
            catch
            {
                dataPackage = null;
            }
        }
Ejemplo n.º 21
0
 public CombinedProperties(SelectedItemsPropertiesViewModel viewModel, CancellationTokenSource tokenSource,
                           CoreDispatcher coreDispatcher, List <ListedItem> listedItems, IShellPage instance)
 {
     ViewModel   = viewModel;
     TokenSource = tokenSource;
     Dispatcher  = coreDispatcher;
     List        = listedItems;
     AppInstance = instance;
     GetBaseProperties();
     ViewModel.PropertyChanged += ViewModel_PropertyChanged;
 }
Ejemplo n.º 22
0
 public static async void CreateFileFromDialogResultType(AddItemType itemType, ShellNewEntry itemInfo, IShellPage associatedInstance)
 {
     _ = await CreateFileFromDialogResultTypeForResult(itemType, itemInfo, associatedInstance);
 }
Ejemplo n.º 23
0
        private static async Task <FilesystemResult> OpenDirectory(string path, IShellPage associatedInstance, IEnumerable <string> selectItems, ShellLinkItem shortcutInfo, bool forceOpenInNewTab)
        {
            IUserSettingsService userSettingsService = Ioc.Default.GetService <IUserSettingsService>();

            var  opened         = (FilesystemResult)false;
            bool isHiddenItem   = NativeFileOperationsHelper.HasFileAttribute(path, System.IO.FileAttributes.Hidden);
            bool isShortcutItem = path.EndsWith(".lnk", StringComparison.Ordinal) || path.EndsWith(".url", StringComparison.Ordinal); // Determine

            if (isShortcutItem)
            {
                if (string.IsNullOrEmpty(shortcutInfo.TargetPath))
                {
                    await Win32Helpers.InvokeWin32ComponentAsync(path, associatedInstance);

                    opened = (FilesystemResult)true;
                }
                else
                {
                    if (forceOpenInNewTab || userSettingsService.PreferencesSettingsService.OpenFoldersInNewTab)
                    {
                        await OpenPathInNewTab(shortcutInfo.TargetPath);
                    }
                    else
                    {
                        associatedInstance.ToolbarViewModel.PathControlDisplayText = shortcutInfo.TargetPath;
                        associatedInstance.NavigateWithArguments(associatedInstance.InstanceViewModel.FolderSettings.GetLayoutType(shortcutInfo.TargetPath), new NavigationArguments()
                        {
                            NavPathParam          = shortcutInfo.TargetPath,
                            AssociatedTabInstance = associatedInstance,
                            SelectItems           = selectItems
                        });
                    }

                    opened = (FilesystemResult)true;
                }
            }
            else if (isHiddenItem)
            {
                if (forceOpenInNewTab || userSettingsService.PreferencesSettingsService.OpenFoldersInNewTab)
                {
                    await OpenPathInNewTab(path);
                }
                else
                {
                    associatedInstance.ToolbarViewModel.PathControlDisplayText = path;
                    associatedInstance.NavigateWithArguments(associatedInstance.InstanceViewModel.FolderSettings.GetLayoutType(path), new NavigationArguments()
                    {
                        NavPathParam          = path,
                        AssociatedTabInstance = associatedInstance
                    });
                }

                opened = (FilesystemResult)true;
            }
            else
            {
                opened = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(path)
                         .OnSuccess(async(childFolder) =>
                {
                    // Add location to Recent Items List
                    if (childFolder.Item is SystemStorageFolder)
                    {
                        await App.RecentItemsManager.AddToRecentItems(childFolder.Path);
                    }
                });

                if (!opened)
                {
                    opened = (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path);
                }
                if (opened)
                {
                    if (forceOpenInNewTab || userSettingsService.PreferencesSettingsService.OpenFoldersInNewTab)
                    {
                        await OpenPathInNewTab(path);
                    }
                    else
                    {
                        associatedInstance.ToolbarViewModel.PathControlDisplayText = path;
                        associatedInstance.NavigateWithArguments(associatedInstance.InstanceViewModel.FolderSettings.GetLayoutType(path), new NavigationArguments()
                        {
                            NavPathParam          = path,
                            AssociatedTabInstance = associatedInstance,
                            SelectItems           = selectItems
                        });
                    }
                }
                else
                {
                    await Win32Helpers.InvokeWin32ComponentAsync(path, associatedInstance);
                }
            }
            return(opened);
        }
Ejemplo n.º 24
0
        public static async Task <IStorageItem> CreateFileFromDialogResultTypeForResult(AddItemType itemType, ShellNewEntry itemInfo, IShellPage associatedInstance)
        {
            string currentPath = null;

            if (associatedInstance.SlimContentPage != null)
            {
                currentPath = associatedInstance.FilesystemViewModel.WorkingDirectory;
            }

            // 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);

            FilesystemResult <(ReturnResult, IStorageItem)> created = null;

            if (folderRes)
            {
                switch (itemType)
                {
                case AddItemType.Folder:
                    userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized();
                    created   = await FilesystemTasks.Wrap(async() =>
                    {
                        return(await associatedInstance.FilesystemHelpers.CreateAsync(
                                   StorageItemHelpers.FromPathAndType(System.IO.Path.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(
                                   StorageItemHelpers.FromPathAndType(System.IO.Path.Combine(folderRes.Result.Path, userInput + itemInfo?.Extension), FilesystemItemType.File),
                                   true));
                    });

                    break;
                }
            }

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

            return(created.Result.Item2);
        }
Ejemplo n.º 25
0
        private static async Task DeleteItem(StorageDeleteOption deleteOption, IShellPage AppInstance, IProgress <uint> progress)
        {
            var deleteFromRecycleBin = AppInstance.FilesystemViewModel.WorkingDirectory.StartsWith(App.AppSettings.RecycleBinPath);

            List <ListedItem> selectedItems = new List <ListedItem>();

            foreach (ListedItem selectedItem in AppInstance.ContentPage.SelectedItems)
            {
                selectedItems.Add(selectedItem);
            }

            if (App.AppSettings.ShowConfirmDeleteDialog == true) //check if the setting to show a confirmation dialog is on
            {
                var dialog = new ConfirmDeleteDialog(deleteFromRecycleBin, deleteOption);
                await dialog.ShowAsync();

                if (dialog.Result != MyResult.Delete) //delete selected  item(s) if the result is yes
                {
                    return;                           //return if the result isn't delete
                }
                deleteOption = dialog.PermanentlyDelete;
            }

            int itemsDeleted = 0;

            foreach (ListedItem storItem in selectedItems)
            {
                uint progressValue = (uint)(itemsDeleted * 100.0 / selectedItems.Count);
                if (selectedItems.Count > 3)
                {
                    progress.Report((uint)progressValue);
                }

                IStorageItem item;
                try
                {
                    if (storItem.PrimaryItemAttribute == StorageItemTypes.File)
                    {
                        item = await ItemViewModel.GetFileFromPathAsync(storItem.ItemPath, AppInstance);
                    }
                    else
                    {
                        item = await ItemViewModel.GetFolderFromPathAsync(storItem.ItemPath, AppInstance);
                    }

                    await item.DeleteAsync(deleteOption);
                }
                catch (UnauthorizedAccessException)
                {
                    if (deleteOption == StorageDeleteOption.Default)
                    {
                        // Try again with fulltrust process
                        if (App.Connection != null)
                        {
                            var result = await App.Connection.SendMessageAsync(new ValueSet()
                            {
                                { "Arguments", "FileOperation" },
                                { "fileop", "MoveToBin" },
                                { "filepath", storItem.ItemPath }
                            });
                        }
                    }
                    else
                    {
                        // Try again with DeleteFileFromApp
                        if (!NativeDirectoryChangesHelper.DeleteFileFromApp(storItem.ItemPath))
                        {
                            Debug.WriteLine(System.Runtime.InteropServices.Marshal.GetLastWin32Error());
                        }
                    }
                }
                catch (FileLoadException)
                {
                    // try again
                    if (storItem.PrimaryItemAttribute == StorageItemTypes.File)
                    {
                        item = await ItemViewModel.GetFileFromPathAsync(storItem.ItemPath, AppInstance);
                    }
                    else
                    {
                        item = await ItemViewModel.GetFolderFromPathAsync(storItem.ItemPath, AppInstance);
                    }

                    await item.DeleteAsync(deleteOption);
                }

                if (deleteFromRecycleBin)
                {
                    // Recycle bin also stores a file starting with $I for each item
                    var iFilePath = Path.Combine(Path.GetDirectoryName(storItem.ItemPath), Path.GetFileName(storItem.ItemPath).Replace("$R", "$I"));
                    await(await ItemViewModel.GetFileFromPathAsync(iFilePath)).DeleteAsync(StorageDeleteOption.PermanentDelete);
                }

                await AppInstance.FilesystemViewModel.RemoveFileOrFolder(storItem);

                itemsDeleted++;
            }
        }
 public BaseLayoutCommandImplementationModel(IShellPage associatedInstance, ItemManipulationModel itemManipulationModel)
 {
     this.associatedInstance    = associatedInstance;
     this.itemManipulationModel = itemManipulationModel;
 }
Ejemplo n.º 27
0
        public FileProperties(SelectedItemsPropertiesViewModel viewModel, CancellationTokenSource tokenSource, CoreDispatcher coreDispatcher, ProgressBar progressBar, ListedItem item, IShellPage instance)
        {
            ViewModel   = viewModel;
            TokenSource = tokenSource;
            ProgressBar = progressBar;
            Dispatcher  = coreDispatcher;
            Item        = item;
            AppInstance = instance;

            GetBaseProperties();
            ViewModel.PropertyChanged += ViewModel_PropertyChanged;
        }
Ejemplo n.º 28
0
        public FileProperties(SelectedItemsPropertiesViewModel viewModel, CancellationTokenSource tokenSource, CoreDispatcher coreDispatcher, IProgress <float> hashProgress, ListedItem item, IShellPage instance)
        {
            ViewModel         = viewModel;
            TokenSource       = tokenSource;
            Dispatcher        = coreDispatcher;
            Item              = item;
            AppInstance       = instance;
            this.hashProgress = hashProgress;

            GetBaseProperties();

            ViewModel.PropertyChanged += ViewModel_PropertyChanged;
        }
Ejemplo n.º 29
0
 public DriveProperties(SelectedItemsPropertiesViewModel viewModel, DriveItem driveItem, IShellPage instance)
 {
     ViewModel   = viewModel;
     Drive       = driveItem;
     AppInstance = instance;
     GetBaseProperties();
 }
Ejemplo n.º 30
0
 public FolderProperties(SelectedItemsPropertiesViewModel viewModel, CancellationTokenSource tokenSource, CoreDispatcher coreDispatcher, ListedItem item, IShellPage instance)
     : base(viewModel, tokenSource, coreDispatcher, item, instance)
 {
     ViewModel.PropertyChanged += ViewModel_PropertyChanged;
 }