From 24c1296b25e76d45120d8659a180e9fe1d402205 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 9 Aug 2019 19:50:58 -0400 Subject: [PATCH] Future support for Galaxy store versions --- .../smapiandroidinstaller/ApkExtractor.java | 10 ++++++++-- .../smapiandroidinstaller/DialogFrag.java | 10 ---------- .../smapiandroidinstaller/MainActivity.java | 2 +- .../smapiandroidinstaller/WriteApk.java | 19 ++++++++++++------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/MartyrPher/smapiandroidinstaller/ApkExtractor.java b/app/src/main/java/com/MartyrPher/smapiandroidinstaller/ApkExtractor.java index 25e3e71..9ece4cd 100644 --- a/app/src/main/java/com/MartyrPher/smapiandroidinstaller/ApkExtractor.java +++ b/app/src/main/java/com/MartyrPher/smapiandroidinstaller/ApkExtractor.java @@ -17,7 +17,7 @@ import android.util.Log; public class ApkExtractor{ private static final String TAG = "ApkExtractor"; - private static final String[] PACKAGE_NAMES = {"com.martyrpher.stardewvalley", "com.chucklefish.stardewvalley"}; + private static final String[] PACKAGE_NAMES = {"com.martyrpher.stardewvalley", "com.chucklefish.stardewvalley", "com.chucklefish.stardewvalleysamsung"}; private final Context context; @@ -25,6 +25,10 @@ public class ApkExtractor{ private PackageManager mPackageManager; private PackageInfo mPackageInfo; + public static String sourceApkFilename; + + private boolean[] foundApk = {false, false, false}; + public ApkExtractor(Context appContext) { this.context = appContext; @@ -33,7 +37,7 @@ public class ApkExtractor{ public boolean[] checkForInstallOrUpgrade() { mPackageManager = context.getPackageManager(); - boolean[] foundApk = {false, false}; + for (int i = 0; i < foundApk.length; i++) { try @@ -60,6 +64,7 @@ public class ApkExtractor{ try { File apkFile = new File(mApplicationInfo.publicSourceDir); + Log.e(TAG, "APK path: " + mApplicationInfo.publicSourceDir); File dest = new File(Environment.getExternalStorageDirectory() + "/SMAPI Installer/"); if (apkFile.exists()) { try { @@ -67,6 +72,7 @@ public class ApkExtractor{ { if(dest.mkdir());//directory is created; } + sourceApkFilename = apkFile.getName(); copy(apkFile.getAbsoluteFile(), new File(dest, apkFile.getName())); } catch (IOException e) { Log.e(TAG, e.getLocalizedMessage()); diff --git a/app/src/main/java/com/MartyrPher/smapiandroidinstaller/DialogFrag.java b/app/src/main/java/com/MartyrPher/smapiandroidinstaller/DialogFrag.java index cfa8398..8dc3dfc 100644 --- a/app/src/main/java/com/MartyrPher/smapiandroidinstaller/DialogFrag.java +++ b/app/src/main/java/com/MartyrPher/smapiandroidinstaller/DialogFrag.java @@ -23,16 +23,6 @@ public class DialogFrag extends DialogFragment { private static ProgressBar mProgressBar; private static TextView mTextView; - //Test array to cycle through different messages - private static int[] messages = { R.string.installing_pufferchicks, - R.string.install_milk_cows, - R.string.install_ancient_fruit , - R.string.install_abigail_rocks, - R.string.install_feeding_juminos, - R.string.install_squid_ocean, - R.string.install_dino_egg, - R.string.install_rock_crab }; - public DialogFrag() { } diff --git a/app/src/main/java/com/MartyrPher/smapiandroidinstaller/MainActivity.java b/app/src/main/java/com/MartyrPher/smapiandroidinstaller/MainActivity.java index b98fe8b..6a0eda3 100644 --- a/app/src/main/java/com/MartyrPher/smapiandroidinstaller/MainActivity.java +++ b/app/src/main/java/com/MartyrPher/smapiandroidinstaller/MainActivity.java @@ -38,7 +38,7 @@ public class MainActivity extends AppCompatActivity { foundGame = apkExtractor.checkForInstallOrUpgrade(); - if((foundGame[0] || foundGame[1])) + if((foundGame[0] || foundGame[1] || foundGame[2])) { BackgroundTask backgroundTask = new BackgroundTask(MainActivity.this, apkExtractor, foundGame[0]); backgroundTask.execute(); diff --git a/app/src/main/java/com/MartyrPher/smapiandroidinstaller/WriteApk.java b/app/src/main/java/com/MartyrPher/smapiandroidinstaller/WriteApk.java index e454f3f..b08ef36 100644 --- a/app/src/main/java/com/MartyrPher/smapiandroidinstaller/WriteApk.java +++ b/app/src/main/java/com/MartyrPher/smapiandroidinstaller/WriteApk.java @@ -1,5 +1,7 @@ package com.MartyrPher.smapiandroidinstaller; +import android.util.Log; + import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; @@ -7,14 +9,13 @@ import java.io.FileOutputStream; import java.io.InputStream; import java.util.zip.CRC32; import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; public class WriteApk { - private static final String TAG = "OpenApk"; + private static final String TAG = "WriteApk"; //Blank Constructor public WriteApk() @@ -25,13 +26,15 @@ public class WriteApk { try { byte[] buffer = new byte[4096]; - ZipFile zipFile = new ZipFile(source); ZipInputStream zin = new ZipInputStream(new FileInputStream(source)); ZipOutputStream out = new ZipOutputStream(new FileOutputStream( source + "_patched.apk")); - for(int i = 0; i < files.length; i++){ - CRC32 crc = new CRC32(); + CRC32 crc = new CRC32(); + + for(int i = 0; i < files.length; i++) + { + if (!compression[i]) { int bytesRead; @@ -63,6 +66,7 @@ public class WriteApk { } for(ZipEntry ze = zin.getNextEntry(); ze != null; ze = zin.getNextEntry()){ if(!apkEntryMatch(ze.getName(), files, path)){ + //ZipEntry loc_ze = new ZipEntry(ze.getName()); out.putNextEntry(ze); for(int read = zin.read(buffer); read > -1; read = zin.read(buffer)){ out.write(buffer, 0, read); @@ -73,8 +77,9 @@ public class WriteApk { out.close(); zin.close(); source.delete(); - }catch(Exception e){ - e.printStackTrace(); + } + catch(Exception e){ + Log.e(TAG, e.getMessage(), e); } }