AniDBmini.AniDBAPI.ed2kHash C# (CSharp) Метод

ed2kHash() публичный Метод

public ed2kHash ( HashItem item ) : HashItem
item HashItem
Результат HashItem
        public HashItem ed2kHash(HashItem item)
        {
            hasher.Clear();
            FileInfo file = new FileInfo(item.Path);

            using (FileStream fs = file.OpenRead())
            {
                AppendDebugLine("Hashing " + item.Name);
                byte[] temp;

                if ((temp = hasher.ComputeHash(fs)) != null)
                {
                    item.Hash = string.Concat(temp.Select(b => b.ToString("x2")).ToArray());
                    AppendDebugLine("Ed2k hash: " + item.Hash);

                    return item;
                }
                else
                    AppendDebugLine("Hashing aborted");

                return null;
            }
        }

Usage Example

Пример #1
0
        private void OnHashWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            while (hashFileList.Count > 0 && isHashing)
            {
                if (m_HashWorker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                HashItem thisItem = hashFileList[0],
                         _temp    = m_aniDBAPI.ed2kHash(thisItem);

                if (isHashing && _temp != null) // if we did not abort remove item from queue and process
                {
                    Dispatcher.BeginInvoke(new Action <HashItem>(FinishHash), _temp);
                    removeRowFromHashTable(hashFileList[hashFileList.IndexOf(thisItem)]);
                }
            }
        }