diff --git a/src/ui/Forms/AudioToText/VoskAudioToText.cs b/src/ui/Forms/AudioToText/VoskAudioToText.cs index 1cbc1dec6..a62cc870b 100644 --- a/src/ui/Forms/AudioToText/VoskAudioToText.cs +++ b/src/ui/Forms/AudioToText/VoskAudioToText.cs @@ -258,9 +258,22 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText fileName = $"{Path.Combine(Utilities.GetPathAndFileNameWithoutExtension(videoFileName))}.{Guid.NewGuid().ToString()}.{format.Extension}"; } - File.WriteAllText(fileName, text, Encoding.UTF8); - textBoxLog.AppendText("Subtitle written to : " + fileName + Environment.NewLine); - _outputBatchFileNames.Add(fileName); + try + { + File.WriteAllText(fileName, text, Encoding.UTF8); + textBoxLog.AppendText("Subtitle written to : " + fileName + Environment.NewLine); + _outputBatchFileNames.Add(fileName); + } + catch + { + var dir = Path.GetDirectoryName(fileName); + if (!WhisperAudioToText.IsDirectoryWritable(dir)) + { + MessageBox.Show($"SE does not have write access to the folder '{dir}'", MessageBoxIcon.Error); + } + + throw; + } } internal static string GetLanguage(string text) diff --git a/src/ui/Forms/AudioToText/WhisperAudioToText.cs b/src/ui/Forms/AudioToText/WhisperAudioToText.cs index be71777c4..2ff397a10 100644 --- a/src/ui/Forms/AudioToText/WhisperAudioToText.cs +++ b/src/ui/Forms/AudioToText/WhisperAudioToText.cs @@ -677,9 +677,37 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText fileName = $"{Path.Combine(Utilities.GetPathAndFileNameWithoutExtension(videoFileName))}.{Guid.NewGuid().ToString()}.{format.Extension}"; } - File.WriteAllText(fileName, text, Encoding.UTF8); - _outputText.Add("Subtitle written to : " + fileName); - _outputBatchFileNames.Add(fileName); + try + { + File.WriteAllText(fileName, text, Encoding.UTF8); + _outputText.Add("Subtitle written to : " + fileName); + _outputBatchFileNames.Add(fileName); + } + catch + { + var dir = Path.GetDirectoryName(fileName); + if (!IsDirectoryWritable(dir)) + { + MessageBox.Show($"SE does not have write access to the folder '{dir}'", MessageBoxIcon.Error); + } + + throw; + } + } + + public static bool IsDirectoryWritable(string dirPath) + { + try + { + using (FileStream fs = File.Create(Path.Combine(dirPath, Path.GetRandomFileName()), 1, FileOptions.DeleteOnClose)) + { + } + return true; + } + catch + { + return false; + } } internal static string GetLanguage(string name)