Skip to content

Commit 73fc79d

Browse files
committed
Fix detection on LGPLv2.1 compliance FFmpeg builds
1 parent ecc5919 commit 73fc79d

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

CollapseLauncher/Classes/GameManagement/ImageBackground/ImageBackgroundManager.FFmpeg.cs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,18 @@ public bool TryRelinkFFmpegPath()
9898
return false;
9999
}
100100

101-
// -- If custom FFmpeg path is set but FFmpeg is not available,
102-
// Try to resolve the symbolic link path again.
103-
// -- Check for custom FFmpeg path availability first. If not available, skip.
104-
result = (IsFFmpegAvailable(customFFmpegDirPath, out exception) &&
105-
// -- Re-link FFmpeg symbolic link
106-
TryLinkFFmpegLibrary(customFFmpegDirPath, curDir, out exception)) ||
107-
// -- If custom FFmpeg path is not avail, then try to find one from EnvVar (this might be a bit expensive).
108-
// If found, the GlobalCustomFFmpegPath will be updated to the found path.
109-
(TryFindFFmpegInstallFromEnvVar(out string? envVarPath, out exception) && TryLinkFFmpegLibrary(envVarPath, curDir, out exception));
110-
111-
return result;
101+
// -- 1. Check from custom path first. If it exists, then pass.
102+
if (!string.IsNullOrEmpty(customFFmpegDirPath) &&
103+
IsFFmpegAvailable(customFFmpegDirPath, out exception) &&
104+
TryLinkFFmpegLibrary(customFFmpegDirPath, curDir, out exception))
105+
{
106+
return result = true;
107+
}
108+
109+
// -- 2. Find one from environment variables. If it exists, then pass.
110+
// Otherwise, return false.
111+
return result = TryFindFFmpegInstallFromEnvVar(out string? envVarPath, out exception) &&
112+
TryLinkFFmpegLibrary(envVarPath, curDir, out exception);
112113
}
113114
finally
114115
{
@@ -180,7 +181,6 @@ internal static bool IsFFmpegAvailable(string? checkOnDirectory,
180181
string dllPathAvfilter = Path.Combine(checkOnDirectory, Fields.DllNameAvfilter);
181182
string dllPathAvformat = Path.Combine(checkOnDirectory, Fields.DllNameAvformat);
182183
string dllPathAvutil = Path.Combine(checkOnDirectory, Fields.DllNameAvutil);
183-
string dllPathPostproc = Path.Combine(checkOnDirectory, Fields.DllNamePostproc);
184184
string dllPathSwresample = Path.Combine(checkOnDirectory, Fields.DllNameSwresample);
185185
string dllPathSwscale = Path.Combine(checkOnDirectory, Fields.DllNameSwscale);
186186

@@ -189,7 +189,6 @@ internal static bool IsFFmpegAvailable(string? checkOnDirectory,
189189
FileUtility.IsFileExistOrSymbolicLinkResolved(dllPathAvfilter, out _, out exception) &&
190190
FileUtility.IsFileExistOrSymbolicLinkResolved(dllPathAvformat, out _, out exception) &&
191191
FileUtility.IsFileExistOrSymbolicLinkResolved(dllPathAvutil, out _, out exception) &&
192-
FileUtility.IsFileExistOrSymbolicLinkResolved(dllPathPostproc, out _, out exception) &&
193192
FileUtility.IsFileExistOrSymbolicLinkResolved(dllPathSwresample, out _, out exception) &&
194193
FileUtility.IsFileExistOrSymbolicLinkResolved(dllPathSwscale, out _, out exception);
195194
}
@@ -201,7 +200,6 @@ internal static string[] GetFFmpegRequiredDllFilenames() =>
201200
Fields.DllNameAvfilter,
202201
Fields.DllNameAvformat,
203202
Fields.DllNameAvutil,
204-
Fields.DllNamePostproc,
205203
Fields.DllNameSwresample,
206204
Fields.DllNameSwscale
207205
];
@@ -262,14 +260,24 @@ public static bool TryLinkFFmpegLibrary(
262260
string dllPathSwresample = Path.Combine(sourceDir, Fields.DllNameSwresample);
263261
string dllPathSwscale = Path.Combine(sourceDir, Fields.DllNameSwscale);
264262

265-
return CreateSymbolLink(dllPathAvcodec, targetDir, out exception) &&
266-
CreateSymbolLink(dllPathAvdevice, targetDir, out exception) &&
267-
CreateSymbolLink(dllPathAvfilter, targetDir, out exception) &&
268-
CreateSymbolLink(dllPathAvformat, targetDir, out exception) &&
269-
CreateSymbolLink(dllPathAvutil, targetDir, out exception) &&
270-
CreateSymbolLink(dllPathPostproc, targetDir, out exception) &&
271-
CreateSymbolLink(dllPathSwresample, targetDir, out exception) &&
272-
CreateSymbolLink(dllPathSwscale, targetDir, out exception);
263+
bool result =
264+
CreateSymbolLink(dllPathAvcodec, targetDir, out exception) &&
265+
CreateSymbolLink(dllPathAvdevice, targetDir, out exception) &&
266+
CreateSymbolLink(dllPathAvfilter, targetDir, out exception) &&
267+
CreateSymbolLink(dllPathAvformat, targetDir, out exception) &&
268+
CreateSymbolLink(dllPathAvutil, targetDir, out exception) &&
269+
CreateSymbolLink(dllPathSwresample, targetDir, out exception) &&
270+
CreateSymbolLink(dllPathSwscale, targetDir, out exception);
271+
272+
// Additionally, link postproc if it exists.
273+
// Since some non-free/GPL custom build (if used by the user) still requires postproc library to exist if enabled on build.
274+
// Without it, some build might fail to run.
275+
if (result && FileUtility.IsFileExistOrSymbolicLinkResolved(dllPathPostproc, out string? resolvedOptDllPostproc, out exception))
276+
{
277+
return result && CreateSymbolLink(resolvedOptDllPostproc, targetDir, out exception);
278+
}
279+
280+
return result;
273281

274282
static bool CreateSymbolLink(string filePath,
275283
string targetDirectory,

0 commit comments

Comments
 (0)