Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
Support reading fonts from files (#14783)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow authored Apr 26, 2023
1 parent aa67f0b commit c05a915
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 25 deletions.
25 changes: 0 additions & 25 deletions src/FileSystem/FileSystem.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,6 @@ Task<bool> PlatformAppPackageFileExistsAsync(string filename)
}
}

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 == 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 partial class FileBase
{
internal FileBase(IStorageFile file)
Expand Down
52 changes: 52 additions & 0 deletions src/FileSystem/FileSystemUtils.uwp.cs
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;
}
}
}

0 comments on commit c05a915

Please sign in to comment.