From 07dd7f2eedc50ff2f6181c3003e009db51bf7de5 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 3 Jan 2016 20:19:46 -0800 Subject: [PATCH] use a different name for each variant's db when written to SD card so they don't overwrite each other's. --- xwords4/android/XWords4-dbg/assets/.gitignore | 1 + .../src/org/eehouse/android/xw4dbg/.gitignore | 1 + .../src/org/eehouse/android/xw4/DBUtils.java | 29 +++++++++++++++---- xwords4/android/scripts/genvers.sh | 1 + 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/xwords4/android/XWords4-dbg/assets/.gitignore b/xwords4/android/XWords4-dbg/assets/.gitignore index 7926bc1b2..7ea20678c 100644 --- a/xwords4/android/XWords4-dbg/assets/.gitignore +++ b/xwords4/android/XWords4-dbg/assets/.gitignore @@ -2,3 +2,4 @@ BasEnglish2to8.xwd CollegeEng_2to8.xwd Top5000.xwd changes.html +gitvers.txt diff --git a/xwords4/android/XWords4-dbg/src/org/eehouse/android/xw4dbg/.gitignore b/xwords4/android/XWords4-dbg/src/org/eehouse/android/xw4dbg/.gitignore index ef65f4ec1..cf33b4575 100644 --- a/xwords4/android/XWords4-dbg/src/org/eehouse/android/xw4dbg/.gitignore +++ b/xwords4/android/XWords4-dbg/src/org/eehouse/android/xw4dbg/.gitignore @@ -124,3 +124,4 @@ RelayInviteDelegate.java XWConnAddrPreference.java XWDevIDPreference.java XWExpListAdapter.java +RequestCode.java diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index 088d5ee8d..c524db255 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -1774,10 +1774,15 @@ public class DBUtils { public static boolean gameDBExists( Context context ) { - String name = DBHelper.getDBName(); - File sdcardDB = new File( Environment.getExternalStorageDirectory(), - name ); - return sdcardDB.exists(); + String varName = getVariantDBName(); + boolean exists = new File( Environment.getExternalStorageDirectory(), + varName ).exists(); + if ( !exists ) { + // try the old one + exists = new File( Environment.getExternalStorageDirectory(), + DBHelper.getDBName() ).exists(); + } + return exists; } public static String[] getColumns( SQLiteDatabase db, String name ) @@ -2128,8 +2133,16 @@ public class DBUtils { { String name = DBHelper.getDBName(); File gamesDB = context.getDatabasePath( name ); + + // Use the variant name EXCEPT where we're copying from sdCard and + // only the older name exists. File sdcardDB = new File( Environment.getExternalStorageDirectory(), - name ); + getVariantDBName() ); + if ( !toSDCard && !sdcardDB.exists() ) { + sdcardDB = new File( Environment.getExternalStorageDirectory(), + name ); + } + try { File srcDB = toSDCard? gamesDB : sdcardDB; if ( srcDB.exists() ) { @@ -2144,6 +2157,12 @@ public class DBUtils { } } + private static String getVariantDBName() + { + return String.format( "%s_%s", DBHelper.getDBName(), + BuildConstants.VARIANT ); + } + // Chat is independent of the GameLock mechanism because it's not // touching the SNAPSHOT column. private static void saveChatHistory( Context context, long rowid, diff --git a/xwords4/android/scripts/genvers.sh b/xwords4/android/scripts/genvers.sh index 161335ac8..6407a2452 100755 --- a/xwords4/android/scripts/genvers.sh +++ b/xwords4/android/scripts/genvers.sh @@ -114,6 +114,7 @@ class BuildConstants { public static final boolean THUMBNAIL_SUPPORTED = $THUMBNAIL_SUPPORTED; public static final long BUILD_STAMP = $(date +'%s'); public static final String DBG_TAG = "$DBG_TAG"; + public static final String VARIANT = "$VARIANT"; } EOF