/// <summary> /// Gets all custom emoticons in all Live accounts in the current PC. /// </summary> /// <returns></returns> public static IEnumerable<LiveEmoticon> GetEmoticons() { List<LiveEmoticon> emoticons = new List<LiveEmoticon>(); // If the Live Messenger directory doesn't exists (i.e. is not installed), // don't fail but return none. if (!Directory.Exists(RootFolderPath)) return emoticons; // Each Live Messenger account has a separate folder string[] accountFolders = Directory.GetDirectories(RootFolderPath, "*@*", SearchOption.TopDirectoryOnly); foreach (string accountFolder in accountFolders) { string emoticonsFolder = Path.Combine(accountFolder, @"ObjectStore\CustomEmoticons"); // The folder may not exists if no custom emoticons were added if (!Directory.Exists(emoticonsFolder)) continue; // Each .dt2 file is, actually, a png or gif image string[] rawEmoticonFiles = Directory.GetFiles(emoticonsFolder, "*.dt2", SearchOption.TopDirectoryOnly); foreach (string rawEmoticonFile in rawEmoticonFiles) { // Calculate the hash (md5) of the file to compare if an equal // emoticon was already added. This happens when the user have // multiple Live Messenger accounts. using (var md5 = new MD5CryptoServiceProvider()) { var hash = md5.ComputeFileHash(rawEmoticonFile); var query = (from e in emoticons where e.Hash.SequenceEqual(hash) select e).SingleOrDefault(); // If the hash isn't found, add the emoticon if (query == null) emoticons.Add(new LiveEmoticon { Filename = rawEmoticonFile, Hash = hash }); } } } return emoticons; }
/// <summary> /// Returns the available emoticon sets from the Rugicon data emoticons folder. /// </summary> /// <returns></returns> public IEnumerable<EmoticonSet> GetEmoticonSets() { // Make sure emoticons folder exists if(!Directory.Exists(EmoticonsFolder)) Directory.CreateDirectory(EmoticonsFolder); // The set of emoticon set (result) var emoticonSets = new List<EmoticonSet>(); // Each subdirectory is a emoticon set, and the root // is the special set "Your own emoticons". var emoticonSetFolders = new List<string> { EmoticonsFolder }; emoticonSetFolders.AddRange(Directory.GetDirectories(EmoticonsFolder)); // Create and populate each set. foreach (string setFolder in emoticonSetFolders) { // Get the emoticon images. // Only PNG, GIF, BMP or JPG. var pngEmoticons = Directory.GetFiles(setFolder, "*.png", SearchOption.TopDirectoryOnly); var gifEmoticons = Directory.GetFiles(setFolder, "*.gif", SearchOption.TopDirectoryOnly); var bmpEmoticons = Directory.GetFiles(setFolder, "*.bmp", SearchOption.TopDirectoryOnly); var jpgEmoticons = Directory.GetFiles(setFolder, "*.jpg", SearchOption.TopDirectoryOnly); var emoticons = pngEmoticons.Union(gifEmoticons).Union(bmpEmoticons).Union(jpgEmoticons); // Check if there is any emoticon in this set if (emoticons.Count() < 1) continue; // Create the set var emoticonSet = new EmoticonSet(); // The name, by now, is the folder name. emoticonSet.Name = new DirectoryInfo(setFolder).Name; // I know this is so ugly... set the appropiate name // to the special set. Encapsulating the foreach block this // can be prettier. if (emoticonSetFolders.IndexOf(setFolder) == 0) emoticonSet.Name = "Your own emoticons"; // Add the set to the result emoticonSets.Add(emoticonSet); // Calculate the hash for each emoticon foreach (string rawEmoticonFile in emoticons) { using (var md5 = new MD5CryptoServiceProvider()) { var hash = md5.ComputeFileHash(rawEmoticonFile); emoticonSet.Emoticons.Add(new Emoticon { Filename = rawEmoticonFile, Hash = hash }); } } } return emoticonSets; }