private static IFolder GetFolder(string path) { IFolder folder = null; if (!string.IsNullOrWhiteSpace(path)) { folder = new FileSystemFolder(path, canDelete: false); } return(folder); }
/// <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 (Directory.Exists(newPath)) { if (option == CreationCollisionOption.GenerateUniqueName) { for (int num = 2; Directory.Exists(newPath); num++) { cancellationToken.ThrowIfCancellationRequested(); nameToUse = desiredName + " (" + num + ")"; newPath = System.IO.Path.Combine(Path, nameToUse); } Directory.CreateDirectory(newPath); } else if (option == CreationCollisionOption.ReplaceExisting) { Directory.Delete(newPath, true); Directory.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 { Directory.CreateDirectory(newPath); } var ret = new FileSystemFolder(newPath, true); 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); string path = System.IO.Path.Combine(Path, name); if (!Directory.Exists(path)) { throw new PCLStorage.Exceptions.DirectoryNotFoundException("Directory does not exist: " + path); } var ret = new FileSystemFolder(path, true); return(ret); }
static Current() { var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); LocalStorage = new FileSystemFolder(documents); }
/// <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); string path = System.IO.Path.Combine(Path, name); if (!Directory.Exists(path)) { throw new PCLStorage.Exceptions.DirectoryNotFoundException("Directory does not exist: " + path); } var ret = new FileSystemFolder(path, true); 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 (Directory.Exists(newPath)) { if (option == CreationCollisionOption.GenerateUniqueName) { for (int num = 2; Directory.Exists(newPath); num++) { cancellationToken.ThrowIfCancellationRequested(); nameToUse = desiredName + " (" + num + ")"; newPath = System.IO.Path.Combine(Path, nameToUse); } Directory.CreateDirectory(newPath); } else if (option == CreationCollisionOption.ReplaceExisting) { Directory.Delete(newPath, true); Directory.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 { Directory.CreateDirectory(newPath); } var ret = new FileSystemFolder(newPath, true); return ret; }