1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-04 14:19:30 +02:00

Bug 866 - FFmpeg: Audacity rejects FFmpeg in PATH/doesn't search PATH if invalid libs are in FFmpeg path

This commit is contained in:
Leland Lucius 2021-02-02 00:37:52 -06:00
parent 31c0196bb4
commit 282bdfa5cc

View File

@ -774,47 +774,53 @@ bool FFmpegLibs::InitLibs(const wxString &libpath_format, bool WXUNUSED(showerr)
FreeLibs(); FreeLibs();
#if defined(__WXMSW__) #if defined(__WXMSW__)
wxString oldpath;
wxString syspath; wxString syspath;
bool pathfix = false; bool pathExisted = false;
// Return PATH to normal
auto restorePath = finally([&]()
{
if (oldpath != syspath)
{
if (pathExisted)
{
wxLogMessage(wxT("Returning PATH to previous setting: %s"), oldpath);
wxSetEnv(wxT("PATH"), oldpath);
}
else
{
wxLogMessage(wxT("Removing PATH environment variable"));
wxUnsetEnv(wxT("PATH"));
}
}
});
wxLogMessage(wxT("Looking up PATH environment variable...")); wxLogMessage(wxT("Looking up PATH environment variable..."));
// First take PATH environment variable and store its content. // First take PATH environment variable and store its content.
if (wxGetEnv(wxT("PATH"),&syspath)) pathExisted = wxGetEnv(wxT("PATH"),&syspath);
{ oldpath = syspath;
wxLogMessage(wxT("PATH = '%s'"), syspath);
const wxString &fmtdir{ wxPathOnly(libpath_format) };
wxString fmtdirsc = fmtdir + wxT(";");
wxString scfmtdir = wxT(";") + fmtdir;
wxLogMessage(wxT("Checking that '%s' is in PATH..."), fmtdir);
// If the directory, where libavformat is, is not in PATH - add it
if (!syspath.Contains(fmtdirsc) && !syspath.Contains(scfmtdir) && !syspath.Contains(fmtdir))
{
wxLogWarning(wxT("FFmpeg directory '%s' is not in PATH."), fmtdir);
if (syspath.Left(1) == wxT(';'))
{
wxLogMessage(wxT("Temporarily prepending '%s' to PATH..."), fmtdir);
syspath.Prepend(scfmtdir);
}
else
{
wxLogMessage(wxT("Temporarily prepending '%s' to PATH..."), scfmtdir);
syspath.Prepend(fmtdirsc);
}
if (wxSetEnv(wxT("PATH"),syspath)) wxLogMessage(wxT("PATH = '%s'"), syspath);
// Remember to change PATH back to normal after we're done
pathfix = true; const wxString &fmtdir{ wxPathOnly(libpath_format) };
else wxString fmtdirsc = fmtdir + wxT(";");
wxLogSysError(wxT("Setting PATH via wxSetEnv('%s') failed."),syspath); wxString scfmtdir = wxT(";") + fmtdir;
}
else if (syspath.Left(1) == wxT(';'))
{ {
wxLogMessage(wxT("FFmpeg directory is in PATH.")); wxLogMessage(wxT("Temporarily prepending '%s' to PATH..."), fmtdir);
} syspath.Prepend(scfmtdir);
} }
else else
{ {
wxLogSysError(wxT("PATH does not exist.")); wxLogMessage(wxT("Temporarily prepending '%s' to PATH..."), scfmtdir);
syspath.Prepend(fmtdirsc);
}
if (!wxSetEnv(wxT("PATH"),syspath))
{
wxLogSysError(wxT("Setting PATH via wxSetEnv('%s') failed."), syspath);
} }
#endif #endif
@ -884,16 +890,6 @@ bool FFmpegLibs::InitLibs(const wxString &libpath_format, bool WXUNUSED(showerr)
gotError = !avformat->Load(nameFull, wxDL_LAZY); gotError = !avformat->Load(nameFull, wxDL_LAZY);
} }
#if defined(__WXMSW__)
//Return PATH to normal
if ( pathfix )
{
wxString oldpath = syspath.BeforeLast(wxT(';'));
wxLogMessage(wxT("Returning PATH to previous setting..."));
wxSetEnv(wxT("PATH"),oldpath);
}
#endif
if (gotError) { if (gotError) {
wxLogError(wxT("Failed to load FFmpeg libraries.")); wxLogError(wxT("Failed to load FFmpeg libraries."));
FreeLibs(); FreeLibs();