Fix possible crash in "Gen transparent subs" when using video from "Program files"

This commit is contained in:
Nikolaj Olsson 2024-09-13 07:15:13 +02:00
parent 4237f39a9f
commit bd3497f23a

View File

@ -1246,7 +1246,16 @@ namespace Nikse.SubtitleEdit.Forms
}
}
FileUtil.WriteAllText(assaTempFileName, format.ToText(subtitle, null), new TextEncoding(Encoding.UTF8, "UTF8"));
try
{
FileUtil.WriteAllText(assaTempFileName, format.ToText(subtitle, null), new TextEncoding(Encoding.UTF8, "UTF8"));
}
catch
{
// might be a write protected folder, so we try the temp folder
assaTempFileName = Path.Combine(Path.GetTempPath(), Path.GetFileName(assaTempFileName));
FileUtil.WriteAllText(assaTempFileName, format.ToText(subtitle, null), new TextEncoding(Encoding.UTF8, "UTF8"));
}
var videoFileName = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.mp4");
var result = RunOnePassEncoding(assaTempFileName, subtitle, videoFileName);