From 4789e3a2548639317b85cb08366f4b4690d294ae Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Sun, 4 Apr 2021 15:51:43 +0200 Subject: [PATCH] Removed special character check, cleanup --- Code/IO/IOUtils.cs | 59 ++++++++++++----------------------- Code/Main/Interpolate.cs | 1 - Code/Main/InterpolateSteps.cs | 4 +-- Code/Main/InterpolateUtils.cs | 6 ---- Code/UI/MainUiFunctions.cs | 1 - 5 files changed, 22 insertions(+), 49 deletions(-) diff --git a/Code/IO/IOUtils.cs b/Code/IO/IOUtils.cs index 7d2f105..ec5291b 100644 --- a/Code/IO/IOUtils.cs +++ b/Code/IO/IOUtils.cs @@ -30,40 +30,35 @@ namespace Flowframes.IO public static string[] ReadLines(string path) { List lines = new List(); - using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 0x1000, FileOptions.SequentialScan)) - using (var sr = new StreamReader(fs, Encoding.UTF8)) + using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 0x1000, FileOptions.SequentialScan)) + + using (var reader = new StreamReader(stream, Encoding.UTF8)) { string line; - while ((line = sr.ReadLine()) != null) + while ((line = reader.ReadLine()) != null) lines.Add(line); } + return lines.ToArray(); } public static bool IsPathDirectory(string path) { if (path == null) - { throw new ArgumentNullException("path"); - } - path = path.Trim(); + + path = path.Trim(); + if (Directory.Exists(path)) - { return true; - } - if (File.Exists(path)) - { + + if (File.Exists(path)) return false; - } - if (new string[2] - { - "\\", - "/" - }.Any((string x) => path.EndsWith(x))) - { + + if (new string[2] {"\\", "/"}.Any((string x) => path.EndsWith(x))) return true; - } - return string.IsNullOrWhiteSpace(Path.GetExtension(path)); + + return string.IsNullOrWhiteSpace(Path.GetExtension(path)); } public static bool IsFileValid(string path) @@ -159,16 +154,7 @@ namespace Flowframes.IO File.Move(path, targetPath); } - public static int GetFilenameCounterLength(string file, string prefixToRemove = "") - { - string filenameNoExt = Path.GetFileNameWithoutExtension(file); - if (!string.IsNullOrEmpty(prefixToRemove)) - filenameNoExt = filenameNoExt.Replace(prefixToRemove, ""); - string onlyNumbersFilename = Regex.Replace(filenameNoExt, "[^.0-9]", ""); - return onlyNumbersFilename.Length; - } - - public static int GetAmountOfFiles (string path, bool recursive, string wildcard = "*") + public static int GetAmountOfFiles (string path, bool recursive, string wildcard = "*") { try { @@ -646,9 +632,7 @@ namespace Flowframes.IO try { Image img = GetImage(path); - if (img.Width > 1 && img.Height > 1) - return true; - return false; + return (img.Width > 0 && img.Height > 0); } catch { @@ -702,6 +686,7 @@ namespace Flowframes.IO // Add file sizes. string[] files; StringComparison ignCase = StringComparison.OrdinalIgnoreCase; + if (includedExtensions == null) files = Directory.GetFiles(path); else @@ -745,12 +730,7 @@ namespace Flowframes.IO } } - public static bool HasBadChars(string str) - { - return str != str.StripBadChars(); - } - - public static void OverwriteFileWithText (string path, string text = "THIS IS A DUMMY FILE - DO NOT DELETE ME") + public static void OverwriteFileWithText (string path, string text = "THIS IS A DUMMY FILE - DO NOT DELETE ME") { try { @@ -771,7 +751,7 @@ namespace Flowframes.IO foreach (DriveInfo d in allDrives) { - if (d.IsReady == true && d.Name.StartsWith(driveLetter)) + if (d.IsReady && d.Name.StartsWith(driveLetter)) { if (mbytes) return (long)(d.AvailableFreeSpace / 1024f / 1000f); @@ -784,6 +764,7 @@ namespace Flowframes.IO { Logger.Log("Error trying to get disk space: " + e.Message, true); } + return 0; } } diff --git a/Code/Main/Interpolate.cs b/Code/Main/Interpolate.cs index 1bc19b5..e88ddc4 100644 --- a/Code/Main/Interpolate.cs +++ b/Code/Main/Interpolate.cs @@ -39,7 +39,6 @@ namespace Flowframes if (!ResumeUtils.resumeNextRun && !Utils.CheckDeleteOldTempFolder()) return; // Try to delete temp folder if an old one exists if (!Utils.CheckPathValid(current.inPath)) return; // Check if input path/file is valid if (!(await Utils.CheckEncoderValid())) return; // Check NVENC compat - Utils.PathAsciiCheck(current.outPath, "output path"); currentInputFrameCount = await Utils.GetInputFrameCountAsync(current.inPath); current.stepByStep = false; Program.mainForm.SetStatus("Starting..."); diff --git a/Code/Main/InterpolateSteps.cs b/Code/Main/InterpolateSteps.cs index f90db74..acb0a64 100644 --- a/Code/Main/InterpolateSteps.cs +++ b/Code/Main/InterpolateSteps.cs @@ -69,7 +69,7 @@ namespace Flowframes.Main current.framesFolder = Path.Combine(current.tempFolder, Paths.framesDir); - if (!Directory.Exists(current.framesFolder) || IOUtils.GetAmountOfFiles(current.framesFolder, false, "*.png") < 2) + if (IOUtils.GetAmountOfFiles(current.framesFolder, false, "*.png") < 2) { InterpolateUtils.ShowMessage("There are no extracted frames that can be interpolated!\nDid you run the extraction step?", "Error"); return; @@ -99,7 +99,7 @@ namespace Flowframes.Main public static async Task CreateOutputVid() { - if (!Directory.Exists(current.interpFolder) || IOUtils.GetAmountOfFiles(current.interpFolder, false) < 2) + if (IOUtils.GetAmountOfFiles(current.interpFolder, false) < 2) { Cancel($"There are no interpolated frames to encode!\n\nDid you delete the folder?"); return; diff --git a/Code/Main/InterpolateUtils.cs b/Code/Main/InterpolateUtils.cs index 9de9563..42ff9e9 100644 --- a/Code/Main/InterpolateUtils.cs +++ b/Code/Main/InterpolateUtils.cs @@ -331,12 +331,6 @@ namespace Flowframes.Main return passes; } - public static void PathAsciiCheck(string path, string pathTitle) - { - if (IOUtils.HasBadChars(path) || OSUtils.HasNonAsciiChars(path)) - ShowMessage($"Warning: Your {pathTitle} includes special characters. This might cause problems. If you get an error, try removing those symbols."); - } - public static bool CheckAiAvailable(AI ai) { if (IOUtils.GetAmountOfFiles(Path.Combine(Paths.GetPkgPath(), ai.pkgDir), true) < 1) diff --git a/Code/UI/MainUiFunctions.cs b/Code/UI/MainUiFunctions.cs index 947b385..1ab095c 100644 --- a/Code/UI/MainUiFunctions.cs +++ b/Code/UI/MainUiFunctions.cs @@ -22,7 +22,6 @@ namespace Flowframes.UI Program.mainForm.SetTab("interpolate"); Program.mainForm.ResetInputInfo(); string path = inputTbox.Text.Trim(); - InterpolateUtils.PathAsciiCheck(path, "input path"); if (Config.GetBool("clearLogOnInput")) Logger.ClearLogBox();