|
|
@@ -8,48 +8,47 @@ namespace Avalonia.Platform.Storage;
|
|
|
/// </summary>
|
|
|
public static class StorageProviderExtensions
|
|
|
{
|
|
|
- /// <inheritdoc cref="IStorageProvider.TryGetFileFromPath"/>
|
|
|
- public static Task<IStorageFile?> TryGetFileFromPath(this IStorageProvider provider, string filePath)
|
|
|
+ /// <inheritdoc cref="IStorageProvider.TryGetFileFromPathAsync"/>
|
|
|
+ public static Task<IStorageFile?> TryGetFileFromPathAsync(this IStorageProvider provider, string filePath)
|
|
|
{
|
|
|
- return provider.TryGetFileFromPath(StorageProviderHelpers.FilePathToUri(filePath));
|
|
|
+ return provider.TryGetFileFromPathAsync(StorageProviderHelpers.FilePathToUri(filePath));
|
|
|
}
|
|
|
|
|
|
- /// <inheritdoc cref="IStorageProvider.TryGetFolderFromPath"/>
|
|
|
- public static Task<IStorageFolder?> TryGetFolderFromPath(this IStorageProvider provider, string folderPath)
|
|
|
+ /// <inheritdoc cref="IStorageProvider.TryGetFolderFromPathAsync"/>
|
|
|
+ public static Task<IStorageFolder?> TryGetFolderFromPathAsync(this IStorageProvider provider, string folderPath)
|
|
|
{
|
|
|
- return provider.TryGetFolderFromPath(StorageProviderHelpers.FilePathToUri(folderPath));
|
|
|
+ return provider.TryGetFolderFromPathAsync(StorageProviderHelpers.FilePathToUri(folderPath));
|
|
|
}
|
|
|
|
|
|
- internal static string? TryGetFullPath(this IStorageFolder folder)
|
|
|
+ /// <summary>
|
|
|
+ /// Gets the local file system path of the item as a string.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="item">Storage folder or file.</param>
|
|
|
+ /// <returns>Full local path to the folder or file if possible, otherwise null.</returns>
|
|
|
+ /// <remarks>
|
|
|
+ /// Android platform usually uses "content:" virtual file paths
|
|
|
+ /// and Browser platform has isolated access without full paths,
|
|
|
+ /// so on these platforms this method will return null.
|
|
|
+ /// </remarks>
|
|
|
+ public static string? TryGetLocalPath(this IStorageItem item)
|
|
|
{
|
|
|
// We can avoid double escaping of the path by checking for BclStorageFolder.
|
|
|
// Ideally, `folder.Path.LocalPath` should also work, as that's only available way for the users.
|
|
|
- if (folder is BclStorageFolder storageFolder)
|
|
|
+ if (item is BclStorageFolder storageFolder)
|
|
|
{
|
|
|
return storageFolder.DirectoryInfo.FullName;
|
|
|
}
|
|
|
-
|
|
|
- if (folder.Path is { IsAbsoluteUri: true, Scheme: "file" } absolutePath)
|
|
|
- {
|
|
|
- return absolutePath.LocalPath;
|
|
|
- }
|
|
|
-
|
|
|
- // android "content:", browser and ios relative links go here.
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- internal static string? TryGetFullPath(this IStorageFile file)
|
|
|
- {
|
|
|
- if (file is BclStorageFile storageFolder)
|
|
|
+ if (item is BclStorageFile storageFile)
|
|
|
{
|
|
|
- return storageFolder.FileInfo.FullName;
|
|
|
+ return storageFile.FileInfo.FullName;
|
|
|
}
|
|
|
|
|
|
- if (file.Path is { IsAbsoluteUri: true, Scheme: "file" } absolutePath)
|
|
|
+ if (item.Path is { IsAbsoluteUri: true, Scheme: "file" } absolutePath)
|
|
|
{
|
|
|
return absolutePath.LocalPath;
|
|
|
}
|
|
|
|
|
|
+ // android "content:", browser and ios relative links go here.
|
|
|
return null;
|
|
|
}
|
|
|
}
|