Skip to content

Commit

Permalink
fix: cleaned code
Browse files Browse the repository at this point in the history
  • Loading branch information
arqueror committed Dec 23, 2022
1 parent 27015f6 commit 449f6cc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Uno.UI.Toolkit/Storage/StorageFile.windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ partial class StorageFileHelper
private static Task<bool> FileExistsInPackage(string fileName)
{
var executingPath = Assembly.GetExecutingAssembly().Location;
if (!string.IsNullOrWhiteSpace(executingPath))
if (!string.IsNullOrEmpty(executingPath))
{
var path = Path.GetDirectoryName(executingPath);
if (!string.IsNullOrWhiteSpace(path))
if (!string.IsNullOrEmpty(path))
{
var fullPath = Path.Combine(path, fileName);
return Task.FromResult(File.Exists(fullPath));
Expand Down
11 changes: 5 additions & 6 deletions src/Uno.UI.Toolkit/Storage/StorageFileHelper.Android.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
#if __ANDROID__
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -11,7 +10,7 @@ namespace Uno.UI.Toolkit;

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

private static Task<bool> FileExistsInPackage(string fileName)
{
Expand All @@ -20,8 +19,9 @@ 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 (!_scannedFiles.Any())
if (_scannedFiles is null)
{
_scannedFiles = new List<string>();
ScanPackageAssets(_scannedFiles);
}

Expand Down Expand Up @@ -76,15 +76,15 @@ private static bool ScanPackageAssets(ICollection<string> scannedFiles, string r
{
foreach (var file in paths)
{
string path = string.IsNullOrWhiteSpace(rootPath) ? file : Path.Combine(rootPath, file);
string path = string.IsNullOrEmpty(rootPath) ? file : Path.Combine(rootPath, file);
if (!ScanPackageAssets(scannedFiles, path))
{
return false;
}

if (path.Contains('.'))
{
scannedFiles.Add(Path.GetFileNameWithoutExtension(path) + Path.GetExtension(path));
scannedFiles.Add(Path.GetFileName(path));
}
}
}
Expand All @@ -98,4 +98,3 @@ private static bool ScanPackageAssets(ICollection<string> scannedFiles, string r
}
}

#endif
5 changes: 1 addition & 4 deletions src/Uno.UI.Toolkit/Storage/StorageFileHelper.iOSmacOS.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
#if __IOS__ || __MACCATALYST__ || __MACOS__
using System.Reflection;
using System.Threading;
using System;
Expand All @@ -15,7 +14,7 @@ partial class StorageFileHelper
{
private static Task<bool> FileExistsInPackage(string fileName)
{
var directoryName = global::System.IO.Path.GetDirectoryName(fileName) + string.Empty;
var directoryName = global::System.IO.Path.GetDirectoryName(fileName) ?? string.Empty;
var fn = global::System.IO.Path.GetFileNameWithoutExtension(fileName);
var fileExtension = global::System.IO.Path.GetExtension(fileName);

Expand All @@ -24,5 +23,3 @@ private static Task<bool> FileExistsInPackage(string fileName)
return Task.FromResult(resourcePathname != null);
}
}

#endif

0 comments on commit 449f6cc

Please sign in to comment.