Удалять служебные папки Android при проверке и после смены загрузчика

This commit is contained in:
Paravis committed 2026-11-14 18:38:52 +03:00
1 parent dd51593af3
commit 2ea5eda1b7
2 files changed
+74

No files matched your search

@@ -474,6 +474,11 @@ public class MainActivity extends Activity {
}
}
int cleanedCount = markers ? cleanupAll(paravis, data) : 0;
if (cleanedCount > 0) {
message = message + "\nУдалено служебных папок: " + cleanedCount;
}
int legacy = -1;
int uefi = -1;
if (markers) {
@@ -1028,6 +1033,10 @@ public class MainActivity extends Activity {
writeBootState(stateRoot, legacyIndex(type), currentUefi);
}
}
if (prep == null) {
File cleanRoot = findParavisRoot();
cleanupAll(cleanRoot, findDataRoot(cleanRoot));
}
final byte[] f1 = first;
final byte[] f2 = second;
final String result = prep != null ? prep
@@ -1441,6 +1450,7 @@ public class MainActivity extends Activity {
}
report.append(name).append(" ").append(destination.length()).append(" байт\n");
}
cleanupAll(root, findDataRoot(root));
writeBootState(root, currentLegacy, uefiIndex(type));
report.append('\n').append(bootDir.getAbsolutePath());
return report.toString();
@@ -1623,6 +1633,51 @@ public class MainActivity extends Activity {
}
}
private int cleanupAll(File paravis, File data) {
int removed = 0;
removed += cleanupRoot(paravis);
removed += cleanupRoot(data);
if (removed > 0) {
android.util.Log.i("paravis", "service folders removed: " + removed);
}
return removed;
}
private int cleanupRoot(File root) {
if (root == null) {
return 0;
}
File[] children = root.listFiles();
if (children == null) {
return 0;
}
int removed = 0;
for (File child : children) {
String name = child.getName();
boolean service = name.equals("Android")
|| name.equals("LOST.DIR")
|| name.equals(".thumbnails")
|| name.equals(".android_secure")
|| name.startsWith(".Trash-");
if (service && deleteRecursively(child)) {
removed++;
}
}
return removed;
}
private boolean deleteRecursively(File file) {
if (file.isDirectory()) {
File[] children = file.listFiles();
if (children != null) {
for (File child : children) {
deleteRecursively(child);
}
}
}
return file.delete();
}
private static boolean looksLikeParavis(byte[] mbr) {
boolean fat32 = false;
boolean vtoy = false;