Skip to content

Commit

Permalink
fix: Fixed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arqueror committed Dec 16, 2022
1 parent 64dc566 commit 8e60f99
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/Uno.UWP/Storage/Helpers/AssetsManager.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal partial class AssetsManager
private static readonly Lazy<Task<HashSet<string>>> _assets = new Lazy<Task<HashSet<string>>>(() => GetAssets(CancellationToken.None));
private static readonly ConcurrentEntryManager _assetsGate = new ConcurrentEntryManager();

private static async Task<HashSet<string>> GetAssets(CancellationToken ct)
internal static async Task<HashSet<string>> GetAssets(CancellationToken ct)
{
var assetsUri = AssetsPathBuilder.BuildAssetUri("uno-assets.txt");

Expand Down
19 changes: 2 additions & 17 deletions src/Uno.UWP/Storage/Helpers/StorageFile.wasm.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
#nullable enable
using System.Threading;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Uno.Extensions;
using Uno.Foundation;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Windows.Storage.Helpers;

partial class StorageFileHelper
{
private static string assets { get; set; } = string.Empty;
private static async Task<bool> FileExistsInPackage(string fileName)
{
if (string.IsNullOrEmpty(assets))
{
var assetsUri = AssetsPathBuilder.BuildAssetUri("uno-assets.txt");
assets = await WebAssemblyRuntime.InvokeAsync($"Windows.Storage.AssetManager.DownloadAssetsManifest(\'{assetsUri}\')");
}

var assetsHash = new HashSet<string>(Regex.Split(assets, "\r\n|\r|\n"), StringComparer.OrdinalIgnoreCase);

return assetsHash?.Contains(fileName) ?? false;
var assets = await AssetsManager.GetAssets(CancellationToken.None);
return assets?.Contains(fileName) ?? false;
}
}
14 changes: 7 additions & 7 deletions src/Uno.UWP/Storage/Helpers/StorageFileHelper.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Windows.Storage.Helpers;

partial class StorageFileHelper
{
private static List<string> files { get; set; } = new List<string>();
private static ICollection<string> _scannedFiles { get; set; } = new List<string>();

private static Task<bool> FileExistsInPackage(string fileName)
{
Expand All @@ -19,12 +19,12 @@ private static Task<bool> FileExistsInPackage(string fileName)

//Get only the filename with extension and apply internal UNO naming rules so we are able to find the compiled resources by replacing '.' and '-' by underscore.
var normalizedFileName = Path.GetFileNameWithoutExtension(fileName).Replace('.', '_').Replace('-', '_') + Path.GetExtension(fileName);
if (!files.Any())
if (!_scannedFiles.Any())
{
ScanPackageAssets(context.Assets!, files);
ScanPackageAssets(_scannedFiles);
}

if (files.Contains(normalizedFileName))
if (_scannedFiles.Contains(normalizedFileName))
{
return Task.FromResult(true);
}
Expand Down Expand Up @@ -64,17 +64,17 @@ private static Task<bool> FileExistsInPackage(string fileName)

//This method will scan for all the assets within current package
//This method will return a list of {file}.{extension}
private static bool ScanPackageAssets(AssetManager assets, List<string> files, string rootPath = "")
private static bool ScanPackageAssets(ICollection<string> files, string rootPath = "")
{
try
{
var Paths = assets?.List(rootPath);
var Paths = global::Android.App.Application.Context.Assets?.List(rootPath);
if (Paths?.Length > 0)
{
foreach (var file in Paths)
{
string path = string.IsNullOrWhiteSpace(rootPath) ? file : Path.Combine(rootPath, file);
if (!ScanPackageAssets(assets!, files, path))
if (!ScanPackageAssets(files, path))
{
return false;
}
Expand Down

0 comments on commit 8e60f99

Please sign in to comment.