|
|
@ -3,11 +3,9 @@ |
|
|
|
|
|
|
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Globalization; |
|
|
|
|
|
using System.IO; |
|
|
using System.IO; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Reflection; |
|
|
using System.Reflection; |
|
|
using System.Resources; |
|
|
|
|
|
using Perspex.Platform; |
|
|
using Perspex.Platform; |
|
|
|
|
|
|
|
|
namespace Perspex.Shared.PlatformSupport |
|
|
namespace Perspex.Shared.PlatformSupport |
|
|
@ -20,7 +18,6 @@ namespace Perspex.Shared.PlatformSupport |
|
|
private static readonly Dictionary<string, Assembly> AssemblyNameCache |
|
|
private static readonly Dictionary<string, Assembly> AssemblyNameCache |
|
|
= new Dictionary<string, Assembly>(); |
|
|
= new Dictionary<string, Assembly>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Assembly GetAssembly(string name) |
|
|
static Assembly GetAssembly(string name) |
|
|
{ |
|
|
{ |
|
|
Assembly rv; |
|
|
Assembly rv; |
|
|
@ -31,6 +28,20 @@ namespace Perspex.Shared.PlatformSupport |
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Checks if an asset with the specified URI exists.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="uri">The URI.</param>
|
|
|
|
|
|
/// <returns>True if the asset could be found; otherwise false.</returns>
|
|
|
|
|
|
public bool Exists(Uri uri) |
|
|
|
|
|
{ |
|
|
|
|
|
var parts = uri.AbsolutePath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); |
|
|
|
|
|
var asm = parts.Length == 1 ? Assembly.GetEntryAssembly() : GetAssembly(parts[0]); |
|
|
|
|
|
var typeName = parts[parts.Length == 1 ? 0 : 1]; |
|
|
|
|
|
var rv = asm.GetManifestResourceStream(typeName); |
|
|
|
|
|
return rv != null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Opens the resource with the requested URI.
|
|
|
/// Opens the resource with the requested URI.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -46,7 +57,7 @@ namespace Perspex.Shared.PlatformSupport |
|
|
var typeName = parts[parts.Length == 1 ? 0 : 1]; |
|
|
var typeName = parts[parts.Length == 1 ? 0 : 1]; |
|
|
var rv = asm.GetManifestResourceStream(typeName); |
|
|
var rv = asm.GetManifestResourceStream(typeName); |
|
|
if (rv == null) |
|
|
if (rv == null) |
|
|
throw new FileNotFoundException(uri.ToString()); |
|
|
throw new FileNotFoundException($"The resource {uri} could not be found."); |
|
|
return rv; |
|
|
return rv; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|