Try to fix Whisher check crash - thx Jyaelev :)

Fix #6352
This commit is contained in:
niksedk 2022-10-24 18:11:10 +02:00
parent 1f8749402a
commit 3fbbc2d99b

View File

@ -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))
{