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:
parent
31c0196bb4
commit
282bdfa5cc
@ -774,22 +774,39 @@ 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);
|
wxLogMessage(wxT("PATH = '%s'"), syspath);
|
||||||
|
|
||||||
const wxString &fmtdir{ wxPathOnly(libpath_format) };
|
const wxString &fmtdir{ wxPathOnly(libpath_format) };
|
||||||
wxString fmtdirsc = fmtdir + wxT(";");
|
wxString fmtdirsc = fmtdir + wxT(";");
|
||||||
wxString scfmtdir = wxT(";") + fmtdir;
|
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(';'))
|
if (syspath.Left(1) == wxT(';'))
|
||||||
{
|
{
|
||||||
wxLogMessage(wxT("Temporarily prepending '%s' to PATH..."), fmtdir);
|
wxLogMessage(wxT("Temporarily prepending '%s' to PATH..."), fmtdir);
|
||||||
@ -801,20 +818,9 @@ bool FFmpegLibs::InitLibs(const wxString &libpath_format, bool WXUNUSED(showerr)
|
|||||||
syspath.Prepend(fmtdirsc);
|
syspath.Prepend(fmtdirsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wxSetEnv(wxT("PATH"),syspath))
|
if (!wxSetEnv(wxT("PATH"),syspath))
|
||||||
// Remember to change PATH back to normal after we're done
|
|
||||||
pathfix = true;
|
|
||||||
else
|
|
||||||
wxLogSysError(wxT("Setting PATH via wxSetEnv('%s') failed."),syspath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
wxLogMessage(wxT("FFmpeg directory is in PATH."));
|
wxLogSysError(wxT("Setting PATH via wxSetEnv('%s') failed."), syspath);
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxLogSysError(wxT("PATH does not exist."));
|
|
||||||
}
|
}
|
||||||
#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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user