From bd3497f23a4f8c7fc2c9675cee6b06055abf2794 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Fri, 13 Sep 2024 07:15:13 +0200 Subject: [PATCH] Fix possible crash in "Gen transparent subs" when using video from "Program files" --- src/ui/Forms/GenerateTransparentVideoWithSubtitles.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ui/Forms/GenerateTransparentVideoWithSubtitles.cs b/src/ui/Forms/GenerateTransparentVideoWithSubtitles.cs index 2e0243daa..acaeedb43 100644 --- a/src/ui/Forms/GenerateTransparentVideoWithSubtitles.cs +++ b/src/ui/Forms/GenerateTransparentVideoWithSubtitles.cs @@ -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);