Improve error message if no write access to video source folder

Related to #7696
This commit is contained in:
Nikolaj Olsson 2023-12-02 18:23:07 +01:00
parent be8cb936b3
commit 88965b913e
2 changed files with 47 additions and 6 deletions

View File

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

View File

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