Ensure FFmpeg DL target is writable before downloading

This commit is contained in:
James Groom 2023-10-24 23:11:54 +10:00 committed by GitHub
parent 542a0e08be
commit 736abf32ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 6 deletions

View File

@ -40,6 +40,9 @@ namespace BizHawk.Client.EmuHawk
try
{
DirectoryInfo parentDir = new(Path.GetDirectoryName(FFmpegService.FFmpegPath)!);
if (!parentDir.Exists) parentDir.Create();
using var fs = File.Create(FFmpegService.FFmpegPath); // check writable before bothering with the download
using (var evt = new ManualResetEvent(false))
{
using (var client = new System.Net.WebClient())
@ -83,15 +86,11 @@ namespace BizHawk.Client.EmuHawk
{
using (var exe = OSTailoredCode.IsUnixHost ? hf.BindArchiveMember("ffmpeg") : hf.BindFirstOf(".exe"))
{
var data = exe!.ReadAllBytes();
//last chance. exiting, don't dump the new ffmpeg file
if (exiting)
return;
DirectoryInfo parentDir = new(Path.GetDirectoryName(FFmpegService.FFmpegPath)!);
if (!parentDir.Exists) parentDir.Create();
File.WriteAllBytes(FFmpegService.FFmpegPath, data);
exe!.GetStream().CopyTo(fs);
fs.Dispose();
if (OSTailoredCode.IsUnixHost)
{
OSTailoredCode.ConstructSubshell("chmod", $"+x {FFmpegService.FFmpegPath}", checkStdout: false).Start();