South Africa
public static readonly string Folders = Config.GetSubFolder(Config.Dir.Thumbs, @"Folders");
public static void CreateFolders()
{
...
System.IO.Directory.CreateDirectory(Folders);
...
}
public static void SetThumbnails(ref GUIListItem item)
{
if (item == null) return;
string strThumb = string.Empty;
if (!item.IsFolder || (item.IsFolder && VirtualDirectory.IsImageFile(System.IO.Path.GetExtension(item.Path).ToLower())))
{
if (IsPicture(item.Path)) return;
strThumb = System.IO.Path.ChangeExtension(item.Path, ".jpg");
if (!System.IO.File.Exists(strThumb))
{
strThumb = System.IO.Path.ChangeExtension(item.Path, ".tbn");
if (!System.IO.File.Exists(strThumb))
{
strThumb = System.IO.Path.ChangeExtension(item.Path, ".png");
if (!System.IO.File.Exists(strThumb))
{
strThumb = GetThumb(item.Path);
if (!System.IO.File.Exists(strThumb))
return;
}
}
}
// now strThumb exists
item.ThumbnailImage = strThumb;
item.IconImage = strThumb;
item.IconImageBig = strThumb;
}
else
{
if (item.Label != "..")
{
strThumb = item.Path + @"\folder.jpg";
if (System.IO.File.Exists(strThumb))
{
item.ThumbnailImage = strThumb;
item.IconImage = strThumb;
item.IconImageBig = strThumb;
}
else
{
strThumb = String.Format(@"{0}\{1}.jpg", Thumbs.Folders, MediaPortal.Util.Utils.EncryptLine(item.Path));
if (System.IO.File.Exists(strThumb))
{
item.ThumbnailImage = strThumb;
item.IconImage = strThumb;
item.IconImageBig = strThumb;
}
}
}
}
if (!string.IsNullOrEmpty(strThumb))
{
strThumb = Util.Utils.ConvertToLargeCoverArt(strThumb);
if (System.IO.File.Exists(strThumb))
item.ThumbnailImage = strThumb;
}
}
public static bool CreateFolderPreviewThumb(List<string> aPictureList, string aThumbPath)
{
bool result = false;
if (aPictureList.Count > 0)
{
try
{
string currentSkin = GUIGraphicsContext.Skin;
// when launched by configuration exe this might be the case
if (string.IsNullOrEmpty(currentSkin))
{
using (Profile.Settings xmlreader = new Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")))
{
currentSkin = Application.StartupPath + @"\skin\" + xmlreader.GetValueAsString("skin", "name", "BlueTwo");
}
}
string defaultBackground = currentSkin + @"\media\previewbackground.png";
if (File.Exists(defaultBackground))
{
using (Image imgFolder = Image.FromFile(defaultBackground))
{
int width = imgFolder.Width;
int height = imgFolder.Height;
int thumbnailWidth = 256;
int thumbnailHeight = 256;
// draw a fullsize thumb if only 1 pic is available
if (aPictureList.Count == 1)
{
thumbnailWidth = (width - 20);
thumbnailHeight = (height - 20);
}
else
{
thumbnailWidth = (width - 30) / 2;
thumbnailHeight = (height - 30) / 2;
}
using (Bitmap bmp = new Bitmap(width, height))
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.CompositingQuality = Thumbs.Compositing;
g.InterpolationMode = Thumbs.Interpolation;
g.SmoothingMode = Thumbs.Smoothing;
g.DrawImage(imgFolder, 0, 0, width, height);
int x, y, w, h;
x = 0;
y = 0;
w = thumbnailWidth;
h = thumbnailHeight;
//Load first of 4 images for the folder thumb.
try
{
AddPicture(g, (string)aPictureList[0], x + 10, y + 10, w, h);
System.Threading.Thread.Sleep(30);
//If exists load second of 4 images for the folder thumb.
if (aPictureList.Count > 1)
{
AddPicture(g, (string)aPictureList[1], x + thumbnailWidth + 20, y + 10, w, h);
System.Threading.Thread.Sleep(30);
}
//If exists load third of 4 images for the folder thumb.
if (aPictureList.Count > 2)
{
AddPicture(g, (string)aPictureList[2], x + 10, y + thumbnailHeight + 20, w, h);
System.Threading.Thread.Sleep(30);
}
//If exists load fourth of 4 images for the folder thumb.
if (aPictureList.Count > 3)
{
AddPicture(g, (string)aPictureList[3], x + thumbnailWidth + 20, y + thumbnailHeight + 20, w, h);
System.Threading.Thread.Sleep(30);
}
}
catch (Exception ex)
{
Log.Error("Utils: An exception occured creating folder preview thumb: {0}", ex.Message);
}
}//using (Graphics g = Graphics.FromImage(bmp) )
try
{
if (System.IO.File.Exists(aThumbPath))
FileDelete(aThumbPath);
string tmpFile = Path.Combine(Path.GetTempPath(), "folderpreview.jpg");
if (System.IO.File.Exists(tmpFile))
FileDelete(tmpFile);
bmp.Save(tmpFile, System.Drawing.Imaging.ImageFormat.Jpeg);
using (Image thumbImage = Image.FromFile(tmpFile))
{
string folderHash = MediaPortal.Util.Utils.EncryptLine(Path.GetDirectoryName(aThumbPath));
aThumbPath = String.Format(@"{0}\{1}.jpg", Thumbs.Folders, folderHash);
if (Picture.CreateThumbnail(thumbImage, aThumbPath, (int)Thumbs.ThumbResolution, (int)Thumbs.ThumbResolution, 0, true))
{
System.Threading.Thread.Sleep(30);
// we do not want a folderL.jpg
if (!aThumbPath.ToLowerInvariant().Contains(folderHash + ".jpg"))
{
aThumbPath = Util.Utils.ConvertToLargeCoverArt(aThumbPath);
Picture.CreateThumbnail(thumbImage, aThumbPath, (int)Thumbs.ThumbLargeResolution, (int)Thumbs.ThumbLargeResolution, 0, false);
}
}
System.Threading.Thread.Sleep(30);
if (System.IO.File.Exists(aThumbPath))
result = true;
// File.SetAttributes(thumbnailImageName, FileAttributes.Hidden);
}
}
catch (Exception ex2)
{
Log.Error("Utils: An exception occured saving folder preview thumb: {0} - {1}", aThumbPath, ex2.Message);
}
}//using (Bitmap bmp = new Bitmap(210,210))
}
}
else
Log.Warn("Utils: Your skin does not supply previewbackground.png to create folder preview thumbs!");
}
catch (Exception exm)
{
Log.Error("Utils: An error occured creating folder preview thumbs: {0}", exm.Message);
}
} //if (pictureList.Count>0)
else
result = false;
return result;
}
map hidden = yes
create mask = 745