Пример #1
0
        public async Task <bool> DeleteItem(IStorageItem item, StorageDeleteOption deletionOption)
        {
            await item.DeleteAsync(deletionOption);

            return(true);
        }
Пример #2
0
        public static async Task DeleteFolderContentsAsync(StorageFolder folder,
            StorageDeleteOption option = StorageDeleteOption.Default)
        {
            try
            {
                // Try to delete all files
                var files = await folder.GetFilesAsync();
                foreach (var file in files)
                {
                    try
                    {
                        await file.DeleteAsync(option);
                    }
                    catch
                    {

                    }
                }
                // Iterate through all subfolders
                var subFolders = await folder.GetFoldersAsync();
                foreach (var subFolder in subFolders)
                {
                    try
                    {
                        // Delete the contents
                        await DeleteFolderContentsAsync(subFolder, option);
                        // Delete the subfolder
                        await subFolder.DeleteAsync(option);
                    }
                    catch
                    {

                    }
                }
            }
            catch
            {

            }
        }
Пример #3
0
        //TODO: Implement CreateStreamedFileAsync and
        // CreateStreamedFileFromUriAsync once stream handling is more mature

        /// <summary>
        /// Removes the current item from disk.
        /// </summary>
        ///
        /// <param name="option">
        /// Whether to always skip the Recycle Bin and permanently delete the
        /// item, or if that decision should rely on the default behaviour.
        /// <para/>
        /// Default value is the latter
        /// (<see cref="StorageDeleteOption.Default"/>).
        /// </param>
        ///
        /// <returns>
        /// An awaitable <see cref="Task"/>, with no associated value.
        /// </returns>
        public Task DeleteAsync(StorageDeleteOption option = StorageDeleteOption.Default)
        {
            throw new NotImplementedException();
        }
Пример #4
0
 public IAsyncAction DeleteAsync(StorageDeleteOption option) =>
 AsyncAction.FromTask(ct => Implementation.DeleteAsync(option, ct));
Пример #5
0
 public IAsyncAction DeleteAsync(StorageDeleteOption option)
 {
     return null;
 }
Пример #6
0
        public async void DeleteItemWithStatus(StorageDeleteOption deleteOption)
        {
            var deleteFromRecycleBin = AppInstance.FilesystemViewModel.WorkingDirectory.StartsWith(App.AppSettings.RecycleBinPath);

            if (deleteFromRecycleBin)
            {
                // Permanently delete if deleting from recycle bin
                deleteOption = StorageDeleteOption.PermanentDelete;
            }

            PostedStatusBanner bannerResult = null;

            if (deleteOption == StorageDeleteOption.PermanentDelete)
            {
                bannerResult = AppInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(null,
                                                                                                   AppInstance.FilesystemViewModel.WorkingDirectory,
                                                                                                   0,
                                                                                                   StatusBanner.StatusBannerSeverity.Ongoing,
                                                                                                   StatusBanner.StatusBannerOperation.Delete);
            }
            else
            {
                bannerResult = AppInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(null,
                                                                                                   AppInstance.FilesystemViewModel.WorkingDirectory,
                                                                                                   0,
                                                                                                   StatusBanner.StatusBannerSeverity.Ongoing,
                                                                                                   StatusBanner.StatusBannerOperation.Recycle);
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            var res = await DeleteItemAsync(deleteOption, AppInstance, bannerResult.Progress);

            bannerResult.Remove();
            sw.Stop();
            if (!res)
            {
                if (res.ErrorCode == FilesystemErrorCode.ERROR_UNAUTHORIZED)
                {
                    bannerResult.Remove();
                    AppInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
                        "AccessDeniedDeleteDialog/Title".GetLocalized(),
                        "AccessDeniedDeleteDialog/Text".GetLocalized(),
                        0,
                        StatusBanner.StatusBannerSeverity.Error,
                        StatusBanner.StatusBannerOperation.Delete);
                }
                else if (res.ErrorCode == FilesystemErrorCode.ERROR_NOTFOUND)
                {
                    bannerResult.Remove();
                    AppInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
                        "FileNotFoundDialog/Title".GetLocalized(),
                        "FileNotFoundDialog/Text".GetLocalized(),
                        0,
                        StatusBanner.StatusBannerSeverity.Error,
                        StatusBanner.StatusBannerOperation.Delete);
                }
                else if (res.ErrorCode == FilesystemErrorCode.ERROR_INUSE)
                {
                    bannerResult.Remove();
                    AppInstance.BottomStatusStripControl.OngoingTasksControl.PostActionBanner(
                        "FileInUseDeleteDialog/Title".GetLocalized(),
                        "FileInUseDeleteDialog/Text".GetLocalized(),
                        "FileInUseDeleteDialog/PrimaryButtonText".GetLocalized(),
                        "FileInUseDeleteDialog/SecondaryButtonText".GetLocalized(), () => { DeleteItemWithStatus(deleteOption); });
                }
            }
            else if (sw.Elapsed.TotalSeconds >= 10)
            {
                if (deleteOption == StorageDeleteOption.PermanentDelete)
                {
                    AppInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
                        "Deletion Complete",
                        "The operation has completed.",
                        0,
                        StatusBanner.StatusBannerSeverity.Success,
                        StatusBanner.StatusBannerOperation.Delete);
                }
                else
                {
                    AppInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(
                        "Recycle Complete",
                        "The operation has completed.",
                        0,
                        StatusBanner.StatusBannerSeverity.Success,
                        StatusBanner.StatusBannerOperation.Recycle);
                }
            }

            AppInstance.NavigationToolbar.CanGoForward = false;
        }
