|
1 | 1 | package id.my.alvinq.prokitid.app.libs; |
2 | 2 |
|
3 | 3 | import android.content.Context; |
| 4 | +import java.io.*; |
4 | 5 |
|
5 | 6 | public class Libs { |
6 | 7 | public static void Main(Context ctx) { |
| 8 | + copyAllLibs(ctx); |
| 9 | + loadAllLibs(ctx); |
7 | 10 | } |
| 11 | + public static void copyAllLibs(Context ctx) { |
| 12 | + try { |
| 13 | + //Context context = ctx; |
| 14 | + String dirPath = ctx.getDir("alvinqid", Context.MODE_PRIVATE).getAbsolutePath(); |
| 15 | + File dirsPath = new File(dirPath, "libs"); |
| 16 | + File libsDir = new File("/storage/emulated/0/alvinqid/libs"); |
| 17 | + if (!libsDir.exists()) { |
| 18 | + libsDir.mkdirs(); |
| 19 | + Logger.get().info("Libs Folder Created!"); |
| 20 | + } else { |
| 21 | + if(!libsDir.isDirectory()) { |
| 22 | + libsDir.delete(); |
| 23 | + libsDir.mkdirs(); |
| 24 | + } |
| 25 | + } |
| 26 | + if (!dirsPath.exists()) { |
| 27 | + dirsPath.mkdirs(); |
| 28 | + Logger.get().info("Folder Internal Libs"); |
| 29 | + } else { |
| 30 | + if(!dirsPath.isDirectory()) { |
| 31 | + dirsPath.delete(); |
| 32 | + dirsPath.mkdirs(); |
| 33 | + } else { |
| 34 | + dirsPath.delete(); |
| 35 | + dirsPath.mkdirs(); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + File[] jars = libsDir.listFiles(); |
| 40 | + if (jars != null) { |
| 41 | + for (File jar : jars) { |
| 42 | + if(!jar.getName().endsWith(".jar")) continue; |
| 43 | + File resf = new File(dirsPath, jar.getName()); |
| 44 | + copyFile(jar, resf); |
| 45 | + } |
| 46 | + } |
| 47 | + } catch (Exception e) { |
| 48 | + throw new RuntimeException(e); |
| 49 | + } |
| 50 | + } |
| 51 | + public static void copyFile(File source, File dest) throws IOException { |
| 52 | + try (InputStream in = new FileInputStream(source); |
| 53 | + OutputStream out = new FileOutputStream(dest)) { |
| 54 | + |
| 55 | + byte[] buffer = new byte[4096]; |
| 56 | + int length; |
| 57 | + while ((length = in.read(buffer)) > 0) { |
| 58 | + out.write(buffer, 0, length); |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + public static void loadAllLibs(Context ctx) { |
| 63 | + try { |
| 64 | + String dirPath = ctx.getDir("alvinqid", Context.MODE_PRIVATE).getAbsolutePath(); |
| 65 | + //File libsDir = new File("/storage/emulated/0/alvinqid", "libs"); |
| 66 | + File libsDir = new File(dirPath, "libs"); |
| 67 | + |
| 68 | + File[] jars = libsDir.listFiles(); |
| 69 | + if (jars != null) { |
| 70 | + for (File jar : jars) { |
| 71 | + if(!jar.getName().endsWith(".jar")) continue; |
| 72 | + //LogToast(ctx, "Loaded -> " + jar.getName()); |
| 73 | + Logger.get().info("Loaded -> " + jar.getName()); |
| 74 | + LibsManager.get(ctx).loadLib(jar); |
| 75 | + } |
| 76 | + } |
| 77 | + } catch (Exception e) { |
| 78 | + throw new RuntimeException(e); |
| 79 | + } |
| 80 | + } |
8 | 81 | } |
0 commit comments