/// <summary> /// Creates a file in this folder /// </summary> /// <param name="desiredName">The name of the file to create</param> /// <param name="option">Specifies how to behave if the specified file already exists</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The newly created file</returns> public async Task <IFile> CreateFileAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken) { Requires.NotNullOrEmpty(desiredName, "desiredName"); await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); EnsureExists(); string nameToUse = desiredName; string path = System.IO.Path.Combine(Path, nameToUse); if (Root.FileExists(path)) { if (option == CreationCollisionOption.GenerateUniqueName) { string desiredRoot = System.IO.Path.GetFileNameWithoutExtension(desiredName); string desiredExtension = System.IO.Path.GetExtension(desiredName); for (int num = 2; Root.FileExists(path); num++) { nameToUse = desiredRoot + " (" + num + ")" + desiredExtension; path = System.IO.Path.Combine(Path, nameToUse); } InternalCreateFile(path); } else if (option == CreationCollisionOption.ReplaceExisting) { Root.DeleteFile(path); InternalCreateFile(path); } else if (option == CreationCollisionOption.FailIfExists) { throw new IOException("File already exists: " + path); } else if (option == CreationCollisionOption.OpenIfExists) { // No operation } else { throw new ArgumentException("Unrecognized CreationCollisionOption: " + option); } } else { // Create file InternalCreateFile(path); } var ret = new IsoStoreFile(nameToUse, this); return(ret); }
/// <summary> /// Gets a file in this folder /// </summary> /// <param name="name">The name of the file to get</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The requested file, or null if it does not exist</returns> public async Task <IFile> GetFileAsync(string name, CancellationToken cancellationToken) { Requires.NotNullOrEmpty(name, "name"); await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); EnsureExists(); string path = System.IO.Path.Combine(Path, name); if (!Root.FileExists(path)) { throw new PCLStorage.Exceptions.FileNotFoundException("File does not exist: " + path); } var ret = new IsoStoreFile(name, this); return(ret); }
/// <summary> /// Creates a file in this folder /// </summary> /// <param name="desiredName">The name of the file to create</param> /// <param name="option">Specifies how to behave if the specified file already exists</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The newly created file</returns> public async Task<IFile> CreateFileAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken) { Requires.NotNullOrEmpty(desiredName, "desiredName"); await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); EnsureExists(); string nameToUse = desiredName; string path = System.IO.Path.Combine(Path, nameToUse); if (Root.FileExists(path)) { if (option == CreationCollisionOption.GenerateUniqueName) { string desiredRoot = System.IO.Path.GetFileNameWithoutExtension(desiredName); string desiredExtension = System.IO.Path.GetExtension(desiredName); for (int num = 2; Root.FileExists(path) ; num++) { nameToUse = desiredRoot + " (" + num + ")" + desiredExtension; path = System.IO.Path.Combine(Path, nameToUse); } InternalCreateFile(path); } else if (option == CreationCollisionOption.ReplaceExisting) { Root.DeleteFile(path); InternalCreateFile(path); } else if (option == CreationCollisionOption.FailIfExists) { throw new IOException("File already exists: " + path); } else if (option == CreationCollisionOption.OpenIfExists) { // No operation } else { throw new ArgumentException("Unrecognized CreationCollisionOption: " + option); } } else { // Create file InternalCreateFile(path); } var ret = new IsoStoreFile(nameToUse, this); return ret; }
/// <summary> /// Gets a file in this folder /// </summary> /// <param name="name">The name of the file to get</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The requested file, or null if it does not exist</returns> public async Task<IFile> GetFileAsync(string name, CancellationToken cancellationToken) { Requires.NotNullOrEmpty(name, "name"); await AwaitExtensions.SwitchOffMainThreadAsync(cancellationToken); EnsureExists(); string path = System.IO.Path.Combine(Path, name); if (!Root.FileExists(path)) { throw new PCLStorage.Exceptions.FileNotFoundException("File does not exist: " + path); } var ret = new IsoStoreFile(name, this); return ret; }