Ejemplo n.º 1
0
        private void OnWebResourceRequested(WebView sender, WebViewWebResourceRequestedEventArgs args)
        {
            HttpResponseMessage response = null;
            var str = args.Request.RequestUri.OriginalString;

            if (str.StartsWith(FakeHttpPrefix))
            {
                var requestString = str.Replace(FakeHttpPrefix, "");
                // e.g. =@public@vhost@g@gutenberg@html@files@61533@61533-h@[email protected]
                if (true || requestString.Contains("@images"))
                {
                    var requestedFile = EpubWizard.GetInternalFileByName(EpubBook, requestString);
                    if (requestedFile != null)
                    {
                        if (requestString.EndsWith(".css"))
                        {
                            var changed = CssFixup.FixupCss(requestedFile);
                            if (changed)
                            {
                                ;
                            }
                        }
                        if (Logger.LogAllResourceLoads)
                        {
                            Logger.Log($"MainEpubReader:OnWebResourceRequested: FOUND internal asset request {requestString}");
                        }
                        response = new HttpResponseMessage(HttpStatusCode.Ok)
                        {
                            Content = new HttpBufferContent(requestedFile.Content.AsBuffer()),
                        };
                        //response.Content.Headers.ContentType
                    }
                    else
                    {
                        Logger.Log($"MainEpubReader:OnWebResourceRequested: Can't find request {requestString}");
                    }
                }
            }
            else
            {
                // Is a link in the book. Just jump to it via external browser.
                App.Error($"Weird: HTTP is requesting {str}");
                Logger.Log($"MainEpubReader:WebResourceRequested: External URL URL={str}");
            }
            if (response == null)
            {
                response = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    ReasonPhrase = "Cant find embedded resource",
                };
            }
            args.Response = response;
        }
Ejemplo n.º 2
0
 public EpubFile GetImageByName(string imageName)
 {
     return(EpubWizard.GetInternalFileByName(EpubBook, imageName));
 }