Пример #7
0
 public abstract Task DeleteAsync(CancellationToken ct, StorageDeleteOption options);
Пример #8
0
 public override IAsyncAction DeleteAsync(StorageDeleteOption option)
 {
     return(Folder.DeleteAsync(option));
 }
Пример #9
0
 public IAsyncAction DeleteAsync(StorageDeleteOption option)
 => AsyncAction.FromTask(ct => _impl.Delete(ct, option));
Пример #10
0
        public async Task DeleteAsync(StorageDeleteOption option)
        {
            await Task.Delay(5).ConfigureAwait(false);

            await _item.DeleteAsync((Windows.Storage.StorageDeleteOption)((int)option));
        }
Пример #11
0
 /// <summary>
 /// For Test use.
 /// </summary>
 private static async Task DeleteAllCacheFolderAsync(bool permanent_delete = false)
 {
     StorageDeleteOption option = permanent_delete ? StorageDeleteOption.PermanentDelete : StorageDeleteOption.Default;
     await LocalCacheFolder.DeleteAsync().AsTask().ConfigureAwait(false);
 }
Пример #12
0
        private 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, AppInstance.ContentPage.SelectedItemsPropertiesViewModel);
                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 AppInstance.FilesystemViewModel.GetFileFromPathAsync(storItem.ItemPath);
                    }
                    else
                    {
                        item = await AppInstance.FilesystemViewModel.GetFolderFromPathAsync(storItem.ItemPath);
                    }

                    await item.DeleteAsync(deleteOption);
                }
                catch (UnauthorizedAccessException)
                {
                    if (deleteOption == StorageDeleteOption.Default)
                    {
                        // Try again with fulltrust process
                        if (AppInstance.FilesystemViewModel.Connection != null)
                        {
                            var result = await AppInstance.FilesystemViewModel.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 AppInstance.FilesystemViewModel.GetFileFromPathAsync(storItem.ItemPath);
                    }
                    else
                    {
                        item = await AppInstance.FilesystemViewModel.GetFolderFromPathAsync(storItem.ItemPath);
                    }

                    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 AppInstance.FilesystemViewModel.GetFileFromPathAsync(iFilePath)).DeleteAsync(StorageDeleteOption.PermanentDelete);
                }

                await AppInstance.FilesystemViewModel.RemoveFileOrFolder(storItem);

                itemsDeleted++;
            }
        }
Пример #13
0
        /// <summary>
        /// Deletes the current folder.
        /// This method also specifies whether to delete the folder permanently.
        /// </summary>
        /// <returns></returns>
        public Task DeleteAsync(StorageDeleteOption option)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE
            return _folder.DeleteAsync((Windows.Storage.StorageDeleteOption)((int)option)).AsTask();
#elif __ANDROID__ || __UNIFIED__ || WIN32 || TIZEN
            if (!Directory.Exists(Path))
            {
                throw new FileNotFoundException();
            }
            return Task.Run(() =>
            {
                global::System.IO.Directory.Delete(Path, true);
            });
#else
            throw new PlatformNotSupportedException();
#endif
        }
Пример #14
0
            public override async Task DeleteAsync(StorageDeleteOption options, CancellationToken ct)
            {
                await TryInitializeStorage();

                Directory.Delete(Path, true);
            }
