diff --git a/CodeLegacy/Cli.cs b/CodeLegacy/Cli.cs index d13b6475..c314aab2 100644 --- a/CodeLegacy/Cli.cs +++ b/CodeLegacy/Cli.cs @@ -18,8 +18,7 @@ public class Cli public static bool DisablePython = false; public static bool ShowMdlDownloader = false; public static bool DontSaveConfig = false; - public static bool ExitWhenDone = false; - public static bool InterpStart = false; + public static bool AutoRun = false; public static float InterpFactor = -1f; public static Implementations.Ai InterpAi = (Implementations.Ai)(-1); public static Enums.Output.Format OutputFormat = Enums.Output.Format.Mp4; @@ -60,19 +59,15 @@ public static void HandleCli() v => DontSaveConfig = v != null }, { - "e|exit", "Exit automatically after interpolation has finished", - v => ExitWhenDone = v != null - }, - { - "s|start", "Start interpolation automatically if valid parameters are provided", - v => InterpStart = v != null + "a|autorun", "Start interpolation automatically if valid parameters are provided and exit afterwards", + v => AutoRun = v != null }, { "f|factor=", "Interpolation factor", v => InterpFactor = v.GetFloat() }, { - "a|ai=", $"Interpolation AI implementation to use (Option: {GetEnums()})", + "ai=", $"Interpolation AI implementation to use (Option: {GetEnums()})", v => InterpAi = ParseUtils.GetEnum(v.Trim().Replace("_", "")) }, { diff --git a/CodeLegacy/Forms/Main/Form1.cs b/CodeLegacy/Forms/Main/Form1.cs index e21bfcd0..dcdf4ef2 100644 --- a/CodeLegacy/Forms/Main/Form1.cs +++ b/CodeLegacy/Forms/Main/Form1.cs @@ -373,7 +373,7 @@ public void InterpolationDone() public void CompletionAction() { - if (Cli.ExitWhenDone) + if (Cli.AutoRun) Application.Exit(); if (completionAction.SelectedIndex == 1) @@ -645,7 +645,7 @@ public void DragDropHandler(string[] files) { if (Program.busy) return; - bool start = Program.initialRun && Cli.InterpStart; + bool start = Program.initialRun && Cli.AutoRun; if (files.Length > 1) { diff --git a/CodeLegacy/IO/IoUtils.cs b/CodeLegacy/IO/IoUtils.cs index 518a0603..2613b113 100644 --- a/CodeLegacy/IO/IoUtils.cs +++ b/CodeLegacy/IO/IoUtils.cs @@ -368,47 +368,40 @@ public static Fraction GetVideoFramerateForDir(string path) public static async Task GetVideoOrFramesRes(string path) { - Size res = new Size(); - try { if (!IsPathDirectory(path)) // If path is video { - res = GetVideoRes(path); + return GetVideoRes(path); } else // Path is frame folder { Image thumb = await MainUiFunctions.GetThumbnail(path); - res = new Size(thumb.Width, thumb.Height); + return new Size(thumb.Width, thumb.Height); } } catch (Exception e) { - Logger.Log("GetVideoOrFramesRes Error: " + e.Message); + Logger.Log($"GetVideoOrFramesRes Error: {e.Message}"); + return new Size(); } - - return res; } public static Size GetVideoRes(string path) { - Size size = new Size(0, 0); - try { if (path.IsConcatFile()) path = ReadFileFirstLine(path).Split('\'')[1].Split('\'')[0]; - size = FfmpegCommands.GetSize(path); - Logger.Log($"Detected video size of {Path.GetFileName(path)} as {size.Width}x{size.Height}", true); + return FfmpegCommands.GetSize(path); } catch (Exception ex) { Logger.Log("Failed to read video size!"); Logger.Log(ex.ToString(), true); + return new Size(); } - - return size; } /// diff --git a/CodeLegacy/Media/GetMediaResolutionCached.cs b/CodeLegacy/Media/GetMediaResolutionCached.cs index 16e72f92..98128346 100644 --- a/CodeLegacy/Media/GetMediaResolutionCached.cs +++ b/CodeLegacy/Media/GetMediaResolutionCached.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; using System.Drawing; +using System.IO; +using System.Linq; using System.Threading.Tasks; using Flowframes.Data; using Flowframes.IO; @@ -12,19 +14,14 @@ class GetMediaResolutionCached public static async Task GetSizeAsync(string path) { - Logger.Log($"Getting media resolution ({path})", true); - long filesize = IoUtils.GetPathSize(path); QueryInfo hash = new QueryInfo(path, filesize); if (filesize > 0 && CacheContains(hash)) { - Logger.Log($"Cache contains this hash, using cached value.", true); - return GetFromCache(hash); - } - else - { - Logger.Log($"Hash not cached, reading resolution.", true); + Size cachedVal = GetFromCache(hash); + Logger.Log($"Resolution of '{Path.GetFileName(path)}': {cachedVal.Width}x{cachedVal.Height} [Cached]", true); + return cachedVal; } Size size; @@ -32,29 +29,21 @@ public static async Task GetSizeAsync(string path) if(size.Width > 0 && size.Height > 0) { - Logger.Log($"Adding hash with value {size} to cache.", true); cache.Add(hash, size); } + Logger.Log($"Resolution of '{Path.GetFileName(path)}': {size.Width}x{size.Height}", true); return size; } private static bool CacheContains(QueryInfo hash) { - foreach (KeyValuePair entry in cache) - if (entry.Key.path == hash.path && entry.Key.filesize == hash.filesize) - return true; - - return false; + return cache.Any(entry => entry.Key.path == hash.path && entry.Key.filesize == hash.filesize); } private static Size GetFromCache(QueryInfo hash) { - foreach (KeyValuePair entry in cache) - if (entry.Key.path == hash.path && entry.Key.filesize == hash.filesize) - return entry.Value; - - return new Size(); + return cache.Where(entry => entry.Key.path == hash.path && entry.Key.filesize == hash.filesize).Select(entry => entry.Value).FirstOrDefault(); } public static void Clear() diff --git a/CodeLegacy/Program.cs b/CodeLegacy/Program.cs index 6f603969..7087e2fc 100644 --- a/CodeLegacy/Program.cs +++ b/CodeLegacy/Program.cs @@ -66,7 +66,7 @@ private static void LaunchGui() bool showMdlDownloader = Cli.ShowMdlDownloader || args.Contains("show-model-downloader"); // The latter check may be needed for legacy reasons - mainForm = new Form1() { ShowModelDownloader = showMdlDownloader, Enabled = false }; + mainForm = new Form1() { ShowModelDownloader = showMdlDownloader, Enabled = !Cli.AutoRun }; Application.Run(mainForm); }