From 99d60a1b2ce724f6a5070dcd7b7bead5a6b16827 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Tue, 28 Nov 2023 18:15:54 -0500 Subject: [PATCH] Add process exit check to mitigate possible .NET bug --- TwitchDownloaderCore/ClipDownloader.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/TwitchDownloaderCore/ClipDownloader.cs b/TwitchDownloaderCore/ClipDownloader.cs index 975e820e..3198af7b 100644 --- a/TwitchDownloaderCore/ClipDownloader.cs +++ b/TwitchDownloaderCore/ClipDownloader.cs @@ -74,6 +74,12 @@ void DownloadProgressHandler(StreamCopyProgress streamProgress) var clipChapter = TwitchHelper.GenerateClipChapter(clipInfo.data.clip); await EncodeClipWithMetadata(tempFile, downloadOptions.Filename, clipInfo.data.clip, clipChapter, cancellationToken); + if (!File.Exists(downloadOptions.Filename)) + { + File.Move(tempFile, downloadOptions.Filename); + throw new FileNotFoundException("Unable to serialize metadata (is FFmpeg missing?). The download has been completed without custom metadata."); + } + _progress.Report(new ProgressReport(ReportType.SameLineStatus, "Encoding Clip Metadata 100%")); _progress.Report(new ProgressReport(100)); } @@ -163,6 +169,12 @@ await FfmpegMetadata.SerializeAsync(metadataFile, clipMetadata.broadcaster.displ }; process.Start(); + + // If the process has exited before we call WaitForExitAsync, the thread locks up. + // This was probably not intended by the .NET team, but it's an issue regardless. + if (process.HasExited) + return; + await process.WaitForExitAsync(cancellationToken); } finally