2023-10-08 18:09:54 +00:00
|
|
|
using System.Reflection;
|
2023-10-20 04:59:28 +00:00
|
|
|
using System.Text;
|
2023-10-08 18:09:54 +00:00
|
|
|
using System.Web;
|
2023-10-09 02:27:47 +00:00
|
|
|
using HeyRed.Mime;
|
2023-10-08 18:09:54 +00:00
|
|
|
|
|
|
|
namespace Shoko;
|
|
|
|
|
|
|
|
[Protocol("res")]
|
|
|
|
class ResProtoHandler : ProtoHandler
|
|
|
|
{
|
|
|
|
public ResProtoHandler(Uri url)
|
|
|
|
{
|
|
|
|
URL = url;
|
|
|
|
}
|
|
|
|
|
2023-10-20 04:59:28 +00:00
|
|
|
public override async Task Load()
|
2023-10-08 18:09:54 +00:00
|
|
|
{
|
2023-10-20 04:59:28 +00:00
|
|
|
var path = HttpUtility.HtmlDecode(URL.AbsolutePath);
|
2023-10-08 18:09:54 +00:00
|
|
|
Status = "OK";
|
|
|
|
try
|
|
|
|
{
|
2023-10-20 04:59:28 +00:00
|
|
|
Content = await Download(Assembly.GetExecutingAssembly().GetManifestResourceStream(path));
|
2023-10-09 02:27:47 +00:00
|
|
|
MediaType = MimeGuesser.GuessMimeType(Content);
|
2023-10-08 18:09:54 +00:00
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
2023-10-20 04:59:28 +00:00
|
|
|
Content = new MemoryStream(Encoding.UTF8.GetBytes("resource not found"));
|
|
|
|
MediaType = "text/plain";
|
2023-10-08 18:09:54 +00:00
|
|
|
Status = "not found";
|
|
|
|
}
|
2023-10-20 04:59:28 +00:00
|
|
|
OnLoaded();
|
2023-10-08 18:09:54 +00:00
|
|
|
}
|
|
|
|
public override void Render()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|