Skip to content
This repository was archived by the owner on Dec 29, 2025. It is now read-only.

Commit 8d58b1c

Browse files
authored
Update Libs.java
1 parent 95287d3 commit 8d58b1c

File tree

1 file changed

+73
-0
lines changed
  • src/main/java/id.my.alvinq.prokitid.app/libs

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,81 @@
11
package id.my.alvinq.prokitid.app.libs;
22

33
import android.content.Context;
4+
import java.io.*;
45

56
public class Libs {
67
public static void Main(Context ctx) {
8+
copyAllLibs(ctx);
9+
loadAllLibs(ctx);
710
}
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+
}
881
}

0 commit comments

Comments
 (0)