MCPcopy Create free account
hub / github.com/NeoTerrm/NeoTerm / SetupThread

Class SetupThread

app/src/main/java/io/neoterm/setup/SetupThread.java:26–165  ·  view source on GitHub ↗

@author kiva

Source from the content-addressed store, hash-verified

24 */
25
26final class SetupThread extends Thread {
27 private final SourceConnection sourceConnection;
28 private final File prefixPath;
29 private final AppCompatActivity activity;
30 private final ResultListener resultListener;
31 private final ProgressDialog progressDialog;
32
33 public SetupThread(AppCompatActivity activity, SourceConnection sourceConnection,
34 File prefixPath, ResultListener resultListener,
35 ProgressDialog progressDialog) {
36 this.activity = activity;
37 this.sourceConnection = sourceConnection;
38 this.prefixPath = prefixPath;
39 this.resultListener = resultListener;
40 this.progressDialog = progressDialog;
41 }
42
43 @Override
44 public void run() {
45 try {
46 final String stagingPrefixPath = NeoTermPath.ROOT_PATH + "/usr-staging";
47 final File stagingPrefixFile = new File(stagingPrefixPath);
48
49 if (stagingPrefixFile.exists()) {
50 deleteFolder(stagingPrefixFile);
51 }
52
53 int totalReadBytes = 0;
54 final byte[] buffer = new byte[8096];
55 final List<Pair<String, String>> symlinks = new ArrayList<>(50);
56
57
58 try (ZipInputStream zipInput = new ZipInputStream(sourceConnection.getInputStream())) {
59 ZipEntry zipEntry;
60
61 int totalBytes = sourceConnection.getSize();
62
63 while ((zipEntry = zipInput.getNextEntry()) != null) {
64 totalReadBytes += zipEntry.getCompressedSize();
65
66 final int totalReadBytesFinal = totalReadBytes;
67 final int totalBytesFinal = totalBytes;
68
69 activity.runOnUiThread(() -> {
70 try {
71 double progressFloat = ((double) totalReadBytesFinal) / ((double) totalBytesFinal) * 100.0;
72 progressDialog.setProgress((int) progressFloat);
73 } catch (RuntimeException ignore) {
74 // activity dismissed
75 }
76 });
77
78 if (zipEntry.getName().contains("SYMLINKS.txt")) {
79 BufferedReader symlinksReader = new BufferedReader(new InputStreamReader(zipInput));
80 String line;
81 while ((line = symlinksReader.readLine()) != null) {
82 if (line.isEmpty()) {
83 continue;

Callers 1

setupMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected