|
|
|
@ -32,6 +32,7 @@ internal abstract class IOSStorageItem : IStorageBookmarkItem |
|
|
|
} |
|
|
|
|
|
|
|
internal NSUrl Url { get; } |
|
|
|
internal string FilePath => _filePath; |
|
|
|
|
|
|
|
public bool CanBookmark => true; |
|
|
|
|
|
|
|
@ -54,6 +55,38 @@ internal abstract class IOSStorageItem : IStorageBookmarkItem |
|
|
|
return Task.FromResult<IStorageFolder?>(new IOSStorageFolder(Url.RemoveLastPathComponent())); |
|
|
|
} |
|
|
|
|
|
|
|
public Task DeleteAsync() |
|
|
|
{ |
|
|
|
return NSFileManager.DefaultManager.Remove(Url, out var error) |
|
|
|
? Task.CompletedTask |
|
|
|
: Task.FromException(new NSErrorException(error)); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<IStorageItem?> MoveAsync(IStorageFolder destination) |
|
|
|
{ |
|
|
|
if (destination is not IOSStorageFolder folder) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("Destination folder must be initialized the StorageProvider API."); |
|
|
|
} |
|
|
|
|
|
|
|
var isDir = this is IStorageFolder; |
|
|
|
var newPath = new NSUrl(System.IO.Path.Combine(folder.FilePath, Name), isDir); |
|
|
|
|
|
|
|
if (NSFileManager.DefaultManager.Move(folder.Url, newPath, out var error)) |
|
|
|
{ |
|
|
|
return isDir |
|
|
|
? new IOSStorageFolder(newPath) |
|
|
|
: new IOSStorageFile(newPath); |
|
|
|
} |
|
|
|
|
|
|
|
if (error is not null) |
|
|
|
{ |
|
|
|
throw new NSErrorException(error); |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public Task ReleaseBookmarkAsync() |
|
|
|
{ |
|
|
|
// no-op
|
|
|
|
@ -149,4 +182,33 @@ internal sealed class IOSStorageFolder : IOSStorageItem, IStorageBookmarkFolder |
|
|
|
yield return item; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Task<IStorageFile?> CreateFileAsync(string name) |
|
|
|
{ |
|
|
|
var path = System.IO.Path.Combine(FilePath, name); |
|
|
|
NSFileAttributes? attributes = null; |
|
|
|
if (NSFileManager.DefaultManager.CreateFile(path, null, attributes)) |
|
|
|
{ |
|
|
|
return Task.FromResult<IStorageFile?>(new IOSStorageFile(new NSUrl(path, false))); |
|
|
|
} |
|
|
|
|
|
|
|
return Task.FromResult<IStorageFile?>(null); |
|
|
|
} |
|
|
|
|
|
|
|
public Task<IStorageFolder?> CreateFolderAsync(string name) |
|
|
|
{ |
|
|
|
var path = System.IO.Path.Combine(FilePath, name); |
|
|
|
NSFileAttributes? attributes = null; |
|
|
|
if (NSFileManager.DefaultManager.CreateDirectory(path, false, attributes, out var error)) |
|
|
|
{ |
|
|
|
return Task.FromResult<IStorageFolder?>(new IOSStorageFolder(new NSUrl(path, true))); |
|
|
|
} |
|
|
|
|
|
|
|
if (error is not null) |
|
|
|
{ |
|
|
|
throw new NSErrorException(error); |
|
|
|
} |
|
|
|
|
|
|
|
return Task.FromResult<IStorageFolder?>(null); |
|
|
|
} |
|
|
|
} |
|
|
|
|