コード例 #1
0
        /// <summary>
        /// Returns the available emoticon sets from Live Messenger.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<EmoticonSet> GetEmoticonSets()
        {
            // This service has only one set of emoticons,
            // the Live Messenger custom emoticons.
            // This set includes all emoticons of all users.
            var set = new EmoticonSet() { Name = "Live Messenger custom emoticons" };

            // Map from LiveEmoticon to Emoticon.
            // There is no real need to let LiveEmoticon class live, by the way.
            foreach (var emoticon in LiveMessenger.GetEmoticons())
            {
                set.Emoticons.Add(new Emoticon
                {
                    Filename = emoticon.Filename,
                    Hash = emoticon.Hash
                });
            }

            // Return the only set available.
            return new List<EmoticonSet> { set };
        }
コード例 #2
0
        /// <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;
        }