-
Notifications
You must be signed in to change notification settings - Fork 50
/
KnownStaticFileProvider.cs
29 lines (24 loc) · 1.04 KB
/
KnownStaticFileProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System.Reflection;
namespace HybridWebView
{
internal static class KnownStaticFileProvider
{
private static readonly string[] KnownStaticFilesNames = { "HybridWebView.js" };
private static readonly Assembly ThisAssembly = typeof(KnownStaticFileProvider).Assembly;
private static readonly string KnownStaticFilePrefix = "_hwv" + Path.DirectorySeparatorChar;
public static Stream? GetKnownResourceStream(string resourceRelativeUrl)
{
resourceRelativeUrl = PathUtils.NormalizePath(resourceRelativeUrl);
if (!resourceRelativeUrl.StartsWith(KnownStaticFilePrefix, StringComparison.Ordinal))
{
return null;
}
var resourceName = resourceRelativeUrl.Substring(KnownStaticFilePrefix.Length);
if (!KnownStaticFilesNames.Contains(resourceName))
{
return null;
}
return ThisAssembly.GetManifestResourceStream("HybridWebView.KnownStaticFiles." + resourceName);
}
}
}