Delete ALL the leftover APK files

This commit is contained in:
Chris 2019-08-10 00:32:11 -04:00
parent 24c1296b25
commit 057d6e9746
1 changed files with 77 additions and 11 deletions

View File

@ -3,6 +3,7 @@ package com.MartyrPher.smapiandroidinstaller;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Environment; import android.os.Environment;
import android.util.Log;
import java.io.File; import java.io.File;
@ -206,26 +207,19 @@ public class BackgroundTask extends AsyncTask<Void, Integer, Boolean> {
signApk.commitSignApk(); signApk.commitSignApk();
publishProgress(81); publishProgress(81);
File filesToDelete = new File(Environment.getExternalStorageDirectory() + DIR_APK_FILES);
File deleteOldApk = new File(Environment.getExternalStorageDirectory() + "/SMAPI Installer/" + ApkExtractor.sourceApkFilename + "_patched.apk"); File deleteOldApk = new File(Environment.getExternalStorageDirectory() + "/SMAPI Installer/" + ApkExtractor.sourceApkFilename + "_patched.apk");
deleteOldApk.delete(); deleteOldApk.delete();
publishProgress(90); publishProgress(90);
if (filesToDelete.isDirectory()) deleteApkFiles();
{
String[] child = filesToDelete.list();
for (int i = 0; i < child.length; i++)
{
new File(filesToDelete, child[i]).delete();
}
filesToDelete.delete();
}
publishProgress(100); publishProgress(100);
return true; return true;
} }
catch(Exception e) catch(Exception e)
{ {
DialogFrag.dismissDialogString(contextActivity, e.getMessage()); Log.e(TAG, e.getMessage(), e);
DialogFrag.dismissDialog();
return false; return false;
} }
} }
@ -273,4 +267,76 @@ public class BackgroundTask extends AsyncTask<Void, Integer, Boolean> {
apkInstall.installNewStardew(); apkInstall.installNewStardew();
} }
} }
//This is super wack but I'm on a time crunch and can probably do this in one nested FOR loop...
private void deleteApkFiles()
{
File filesToDelete = new File(Environment.getExternalStorageDirectory() + DIR_APK_FILES);
File mdpiToDelete = new File(Environment.getExternalStorageDirectory() + DIR_APK_FILES_MDPI);
File hdpiToDelete = new File(Environment.getExternalStorageDirectory() + DIR_APK_FILES_HDPI);
File xhdpiToDelete = new File(Environment.getExternalStorageDirectory() + DIR_APK_FILES_XHDPI);
File xxhdpiToDelete = new File(Environment.getExternalStorageDirectory() + DIR_APK_FILES_XXHDPI);
File xxxhdpiToDelete = new File(Environment.getExternalStorageDirectory() + DIR_APK_FILES_XXXHDPI);
if (filesToDelete.isDirectory())
{
String[] child = filesToDelete.list();
for (int i = 0; i < child.length; i++)
{
new File(filesToDelete, child[i]).delete();
}
}
if (mdpiToDelete.isDirectory())
{
String[] child = mdpiToDelete.list();
for (int i = 0; i < child.length; i++)
{
new File(mdpiToDelete, child[i]).delete();
}
mdpiToDelete.delete();
}
if (hdpiToDelete.isDirectory())
{
String[] child = hdpiToDelete.list();
for (int i = 0; i < child.length; i++)
{
new File(hdpiToDelete, child[i]).delete();
}
hdpiToDelete.delete();
}
if (xhdpiToDelete.isDirectory())
{
String[] child = xhdpiToDelete.list();
for (int i = 0; i < child.length; i++)
{
new File(xhdpiToDelete, child[i]).delete();
}
xhdpiToDelete.delete();
}
if (xxhdpiToDelete.isDirectory())
{
String[] child = xxhdpiToDelete.list();
for (int i = 0; i < child.length; i++)
{
new File(xxhdpiToDelete, child[i]).delete();
}
xxhdpiToDelete.delete();
}
if (xxxhdpiToDelete.isDirectory())
{
String[] child = xxxhdpiToDelete.list();
for (int i = 0; i < child.length; i++)
{
new File(xxxhdpiToDelete, child[i]).delete();
}
xxxhdpiToDelete.delete();
}
filesToDelete.delete();
}
} }