Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(skia): Enable StorageFile.GetFileFromApplicationUri
- Loading branch information
Showing
2 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} | ||
} | ||
} |