DataHash DigestFile(MD5 provider, string filepath, Regex findDateTime)
{
var rv = new DataHash()
{
Result = DataHashResult.FileNotFound,
InputName = filepath,
};
if (!FileUtils.Exists(filepath))
{
return(rv);
}
provider.Initialize();
var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
using (var bs = new BufferedStream(fs))
{
Logging.Emit("digest {0}", filepath);
rv.Hash = new SoapHexBinary(provider.ComputeHash(bs)).ToString();
rv.Result = DataHashResult.Ok;
if (findDateTime != null)
{
// check include cache for this file
if (includeCache.ContainsEntry(rv.Hash, F_NotDateTime))
{
return(rv);
}
if (includeCache.ContainsEntry(rv.Hash, F_HasDateTime))
{
rv.Result = DataHashResult.ContainsTimeOrDate;
return(rv);
}
bs.Seek(0, SeekOrigin.Begin);
using (var ts = new StreamReader(bs))
{
string line = null;
do
{
line = ts.ReadLine();
if (line == null)
{
includeCache.WaitOne();
try
{
includeCache.AddTextFileContent(rv.Hash, F_NotDateTime, "");
}
finally
{
includeCache.ReleaseMutex();
}
break;
}
if (findDateTime.IsMatch(line))
{
rv.Result = DataHashResult.ContainsTimeOrDate;
includeCache.WaitOne();
try
{
includeCache.AddTextFileContent(rv.Hash, F_HasDateTime, "");
}
finally
{
includeCache.ReleaseMutex();
}
break;
}
} while (true);
}
}
}
rv.Result = DataHashResult.Ok;
return(rv);
}