Beispiel #1
0
        private async Task FillMissingHashes(SVR_VideoLocal vlocal, CancellationToken token, IProgress <ICommand> progress = null)
        {
            HashTypes types = 0;

            if (string.IsNullOrEmpty(vlocal.CRC32))
            {
                types |= HashTypes.CRC;
            }
            if (string.IsNullOrEmpty(vlocal.MD5))
            {
                types |= HashTypes.MD5;
            }
            if (string.IsNullOrEmpty(vlocal.SHA1))
            {
                types |= HashTypes.SHA1;
            }
            if (types > 0)
            {
                FillVideoHashes(vlocal);
            }
            types = 0;
            if (string.IsNullOrEmpty(vlocal.CRC32))
            {
                types |= HashTypes.CRC;
            }
            if (string.IsNullOrEmpty(vlocal.MD5))
            {
                types |= HashTypes.MD5;
            }
            if (string.IsNullOrEmpty(vlocal.SHA1))
            {
                types |= HashTypes.SHA1;
            }
            if (types > 0)
            {
                _hashingState = true;
                DateTime start = DateTime.Now;
                logger.Trace("Calculating missing {1} hashes for: {0}", File.FullName, types.ToString("F"));
                // update the VideoLocal record with the Hash, since cloud support we calculate everything
                Hasher h     = new Hasher(File, HashAll);
                string error = await h.RunAsync(new ChildProgress(20, 60, this, progress), token);

                TimeSpan ts = DateTime.Now - start;
                logger.Trace("Hashed file in {0:#0.0} seconds --- {1} ({2})", ts.TotalSeconds, File.FullName, Utils.FormatByteSize(vlocal.FileSize));
                if (error != null)
                {
                    logger.Error("Unable to add additional hashes missing {1} hashes for: {0} Error {2}", File.FullName, types.ToString("F"), error);
                }
                else
                {
                    if ((types & HashTypes.CRC) > 0)
                    {
                        vlocal.CRC32 = h.Result.GetHash(HashTypes.CRC);
                    }
                    if ((types & HashTypes.MD5) > 0)
                    {
                        vlocal.MD5 = h.Result.GetHash(HashTypes.MD5);
                    }
                    if ((types & HashTypes.SHA1) > 0)
                    {
                        vlocal.SHA1 = h.Result.GetHash(HashTypes.SHA1);
                    }
                    WebCacheAPI.Instance.AddHash(new List <WebCache_FileHash> {
                        vlocal.ToHashRequest()
                    });
                }
            }
        }