当前位置: 首页>>代码示例>>C#>>正文


C# MD5CryptoServiceProvider.ComputeFileHash方法代码示例

本文整理汇总了C#中System.Security.Cryptography.MD5CryptoServiceProvider.ComputeFileHash方法的典型用法代码示例。如果您正苦于以下问题:C# MD5CryptoServiceProvider.ComputeFileHash方法的具体用法?C# MD5CryptoServiceProvider.ComputeFileHash怎么用?C# MD5CryptoServiceProvider.ComputeFileHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.MD5CryptoServiceProvider的用法示例。


在下文中一共展示了MD5CryptoServiceProvider.ComputeFileHash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetEmoticons

        /// <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;
        }
开发者ID:mcastagnasso,项目名称:rugicon,代码行数:49,代码来源:LiveMessenger.cs

示例2: GetEmoticonSets

        /// <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;
        }
开发者ID:mcastagnasso,项目名称:rugicon,代码行数:65,代码来源:FileEmoticonService.cs


注:本文中的System.Security.Cryptography.MD5CryptoServiceProvider.ComputeFileHash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。