2014-03-29, 08:01 PM
I needed a way to get the show images from the server in a Win 8 metro app on a client machine. Nothing I tried worked (seriously walled garden) so I looked into using public/Download.ashx but I would get a E_NETWORK_ERROR in my app because of the way the response/content-type was being written from the web service.
I changed "case FanArt:" to work the way I needed it. Images are now displayed inline in IE instead of being downloaded and displayed in a separate app.
I changed "case FanArt:" to work the way I needed it. Images are now displayed inline in IE instead of being downloaded and displayed in a separate app.
Code:
case (int)InternalFiles.FanArt:
/*
Can be used to download any image.
Supports the following variables (trailing backslash not required):
[[DataDir]] = NPVR data directory.
[[MediaDir]] = NPVR data directory + "Media\\"
[[MediaShowsDir]] = NPVR data directory + "Media\\Shows\\"
Notes:
DO NOT INCLUDE FILE EXTENSIONS... the request will automatically check for ".png" then for ".jpg".
Filenames should already be parsed to remove invalid filename characters and trimmed.
If no image is found, it will return "no_album_art.jpg".
Example:
// Download the image for the show "2 Broke Girls *" from Media\Shows:
{
string showName = "2 Broke Girls *";
string url = @"http://localhost:8866/public/download.ashx/-11,1?[[MediaShowsDir]]" + string.Join(string.Empty, rName.Split(System.IO.Path.GetInvalidFileNameChars())).Trim();
// Download the image from "url"
}
*/
fileName = path.Replace("[[DataDir]]", SettingsHelper.GetInstance().GetDataDirectory());
fileName = fileName.Replace("[[MediaDir]]", SettingsHelper.GetInstance().GetDataDirectory() + "Media\\");
fileName = fileName.Replace("[[MediaShowsDir]]", SettingsHelper.GetInstance().GetDataDirectory() + "Media\\Shows\\");
if (File.Exists(fileName + ".png"))
{
fileName += ".png";
Response.ContentType = "image/png";
}
else
{
if (File.Exists(fileName + ".jpg"))
fileName += ".jpg";
else
fileName = SettingsHelper.GetInstance().GetDataDirectory() + "web\\themes2\\common\\graphics\\no_album_art.jpg";
Response.ContentType = "image/jpeg";
}
Image fanArtImg = new Bitmap(fileName);
ImageConverter fanArtConverter = new ImageConverter();
Response.BinaryWrite((byte[])fanArtConverter.ConvertTo(fanArtImg, typeof(byte[])));
Response.End();
fanArtImg.Dispose();
seekable = false;
break;