Skip to content

Commit

Permalink
feat(skia): Enable StorageFile.GetFileFromApplicationUri
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpinedam committed Jan 6, 2021
1 parent 9076e43 commit f910b24
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Uno.UWP/Storage/StorageFile.cs
Expand Up @@ -24,11 +24,11 @@ public static IAsyncOperation<StorageFile> GetFileFromPathAsync(string path)
internal static StorageFile GetFileFromPath(string path)
=> new StorageFile(new Local(path));

[NotImplemented("NET461", "__SKIA__", "__NETSTD_REFERENCE__")]
[NotImplemented("NET461", "__NETSTD_REFERENCE__")]
public static IAsyncOperation<StorageFile> GetFileFromApplicationUriAsync(Uri uri)
=> AsyncOperation.FromTask(ct => GetFileFromApplicationUri(ct, uri));

#if NET461 || __SKIA__ || __NETSTD_REFERENCE__
#if NET461 || __NETSTD_REFERENCE__
private static Task<StorageFile> GetFileFromApplicationUri(CancellationToken ct, Uri uri)
=> throw new NotImplementedException();
#endif
Expand Down
34 changes: 34 additions & 0 deletions src/Uno.UWP/Storage/StorageFile.skia.cs
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Windows.Storage
{
partial class StorageFile
{
private static async Task<StorageFile> GetFileFromApplicationUri(CancellationToken ct, Uri uri)
{
if (uri.Scheme != "ms-appx")
{
throw new InvalidOperationException("Uri is not using the ms-appx scheme");
}

var path = uri.PathAndQuery.TrimStart(new char[] { '/' });

var baseDir = global::System.IO.Path.GetDirectoryName(global::System.Reflection.Assembly.GetExecutingAssembly().Location);
var resourcePathname = global::System.IO.Path.Combine(baseDir, path);

if (resourcePathname != null)
{
return await StorageFile.GetFileFromPathAsync(resourcePathname);
}
else
{
throw new FileNotFoundException($"The file [{path}] cannot be found in the package directory");
}
}
}
}

0 comments on commit f910b24

Please sign in to comment.