Cleanup library resolution logic

This commit is contained in:
Michael Pfaff 2022-11-10 20:41:03 -05:00
parent b78e44c3bd
commit b184525212
Signed by: michael
GPG Key ID: CF402C4A012AA9D4
1 changed files with 9 additions and 11 deletions

View File

@ -198,6 +198,15 @@ public class LWJGLUtil {
* @return Paths to located libraries, if any
*/
public static String[] getLibraryPaths(String libname, String[] platform_lib_names, ClassLoader classloader) {
String overridePath = getPrivilegedProperty("org.lwjgl.librarypath");
if (overridePath != null) {
String[] paths = new String[platform_lib_names.length];
for (int i = 0; i < paths.length; i++) {
paths[i] = overridePath + File.separator + platform_lib_names[i];
}
return paths;
}
// need to pass path of possible locations of library to native side
List<String> possible_paths = new ArrayList<String>();
@ -220,12 +229,6 @@ public class LWJGLUtil {
+ File.separator + platform_lib_name);
}
// add Installer path
String alternative_path = getPrivilegedProperty("org.lwjgl.librarypath");
if ( alternative_path != null ) {
possible_paths.add(alternative_path + File.separator + platform_lib_name);
}
// Add all possible paths from java.library.path
String java_library_path = getPrivilegedProperty("java.library.path");
@ -235,11 +238,6 @@ public class LWJGLUtil {
possible_paths.add(path + File.separator + platform_lib_name);
}
// TODO: this can be very dangerous (see recent (2022-08) use of completely safe notepad.exe to load a malicious dll)
//add current path
String current_dir = getPrivilegedProperty("user.dir");
possible_paths.add(current_dir + File.separator + platform_lib_name);
//add pure library (no path, let OS search)
possible_paths.add(platform_lib_name);
}