Пример #15
0
 public override IAsyncAction DeleteAsync(StorageDeleteOption option)
 {
     throw new NotSupportedException();
 }
Пример #16
0
 internal Task Delete(CancellationToken ct, StorageDeleteOption options)
 => _impl.Delete(ct, options);
Пример #17
0
        private async Task <FilesystemResult> DeleteItemAsync(StorageDeleteOption deleteOption, IShellPage AppInstance, IProgress <uint> progress)
        {
            var deleted = (FilesystemResult)false;
            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, AppInstance.ContentPage.SelectedItemsPropertiesViewModel);
                await dialog.ShowAsync();

                if (dialog.Result != MyResult.Delete) //delete selected  item(s) if the result is yes
                {
                    return((FilesystemResult)true);   //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(progressValue);
                }

                if (storItem.PrimaryItemAttribute == StorageItemTypes.File)
                {
                    deleted = await AppInstance.FilesystemViewModel.GetFileFromPathAsync(storItem.ItemPath)
                              .OnSuccess(t => t.DeleteAsync(deleteOption).AsTask());
                }
                else
                {
                    deleted = await AppInstance.FilesystemViewModel.GetFolderFromPathAsync(storItem.ItemPath)
                              .OnSuccess(t => t.DeleteAsync(deleteOption).AsTask());
                }

                if (deleted.ErrorCode == FilesystemErrorCode.ERROR_UNAUTHORIZED)
                {
                    // Try again with fulltrust process
                    if (AppInstance.FilesystemViewModel.Connection != null)
                    {
                        var response = await AppInstance.FilesystemViewModel.Connection.SendMessageAsync(new ValueSet()
                        {
                            { "Arguments", "FileOperation" },
                            { "fileop", "DeleteItem" },
                            { "filepath", storItem.ItemPath },
                            { "permanently", deleteOption == StorageDeleteOption.PermanentDelete }
                        });

                        deleted = (FilesystemResult)(response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success);
                    }
                }
                else if (deleted.ErrorCode == FilesystemErrorCode.ERROR_INUSE)
                {
                    // TODO: retry or show dialog
                    await DialogDisplayHelper.ShowDialogAsync("FileInUseDeleteDialog/Title".GetLocalized(), "FileInUseDeleteDialog/Text".GetLocalized());
                }

                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 AppInstance.FilesystemViewModel.GetFileFromPathAsync(iFilePath)
                    .OnSuccess(t => t.DeleteAsync(StorageDeleteOption.PermanentDelete).AsTask());
                }

                if (deleted)
                {
                    await AppInstance.FilesystemViewModel.RemoveFileOrFolderAsync(storItem);

                    itemsDeleted++;
                }
                else
                {
                    // Stop at first error
                    return(deleted);
                }
            }
            return((FilesystemResult)true);
        }
Пример #18
0
 public IAsyncAction DeleteAsync(StorageDeleteOption option)
 {
     throw new NotImplementedException();
 }
Пример #19
0
 public override IAsyncAction DeleteAsync(StorageDeleteOption option)
 {
     return(DeleteAsync());
 }
Пример #20
0
 public override async Task Delete(CancellationToken ct, StorageDeleteOption options)
 => File.Delete(Path);
Пример #21
0
 internal Task Delete(CancellationToken ct, StorageDeleteOption options)
 => Implementation.DeleteAsync(ct, options);
Пример #22
0
 public IAsyncAction DeleteAsync(StorageDeleteOption option)
 {
     return(null);
 }
Пример #23
0
 public IAsyncAction DeleteAsync(StorageDeleteOption option)
 {
     throw new NotImplementedException();
 }
Пример #24
0
 public abstract IAsyncAction DeleteAsync(StorageDeleteOption option);
Пример #25
0
 public Windows.Foundation.IAsyncAction DeleteAsync(StorageDeleteOption option)
 {
     throw new NotImplementedException();
 }
Пример #26
0
        /// <summary>
        /// Deletes the current file, optionally deleting the item permanently.
        /// </summary>
        /// <returns></returns>
        public Task DeleteAsync(StorageDeleteOption option)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE
            return _file.DeleteAsync((Windows.Storage.StorageDeleteOption)((int)option)).AsTask();
#elif __ANDROID__ || __UNIFIED__ || WIN32 || TIZEN
            return Task.Run(() =>
            {
                global::System.IO.File.Delete(Path);
            });
#else
            throw new PlatformNotSupportedException();
#endif
        }