From 3fbbc2d99b9b44d7a1ae71f0f0a7d7bc3731a6c4 Mon Sep 17 00:00:00 2001 From: niksedk Date: Mon, 24 Oct 2022 18:11:10 +0200 Subject: [PATCH] Try to fix Whisher check crash - thx Jyaelev :) Fix #6352 --- src/libse/AudioToText/WhisperHelper.cs | 102 ++++++++++++------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/libse/AudioToText/WhisperHelper.cs b/src/libse/AudioToText/WhisperHelper.cs index ce1e581ce..7065f651f 100644 --- a/src/libse/AudioToText/WhisperHelper.cs +++ b/src/libse/AudioToText/WhisperHelper.cs @@ -23,72 +23,72 @@ namespace Nikse.SubtitleEdit.Core.AudioToText return null; } - var location = Configuration.Settings.Tools.WhisperLocation; - if (!string.IsNullOrEmpty(location)) + try { - if (location.EndsWith("whisper.exe", StringComparison.InvariantCultureIgnoreCase) && File.Exists(location)) + var location = Configuration.Settings.Tools.WhisperLocation; + if (!string.IsNullOrEmpty(location)) { - return Path.GetDirectoryName(location); - } - - if (Directory.Exists(location) && File.Exists(Path.Combine(location, "whisper.exe"))) - { - return location; - } - } - - var pythonFolder = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - "AppData", - "Local", - "Programs", - "Python"); - if (Directory.Exists(pythonFolder)) - { - foreach (var dir in Directory.GetDirectories(pythonFolder)) - { - var dirName = Path.GetFileName(dir); - if (dirName != null && dirName.StartsWith("Python3")) + if (location.EndsWith("whisper.exe", StringComparison.InvariantCultureIgnoreCase) && File.Exists(location)) { - var whisperFullPath = Path.Combine(dir, "Scripts", "whisper.exe"); - if (File.Exists(whisperFullPath)) + return Path.GetDirectoryName(location); + } + + if (Directory.Exists(location) && File.Exists(Path.Combine(location, "whisper.exe"))) + { + return location; + } + } + + var pythonFolder = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), + "AppData", + "Local", + "Programs", + "Python"); + if (Directory.Exists(pythonFolder)) + { + foreach (var dir in Directory.GetDirectories(pythonFolder)) + { + var dirName = Path.GetFileName(dir); + if (dirName != null && dirName.StartsWith("Python3")) { - return Path.Combine(dir, "Scripts"); + var whisperFullPath = Path.Combine(dir, "Scripts", "whisper.exe"); + if (File.Exists(whisperFullPath)) + { + return Path.Combine(dir, "Scripts"); + } } } } - } - var programFilesFolder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); - foreach (var dir in Directory.GetDirectories(programFilesFolder)) - { - var dirName = Path.GetFileName(dir); - if (dirName != null && dirName.StartsWith("Python")) + var programFilesFolder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); + foreach (var dir in Directory.GetDirectories(programFilesFolder)) { - var files = Directory.GetFiles(dir, "whisper.exe", SearchOption.AllDirectories); + var dirName = Path.GetFileName(dir); + if (dirName != null && dirName.StartsWith("Python")) + { + var files = Directory.GetFiles(dir, "whisper.exe", SearchOption.AllDirectories); + if (files.Length > 0) + { + return Path.GetDirectoryName(files[0]); + } + } + } + + var packagesFolder = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), + "AppData", + "Local", + "Packages"); + if (Directory.Exists(packagesFolder)) + { + var files = Directory.GetFiles(packagesFolder, "whisper.exe", SearchOption.AllDirectories); if (files.Length > 0) { return Path.GetDirectoryName(files[0]); } } - } - var packagesFolder = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - "AppData", - "Local", - "Packages"); - if (Directory.Exists(packagesFolder)) - { - var files = Directory.GetFiles(packagesFolder, "whisper.exe", SearchOption.AllDirectories); - if (files.Length > 0) - { - return Path.GetDirectoryName(files[0]); - } - } - - try - { pythonFolder = "C:\\"; foreach (var dir in Directory.GetDirectories(pythonFolder)) {