This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support reading fonts from files (#14783)
- Loading branch information
1 parent
aa67f0b
commit c05a915
Showing
2 changed files
with
52 additions
and
25 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,52 @@ | ||
#nullable enable | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.IO; | ||
using Microsoft.Maui.ApplicationModel; | ||
using Package = Windows.ApplicationModel.Package; | ||
|
||
namespace Microsoft.Maui.Storage | ||
{ | ||
static partial class FileSystemUtils | ||
{ | ||
public static bool AppPackageFileExists(string filename) | ||
{ | ||
var file = PlatformGetFullAppPackageFilePath(filename); | ||
return File.Exists(file); | ||
} | ||
|
||
public static string PlatformGetFullAppPackageFilePath(string filename) | ||
{ | ||
if (filename is null) | ||
throw new ArgumentNullException(nameof(filename)); | ||
|
||
filename = NormalizePath(filename); | ||
|
||
string root; | ||
if (AppInfoUtils.IsPackagedApp) | ||
root = Package.Current.InstalledLocation.Path; | ||
else | ||
root = AppContext.BaseDirectory; | ||
|
||
return Path.Combine(root, filename); | ||
} | ||
|
||
public static bool TryGetAppPackageFileUri(string filename, [NotNullWhen(true)] out string? uri) | ||
{ | ||
var path = PlatformGetFullAppPackageFilePath(filename); | ||
|
||
if (File.Exists(path)) | ||
{ | ||
if (AppInfoUtils.IsPackagedApp) | ||
uri = $"ms-appx:///{filename.Replace('\\', '/')}"; | ||
else | ||
uri = $"file:///{path.Replace('\\', '/')}"; | ||
|
||
return true; | ||
} | ||
|
||
uri = null; | ||
return false; | ||
} | ||
} | ||
} |