/// <summary> /// Creates a subfolder in this folder /// </summary> /// <param name="desiredName">The name of the folder to create</param> /// <param name="option">Specifies how to behave if the specified folder already exists</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The newly created folder</returns> public async Task <IFolder> CreateFolderAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken) { Requires.NotNullOrEmpty(desiredName, "desiredName"); await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); EnsureExists(); string nameToUse = desiredName; string newPath = System.IO.Path.Combine(Path, nameToUse); if (Root.DirectoryExists(newPath)) { if (option == CreationCollisionOption.GenerateUniqueName) { for (int num = 2; Root.DirectoryExists(newPath); num++) { nameToUse = desiredName + " (" + num + ")"; newPath = System.IO.Path.Combine(Path, nameToUse); } Root.CreateDirectory(newPath); } else if (option == CreationCollisionOption.ReplaceExisting) { IsoStoreFolder folderToDelete = new IsoStoreFolder(nameToUse, this); await folderToDelete.DeleteAsync(cancellationToken).ConfigureAwait(false); Root.CreateDirectory(newPath); } else if (option == CreationCollisionOption.FailIfExists) { throw new IOException("Directory already exists: " + newPath); } else if (option == CreationCollisionOption.OpenIfExists) { // No operation } else { throw new ArgumentException("Unrecognized CreationCollisionOption: " + option); } } else { Root.CreateDirectory(newPath); } var ret = new IsoStoreFolder(nameToUse, this); return(ret); }
/// <summary> /// Gets a subfolder in this folder /// </summary> /// <param name="name">The name of the folder to get</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The requested folder, or null if it does not exist</returns> public async Task <IFolder> GetFolderAsync(string name, CancellationToken cancellationToken) { Requires.NotNullOrEmpty(name, "name"); await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); EnsureExists(); string path = System.IO.Path.Combine(Path, name); if (!Root.DirectoryExists(path)) { throw new PCLStorage.Exceptions.DirectoryNotFoundException("Directory does not exist: " + path); } var ret = new IsoStoreFolder(name, this); return(ret); }
/// <summary> /// Creates a new <see cref="IsoStoreFolder"/> corresponding to a subfolder of another <see cref="IsoStoreFolder"/> /// </summary> /// <param name="name">The name of the folder</param> /// <param name="parent">The parent folder</param> public IsoStoreFolder(string name, IsoStoreFolder parent) : this(parent.Root, System.IO.Path.Combine(parent.Path, name)) { }
/// <summary> /// Gets a subfolder in this folder /// </summary> /// <param name="name">The name of the folder to get</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The requested folder, or null if it does not exist</returns> public async Task<IFolder> GetFolderAsync(string name, CancellationToken cancellationToken) { Requires.NotNullOrEmpty(name, "name"); await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); EnsureExists(); string path = System.IO.Path.Combine(Path, name); if (!Root.DirectoryExists(path)) { throw new PCLStorage.Exceptions.DirectoryNotFoundException("Directory does not exist: " + path); } var ret = new IsoStoreFolder(name, this); return ret; }
/// <summary> /// Creates a subfolder in this folder /// </summary> /// <param name="desiredName">The name of the folder to create</param> /// <param name="option">Specifies how to behave if the specified folder already exists</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The newly created folder</returns> public async Task<IFolder> CreateFolderAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken) { Requires.NotNullOrEmpty(desiredName, "desiredName"); await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); EnsureExists(); string nameToUse = desiredName; string newPath = System.IO.Path.Combine(Path, nameToUse); if (Root.DirectoryExists(newPath)) { if (option == CreationCollisionOption.GenerateUniqueName) { for (int num = 2; Root.DirectoryExists(newPath); num++) { nameToUse = desiredName + " (" + num + ")"; newPath = System.IO.Path.Combine(Path, nameToUse); } Root.CreateDirectory(newPath); } else if (option == CreationCollisionOption.ReplaceExisting) { IsoStoreFolder folderToDelete = new IsoStoreFolder(nameToUse, this); await folderToDelete.DeleteAsync(cancellationToken).ConfigureAwait(false); Root.CreateDirectory(newPath); } else if (option == CreationCollisionOption.FailIfExists) { throw new IOException("Directory already exists: " + newPath); } else if (option == CreationCollisionOption.OpenIfExists) { // No operation } else { throw new ArgumentException("Unrecognized CreationCollisionOption: " + option); } } else { Root.CreateDirectory(newPath); } var ret = new IsoStoreFolder(nameToUse, this); return ret; }