public async Task <IStorageHistory> RenameAsync(PathWithType source, string newName, NameCollisionOption collision, IProgress <FilesystemErrorCode> errorCode, CancellationToken cancellationToken) { if (Path.GetFileName(source.Path) == newName && collision == NameCollisionOption.FailIfExists) { errorCode?.Report(FilesystemErrorCode.ERROR_ALREADYEXIST); return(null); } if (!string.IsNullOrWhiteSpace(newName) && !FilesystemHelpers.ContainsRestrictedCharacters(newName) && !FilesystemHelpers.ContainsRestrictedFileName(newName)) { try { IStorageItem itemToRename = await source.Path.ToStorageItem(); await itemToRename.RenameAsync(newName, collision); errorCode?.Report(FilesystemErrorCode.ERROR_SUCCESS); return(new StorageHistory(FileOperationType.Rename, source, new PathWithType(itemToRename.Path, source.ItemType))); } catch (Exception e) { errorCode?.Report(FilesystemTasks.GetErrorCode(e)); return(null); } } return(null); }
public async Task <IStorageHistory> RenameAsync(IStorageItem source, string newName, NameCollisionOption collision, IProgress <FilesystemErrorCode> errorCode, CancellationToken cancellationToken) { if (Path.GetFileName(source.Path) == newName && collision == NameCollisionOption.FailIfExists) { errorCode?.Report(FilesystemErrorCode.ERROR_ALREADYEXIST); return(null); } if (!string.IsNullOrWhiteSpace(newName) && !FilesystemHelpers.ContainsRestrictedCharacters(newName) && !FilesystemHelpers.ContainsRestrictedFileName(newName)) { try { FilesystemItemType itemType = source.IsOfType(StorageItemTypes.File) ? FilesystemItemType.File : FilesystemItemType.Directory; string originalSource = source.Path; await source.RenameAsync(newName, collision); errorCode?.Report(FilesystemErrorCode.ERROR_SUCCESS); return(new StorageHistory(FileOperationType.Rename, StorageItemHelpers.FromPathAndType(originalSource, itemType), source.FromStorageItem())); } catch (Exception e) { errorCode?.Report(FilesystemTasks.GetErrorCode(e)); return(null); } } return(null); }
public async Task <(IStorageHistory, IStorageItem)> CreateAsync(IStorageItemWithPath source, IProgress <FileSystemStatusCode> errorCode, CancellationToken cancellationToken) { IStorageItem item = null; try { switch (source.ItemType) { case FilesystemItemType.File: { var newEntryInfo = await RegistryHelper.GetNewContextMenuEntryForType(Path.GetExtension(source.Path)); if (newEntryInfo == null) { StorageFolder folder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(Path.GetDirectoryName(source.Path)); item = await folder.CreateFileAsync(Path.GetFileName(source.Path)); } else { item = (await newEntryInfo.Create(source.Path, associatedInstance)).Result; } break; } case FilesystemItemType.Directory: { StorageFolder folder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(Path.GetDirectoryName(source.Path)); item = await folder.CreateFolderAsync(Path.GetFileName(source.Path)); break; } case FilesystemItemType.Symlink: { Debugger.Break(); throw new NotImplementedException(); } default: Debugger.Break(); break; } errorCode?.Report(FileSystemStatusCode.Success); return(new StorageHistory(FileOperationType.CreateNew, source.CreateEnumerable(), null), item); } catch (Exception e) { errorCode?.Report(FilesystemTasks.GetErrorCode(e)); return(null, null); } }
public async Task <IStorageHistory> CreateAsync(PathWithType source, IProgress <FilesystemErrorCode> errorCode, CancellationToken cancellationToken) { try { switch (source.ItemType) { case FilesystemItemType.File: { StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(Path.GetDirectoryName(source.Path)); await folder.CreateFileAsync(Path.GetFileName(source.Path)); break; } case FilesystemItemType.Directory: { StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(Path.GetDirectoryName(source.Path)); await folder.CreateFolderAsync(Path.GetFileName(source.Path)); break; } case FilesystemItemType.Symlink: { Debugger.Break(); throw new NotImplementedException(); } default: Debugger.Break(); break; } errorCode?.Report(FilesystemErrorCode.ERROR_SUCCESS); return(new StorageHistory(FileOperationType.CreateNew, source.CreateEnumerable(), null)); } catch (Exception e) { errorCode?.Report(FilesystemTasks.GetErrorCode(e)); return(null); } }