本文整理匯總了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;
}
示例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;
}