From 7259a13f3e8b3d33ecb2984c273254bca04a05d3 Mon Sep 17 00:00:00 2001 From: Chris Boyle Date: Sun, 26 Oct 2014 13:51:47 +0000 Subject: [PATCH] Fix #217: track puzzlesgen version explicitly, not by timestamp. Bump version. --- app/build.gradle | 4 ++-- .../java/name/boyle/chris/sgtpuzzles/GamePlay.java | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 357a59518..a92348720 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { defaultConfig { applicationId "name.boyle.chris.sgtpuzzles" - versionCode 88 - versionName "10286.4" + versionCode 89 + versionName "10286.5" if (file(ndkDir.absolutePath + '/platforms/android-15').exists()) { // the last without PIE minSdkVersion 7 diff --git a/app/src/main/java/name/boyle/chris/sgtpuzzles/GamePlay.java b/app/src/main/java/name/boyle/chris/sgtpuzzles/GamePlay.java index 8ecb0e85e..ee630c82f 100644 --- a/app/src/main/java/name/boyle/chris/sgtpuzzles/GamePlay.java +++ b/app/src/main/java/name/boyle/chris/sgtpuzzles/GamePlay.java @@ -37,6 +37,7 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Color; @@ -98,6 +99,7 @@ public class GamePlay extends ActionBarActivity implements OnSharedPreferenceCha public static final String SAVED_COMPLETED_PREFIX = "savedCompleted_"; public static final String SAVED_GAME_PREFIX = "savedGame_"; public static final String LAST_PARAMS_PREFIX = "last_params_"; + private static final String PUZZLESGEN_LAST_UPDATE = "puzzlesgen_last_update"; private ProgressDialog progress; private TextView statusBar; @@ -564,6 +566,7 @@ private String generateGame(final List args) throws IllegalArgumentExcep return game; } + @SuppressLint("CommitPrefEdits") private void startGameGenProcess(final List args) throws IOException { final ApplicationInfo applicationInfo = getApplicationInfo(); final File dataDir = new File(applicationInfo.dataDir); @@ -577,8 +580,13 @@ private void startGameGenProcess(final List args) throws IOException { final String suffix = canRunPIE ? "-with-pie" : "-no-pie"; File installablePath = new File(libDir, "libpuzzlesgen" + suffix + ".so"); File executablePath = new File(dataDir, "puzzlesgen" + suffix); - if (!executablePath.exists() || - executablePath.lastModified() < installablePath.lastModified()) { + boolean needCopy = true; + try { + final int currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; + needCopy = !executablePath.exists() || (prefs.getInt(PUZZLESGEN_LAST_UPDATE, 0) < currentVersion); + prefsSaver.save(prefs.edit().putInt(PUZZLESGEN_LAST_UPDATE, currentVersion)); + } catch (PackageManager.NameNotFoundException ignored) {} + if (needCopy) { copyFile(installablePath, executablePath); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {