Load html file from disk using CefGlue - chromium-embedded

I am playing with CefGlue (the .net wrapper around chromium embedded") I need to make some proof of concept so I create my own special html files that contains what I need to test. However I can't find a way to load those files.
The CefBrowserHost.CreateBrowser(cefWindowInfo, cefClient, cefBrowserSettings, url); requires an url and there is no overloaded method that accepts the content as string. So the question is: How to load html file from disk?

I've not used CefGlue - but in general you can use a custom cef resource handler to load the file. Briefly, when CEF sees your URL, they will call through a resource override handler you set up, which will then read that resource into a byte stream. In our case we read an html file compiled into our application resources. In your case I suppose you could also read the resource from disk at that time, though I've not done this. If you can compile resources into your C# app, you can add the html file into the Resources if you prefer.
We pass the url to CreateBrowserSync() in our case, and CEF ends up calling our ResourceHandler to load it. The CefClient c++ sample has an excellent example of this, see resource_util_win.cpp.
This is set up in a Handler override in CefResourceHandler. We overrode GetResourceHandler, their example overrides ProcessRequest in SchemeHandler. See scheme_test.cpp in the CefClient sample.
Most of the code from their samples is pretty boiler plate and you should be able to use what they have as the basis for your implementation - it's really too much code to list it all out here though.

I found a solution: just pass the full path to the file in the url parameter and everything works fine. It's just like chrome opening file from disk so I don't know why I did not tried that the first time.

Related

How to play a .ts file in Edge browser with Apache2

I use Apache2’s mod-autoindex to build a directory listing of files in a folder and MS Edge to display the list. When I click on a .mp4 file, Edge opens a video player embedded in the browser and correctly plays the video. When I click on a .ts file, Edge again opens the embedded player, but nothing plays. I have installed the MPEG-2 Video Extension app from the MS Store and Windows’ built-in Movies and TV app now successfully plays both .mp4 and .ts files when I select them from within Windows Explorer. But Edge still can’t play the .ts file.
The html generated when I click the .ts file includes the element <source src="https://my.site/foldername/filename.ts" type="video/mp2t">
I conclude that whatever player is invoked by Edge doesn’t know how to deal with the video/mp2t file type.
Can anyone help me find a way to either (1) change the way Apache2 generates the html to specify type="video/.ts" or (2) cause the file click to invoke an external player such as Windows’ Movies and TV app rather than Edge’s embedded player?
You just can't play .ts video file in Edge because it's not supported by Edge. From this doc, you can see that only Safari supports MPEG-2. Besides, MPEG-2 Video Extension can only help play MPEG videos in video apps, not Edge.
For your questions:
video/mp2t is the right MIME type for .ts file. You can't change it to video/.ts which is wrong and useless.
You can't open the default media player without downloading the file. So I think it's impossible.
Since my OP in August, I discovered and implemented a somewhat complex, but perfectly functional way to do what I wanted to do. Herewith, a summary of what I did:
Tiring of the limitations of Apache2’s mod_autoindex, I developed my own custom index.php to replace it. Once I had full control over the format and content of the index, I discovered this SO thread wherein #Jun Hsieh provides a detailed discussion of this former MSDN link, which describes the process for Registering an Application to a URI Scheme.
I followed those instructions to create a custom URI handler that will invoke a DOS batch script on my client. Then I coded my index.php to create an HTML anchor with an HREF that invokes my custom URI, including the path to the desired file. When the link is clicked, the browser invokes the URI handler, which invokes the DOS batch script, which validates the file name and proceeds to invoke Microsoft’s MediaPlayer, which includes a codec that can play a network-resident Transport Stream (.ts) file directly, without requiring it to be fully downloaded to the client. The MediaPlayer also has user controls superior to those available in the video player embedded in the Edge browser.
Of course, the custom URI handler is not limited to invoking Microsoft's MediaPlayer and could invoke any app installed on my client PC.
Note that the browser (in this case Edge) will percent-encode the file name passed to the URI handler (i.e. spaces are converted to %20, etc.) so file/folder names that include ‘special’ characters (such as almost every non-letter/number) must be decoded upon receipt to remove the encoding before passing them to the desired app. File/folder names that include characters such as semi-colon, single-quote, and similar characters (perfectly legal in Windows file names) are particularly problematic and must be appropriately handled by the app invoked by the custom URI handler.
Of course, my solution works only on a Windows client, which is OK for me now because I currently do not have any Linux clients on my home network. But believe that it may be possible to create custom handlers on Linux clients as described in this post.
Yes, I’m aware of the potential security risks of this implementation. But my web server serves only the local network within my home. And it now allows me to use a browser as the single UI to browse and stream web content as well as local content. Just what I had been trying to do. Perhaps others will find this information of interest.

Serilog in UWP is not writing the log in D drive

I am using Serilog in my UWP application. I can write the log in App LocalState folder without any issue.
But now I want to write the logs in D: drive specific folder. I have added the broadFileSystemAccess restricted capability and enabled the full access from the settings.
But still it is not creating the file in the specified location and not raising any error.
Anyone know the fix for this? Thanks in advance.
var file = #"D:\Logs\Serilog.txt";
Serilog.Log.Logger = new LoggerConfiguration().WriteTo.File(file).CreateLogger();
There is a very important information about broadFileSystemAccess capability on the File access permissions document. I'm not sure if you note it.
This broadFileSystemAccess capability only works for APIs in the Windows.Storage namespace.
This point is very important. So, your issue actually is you need to check the LoggerConfiguration().WriteTo.File(file).CreateLogger() relevant method if it write to files by using the Windows.Storage APIs.
By my checking, it uses the StreamWriter method to write to files. But this method is not included in the Windows.Storage APIs. So, the issue was very obvious. You need to submit this issue to Github and let the officials to modify this method and make it work in UWP.
Or, if you're interested in serilog-sinks-file source code, you could download it and make the change by yourself, Then, you could compile a custom serilog library version for your UWP project.

How to copy resources from one executable to other

Ok my question is a little odd. But here we go.
I am trying to develop an executable file "wrapper" and a console program. The task of the console program is to copy Icons and Version Informations from another exe file to the wrapper file so that both the wrapper file and the exe file looks exactly same. Apart from that the exe file is appended to the wrapper file at the end. So that when the wrapper is executed it can extract and execute the appended exe file.
My question is how do I create the wrapper file so as to accomodate the Icons and Version info from other exe file ? I mean How should my resource file be ?
And next is How to copy Icons and version info. I hv searched and found a few codes and MSDN instructions but everyone of them uses FindResource, LoadResource, etc. But by following this method, I am losing the original contents of the wrapper file. The size of my file reduces from originally 67kb to 14kb and when I open up in notepad, I see lots of contents are gone ...
can anything be done by using SHGetFileInfo() ? This can be used to get HICON from the exe file. but how do I use this HICON to replace the icon resource in the wrapper file ??
The basic approach in your previous question is correct. You definitely don't want to be mucking around with SHGetFileInfo and HICONs. The type of resource shouldn't matter.
Your wrapper should start with no resources. This ensures, for example, that any icon you add will be both first and lowest numbered and thus guaranteed to be used as the app icon.
To understand what's happening with your code, use a tool that can view the resources in the resulting exe. Visual C++ Express can't do this, but the paid versions can. Alternatively, Google turns up a bunch of free utilities to do this. Here's one, I don't know if it's any good. The page also contains links to some other tools.

Accessing embedded resources from MEF loaded XAPs

Simple question.
So MEF doesn't support importing or exporting loose files (such as xml files) etc.
However, it should at least support embedded resources right?
I currently have a silverlight application that loads xaps dynamically. These dynamically loaded xaps each have an xml file attached as an embedded resource accesible via an instance method that looks something like this...
public XDocument MenuStructure
{
get
{
return XDocument.Load("myFile.xml");
}
}
However, this property fails after import with a message saying "Cannot find file 'myFile.xml' in the application xap package."
I'm not sure whether the problem is how I'm accessing the file now that it's BuildAction is set to EmbeddedResource or not.
Any ideas?
Thanks
Ok, according to http://msdn.microsoft.com/en-us/library/ms596994(VS.95).aspx I was supposed to use Application.GetResourceStream. Everything works great now.
You are correct that MEF does not support loading resources from secondary downloaded XAP's. You can however do embedded resources (embedded in the assembly not the XAP) but the way you are accessing it will not pull the file from the embedded resources.
For BuildAction EmbeddedResource you will need to get the stream from the Assembly.GetManifestResourceStream(...)(http://msdn.microsoft.com/en-us/library/xc4235zt.aspx).
For BuildAction Resource you will need to build a proper pack uri (see Resource File Pack URIs - Referenced Assembly in http://msdn.microsoft.com/en-us/library/aa970069(VS.85).aspx) and pass to Application.GetResourceStream (I'm actually not entirely sure if this approach works for dynamically loaded XAPs or not).

Silverlight 4 MediaElement play sound

I converted a local sound file to a resource, which built this in my XAML:
<UserControl.Resources>
<my:Uri x:Key="SoundFiles">file:///c:/Audio/HebrewDemo/Shalom.wav</my:Uri>
</UserControl.Resources>
I did this by pasting a local disk mp3 filename into source, then clicked on the "dot" by source and chose "Extract Value to Resource".
When I run, it tells me that "Uri" is not valid, and sure enough, in the Intellisense, I see other elements that start with "uri" but not just URI by itself.
In the real world I want to specify a dynamic mp3 file name. For example, I might have a database of foreign language words used for flashcards, I want to play a sound file on a URL. But I thought I would try to walk before running...
Now I'm trying this:
mediaElement1.Source = new Uri(
"http://HebrewResources.com/SoundFiles/Shalom.mp3",
UriKind.Absolute);
mediaElement1.Play();
The status bar in the FireFox browser indicates some data being transferred from the website. However, I never hear any sound. Could it just be an encoding issue? If it is not encoded properly, would I get an error?
Also, can I put the Uri statement in the load or make it run in the background, so the user can read the screen, at the same time the sound file is downloading? In other words, when he clicks the button to hear the soundfile, ideally it would already be preloaded for him. In this language-learning app, the user will see a word in a foreign language, and try to pronounce it himself, then he will click the "Play" button to hear the sound to check his results.
The first code which points to the local file won't work in a normal Silverlight application because of Silverlights "sanboxed" security model. Running a normal Silverlight application in your browser, you can't access local resources like you can if you were running an installed winforms/WPF application. Have a look at this video tutorial http://www.silverlight.net/learn/videos/all/local-file-access/, if you want to learn more about accessing local files using Silverlight.
In regards to your second piece of code, it should work, so quite possibly it's an encoding issue, and no unfortunately you often don't get any errors for things like that.
I created a sample app and pointed it at your mp3 file and it' wouldn't work, however a quick search for sample mp3s, lead me to another freely available (first hit). Using the code/url below, it works ok.
myMediaelement.Source = new Uri("http://www.robtowns.com/music/blind_willie.mp3", UriKind.Absolute);
In regards to the loading, it will start downloading the file when it hits the code that sets the source of the mediaelement. So if you set the source for the media element in your constructor or in your loaded event, it will automatically start downloading in the background. Then you just call myMediaelement.Play(); on the button click event.
If you find using Firefox a bit limited, when it comes to determine what and when something like external files or webservices are being loaded. There's a great free tool called Fiddler (http://www.fiddlertool.com/fiddler/version.asp) which will let you monitor those things very easily.
Good luck :)

Resources