Skip to content

Commit 6703ffd

Browse files
committed
Restructured code for adding libs by regex
1 parent 6f33b48 commit 6703ffd

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

pythonforandroid/bootstraps/sdl2/build/src/org/kivy/android/PythonUtil.java

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,48 @@
55
import android.util.Log;
66
import java.util.ArrayList;
77
import java.io.FilenameFilter;
8+
// import android.os.PatternMatcher;
9+
import java.util.regex.Pattern;
810

911
public class PythonUtil {
1012
private static final String TAG = "pythonutil";
1113

12-
protected static ArrayList<String> getLibraries(File filesDir) {
13-
14-
ArrayList<String> MyList = new ArrayList<String>();
15-
MyList.add("SDL2");
16-
MyList.add("SDL2_image");
17-
MyList.add("SDL2_mixer");
18-
MyList.add("SDL2_ttf");
14+
protected static void addLibraryIfExists(ArrayList<String> libsList, String pattern, File libsDir) {
15+
// pattern should be the name of the lib file, without the
16+
// preceding "lib" or suffix ".so", for instance "ssl.*" will
17+
// match files of the form "libssl.*.so".
18+
File [] files = libsDir.listFiles();
1919

20-
String absPath = filesDir.getParentFile().getParentFile().getAbsolutePath() + "/lib/";
21-
filesDir = new File(absPath);
22-
File [] files = filesDir.listFiles(new FilenameFilter() {
23-
@Override
24-
public boolean accept(File dir, String name) {
25-
return name.matches(".*ssl.*") || name.matches(".*crypto.*");
20+
pattern = "lib" + pattern + "\\.so";
21+
Pattern p = Pattern.compile(pattern);
22+
for (int i = 0; i < files.length; ++i) {
23+
File file = files[i];
24+
String name = file.getName();
25+
Log.v(TAG, "Checking pattern " + pattern + " against " + name);
26+
if (p.matcher(name).matches()) {
27+
Log.v(TAG, "Pattern " + pattern + " matched file " + name);
28+
libsList.add(name.substring(3, name.length() - 3));
2629
}
27-
});
30+
}
31+
}
2832

29-
for (int i = 0; i < files.length; ++i) {
30-
File mfl = files[i];
31-
String name = mfl.getName();
32-
name = name.substring(3, name.length() - 3);
33-
MyList.add(name);
34-
};
33+
protected static ArrayList<String> getLibraries(File filesDir) {
34+
35+
String libsDirPath = filesDir.getParentFile().getParentFile().getAbsolutePath() + "/lib/";
36+
File libsDir = new File(libsDirPath);
3537

36-
MyList.add("python2.7");
37-
MyList.add("python3.5m");
38-
MyList.add("main");
39-
return MyList;
38+
ArrayList<String> libsList = new ArrayList<String>();
39+
addLibraryIfExists(libsList, "crystax", libsDir);
40+
libsList.add("SDL2");
41+
libsList.add("SDL2_image");
42+
libsList.add("SDL2_mixer");
43+
libsList.add("SDL2_ttf");
44+
addLibraryIfExists(libsList, "ssl.*", libsDir);
45+
addLibraryIfExists(libsList, "crypto.*", libsDir);
46+
libsList.add("python2.7");
47+
libsList.add("python3.5m");
48+
libsList.add("main");
49+
return libsList;
4050
}
4151

4252
public static void loadLibraries(File filesDir) {

0 commit comments

Comments
 (0)