|
3 | 3 | import java.io.File; |
4 | 4 |
|
5 | 5 | import android.util.Log; |
6 | | - |
| 6 | +import java.util.ArrayList; |
| 7 | +import java.io.FilenameFilter; |
7 | 8 |
|
8 | 9 | public class PythonUtil { |
9 | 10 | private static final String TAG = "pythonutil"; |
10 | 11 |
|
11 | | - protected static String[] getLibraries() { |
12 | | - return new String[] { |
13 | | - "SDL2", |
14 | | - "SDL2_image", |
15 | | - "SDL2_mixer", |
16 | | - "SDL2_ttf", |
17 | | - "crypto1.0.2h", |
18 | | - "ssl1.0.2h", |
19 | | - "python2.7", |
20 | | - "python3.5m", |
21 | | - "python3.6m", |
22 | | - "main" |
| 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"); |
| 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.*"); |
| 26 | + } |
| 27 | + }); |
| 28 | + |
| 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); |
23 | 34 | }; |
| 35 | + |
| 36 | + MyList.add("python2.7"); |
| 37 | + MyList.add("python3.5m"); |
| 38 | + MyList.add("main"); |
| 39 | + return MyList; |
24 | 40 | } |
25 | 41 |
|
26 | | - public static void loadLibraries(File filesDir) { |
| 42 | + public static void loadLibraries(File filesDir) { |
27 | 43 |
|
28 | 44 | String filesDirPath = filesDir.getAbsolutePath(); |
29 | 45 | boolean foundPython = false; |
30 | 46 |
|
31 | | - for (String lib : getLibraries()) { |
| 47 | + for (String lib : getLibraries(filesDir)) { |
32 | 48 | Log.v(TAG, "Loading library: " + lib); |
33 | 49 | try { |
34 | 50 | System.loadLibrary(lib); |
@@ -68,3 +84,4 @@ public static void loadLibraries(File filesDir) { |
68 | 84 | Log.v(TAG, "Loaded everything!"); |
69 | 85 | } |
70 | 86 | } |
| 87 | + |
0 commit comments