From 2932e702e337e271fb42ba088e8ae161a07bd366 Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Thu, 4 Feb 2021 21:18:36 +0100 Subject: [PATCH] Don't hash framecount of >256mb files as it's too slow and I/O heavy --- Code/ExtensionMethods.cs | 2 +- Code/IO/IOUtils.cs | 20 +++++++++++++++++--- Code/Main/InterpolateUtils.cs | 10 +++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Code/ExtensionMethods.cs b/Code/ExtensionMethods.cs index 3a6e3f3..1a4c7ca 100644 --- a/Code/ExtensionMethods.cs +++ b/Code/ExtensionMethods.cs @@ -38,7 +38,7 @@ namespace Flowframes try { return int.Parse(str.TrimNumbers()); } catch (Exception e) { - Logger.Log("Failed to parse \"" + str + "\" to int: " + e, true); + Logger.Log("Failed to parse \"" + str + "\" to int: " + e.Message, true); return 0; } } diff --git a/Code/IO/IOUtils.cs b/Code/IO/IOUtils.cs index 6186746..c8d06cf 100644 --- a/Code/IO/IOUtils.cs +++ b/Code/IO/IOUtils.cs @@ -738,13 +738,27 @@ namespace Flowframes.IO public static long GetFilesize(string path) { - return new FileInfo(path).Length; + try + { + return new FileInfo(path).Length; + } + catch + { + return -1; + } } public static string GetFilesizeStr (string path) { - return FormatUtils.Bytes(GetFilesize(path)); - } + try + { + return FormatUtils.Bytes(GetFilesize(path)); + } + catch + { + return "?"; + } + } public static byte[] GetLastBytes (string path, int startAt, int bytesAmount) { diff --git a/Code/Main/InterpolateUtils.cs b/Code/Main/InterpolateUtils.cs index 062b38b..da538bd 100644 --- a/Code/Main/InterpolateUtils.cs +++ b/Code/Main/InterpolateUtils.cs @@ -155,7 +155,9 @@ namespace Flowframes.Main { if (img == null) return; + preview.Image = img; + if (bigPreviewForm != null) bigPreviewForm.SetImage(img); } @@ -163,7 +165,13 @@ namespace Flowframes.Main public static Dictionary frameCountCache = new Dictionary(); public static async Task GetInputFrameCountAsync (string path) { - string hash = await IOUtils.GetHashAsync(path, IOUtils.Hash.xxHash); // Get checksum for caching + int maxMb = Config.GetInt("storeHashedFramecountMaxSizeMb", 256); + string hash = ""; + + if (IOUtils.GetFilesize(path) >= 0 && IOUtils.GetFilesize(path) < maxMb * 1024 * 1024) + hash = await IOUtils.GetHashAsync(path, IOUtils.Hash.xxHash); // Get checksum for caching + else + Logger.Log($"GetInputFrameCountAsync: File bigger than {maxMb}mb, won't hash.", true); if (hash.Length > 1 && frameCountCache.ContainsKey(hash)) {