|
5 | 5 | import android.util.Log; |
6 | 6 | import java.util.ArrayList; |
7 | 7 | import java.io.FilenameFilter; |
| 8 | +// import android.os.PatternMatcher; |
| 9 | +import java.util.regex.Pattern; |
8 | 10 |
|
9 | 11 | public class PythonUtil { |
10 | 12 | private static final String TAG = "pythonutil"; |
11 | 13 |
|
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(); |
19 | 19 |
|
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)); |
26 | 29 | } |
27 | | - }); |
| 30 | + } |
| 31 | + } |
28 | 32 |
|
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); |
35 | 37 |
|
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; |
40 | 50 | } |
41 | 51 |
|
42 | 52 | public static void loadLibraries(File filesDir) { |
|
0 commit comments