Fixed GetHash file lock, AE safety buffers in config, increased to 90 for ncnn

This commit is contained in:
N00MKRAD
2021-01-17 20:05:39 +01:00
parent 9e52c25b2b
commit f13dffbeb8
5 changed files with 18 additions and 10 deletions

View File

@@ -558,23 +558,29 @@ namespace Flowframes.IO
}
try
{
var stream = File.OpenRead(path);
if (hashType == Hash.MD5)
{
MD5 md5 = MD5.Create();
var hash = md5.ComputeHash(File.OpenRead(path));
var hash = md5.ComputeHash(stream);
hashStr = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
if (hashType == Hash.CRC32)
{
var crc = new Crc32Algorithm();
var crc32bytes = crc.ComputeHash(File.OpenRead(path));
var crc32bytes = crc.ComputeHash(stream);
hashStr = BitConverter.ToUInt32(crc32bytes, 0).ToString();
}
if (hashType == Hash.xxHash)
{
ulong xxh64 = xxHash64.ComputeHash(File.OpenRead(path), 8192, (ulong)GetFilesize(path));
ulong xxh64 = xxHash64.ComputeHash(stream, 8192, (ulong)GetFilesize(path));
hashStr = xxh64.ToString();
}
stream.Close();
}
catch (Exception e)
{

View File

@@ -41,6 +41,7 @@ namespace Flowframes.IO
static async Task DownloadTo (string url, string saveDir, int retries = 3)
{
string savePath = Path.Combine(saveDir, Path.GetFileName(url));
IOUtils.TryDeleteIfExists(savePath);
Logger.Log($"Downloading '{url}' to '{savePath}'", true);
Stopwatch sw = new Stopwatch();
sw.Restart();
@@ -68,6 +69,7 @@ namespace Flowframes.IO
if (Interpolate.canceled)
{
client.CancelAsync();
client.Dispose();
return;
}
if (sw.ElapsedMilliseconds > 6000)
@@ -106,7 +108,7 @@ namespace Flowframes.IO
foreach (KeyValuePair<string, string> modelFile in fileList)
await DownloadTo(GetMdlFileUrl(ai, model, modelFile.Key), mdlDir);
Logger.Log($"Downloaded \"{model}\" model files.", false, true);
}
catch (Exception e)
@@ -174,7 +176,7 @@ namespace Flowframes.IO
string md5 = IOUtils.GetHash(Path.Combine(mdlDir, file.Key), IOUtils.Hash.MD5);
if (md5.Trim() != file.Value.Trim())
{
Logger.Log($"Files for model {model} not valid: Local MD5 ({md5.Trim()}) does not equal validation MD5 ({file.Value.Trim()}).", true);
Logger.Log($"Files for model {model} not valid: MD5 of {file.Key} ({md5.Trim()}) does not equal validation MD5 ({file.Value.Trim()}).", true);
return false;
}
}