mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-20 22:26:54 +01:00
include dict's full-file md5sum when querying for upgrades
Requires adding a new db field to cache the value.
This commit is contained in:
parent
ab29dfa6ce
commit
9778abd6a5
6 changed files with 87 additions and 7 deletions
|
@ -56,7 +56,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
private int addedVersion() { return mAddedVersion; }
|
||||
}
|
||||
private static final String DB_NAME = BuildConfig.DB_NAME;
|
||||
private static final int DB_VERSION = 30;
|
||||
private static final int DB_VERSION = 31;
|
||||
|
||||
public static final String GAME_NAME = "GAME_NAME";
|
||||
public static final String VISID = "VISID";
|
||||
|
@ -97,6 +97,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
|
||||
public static final String DICTNAME = "DICTNAME";
|
||||
public static final String MD5SUM = "MD5SUM";
|
||||
public static final String FULLSUM = "FULLSUM";
|
||||
public static final String WORDCOUNT = "WORDCOUNT";
|
||||
public static final String WORDCOUNTS = "WORDCOUNTS";
|
||||
public static final String LANGCODE = "LANGCODE";
|
||||
|
@ -179,11 +180,12 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
};
|
||||
|
||||
private static final String[][] s_dictInfoColsAndTypes = {
|
||||
{ DICTNAME, "TEXT" }
|
||||
,{ LOC, "UNSIGNED INTEGER(1)" }
|
||||
,{ MD5SUM, "TEXT(32)" }
|
||||
,{ WORDCOUNT,"INTEGER" }
|
||||
,{ LANGCODE, "INTEGER" }
|
||||
{ DICTNAME, "TEXT" },
|
||||
{ LOC, "UNSIGNED INTEGER(1)" },
|
||||
{ MD5SUM, "TEXT(32)" },
|
||||
{ FULLSUM, "TEXT(32)" },
|
||||
{ WORDCOUNT, "INTEGER" },
|
||||
{ LANGCODE, "INTEGER" },
|
||||
};
|
||||
|
||||
private static final String[][] s_dictBrowseColsAndTypes = {
|
||||
|
@ -278,6 +280,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
|
||||
boolean madeSumTable = false;
|
||||
boolean madeChatTable = false;
|
||||
boolean madeDITable = false;
|
||||
switch( oldVersion ) {
|
||||
case 5:
|
||||
createTable( db, TABLE_NAMES.OBITS, s_obitsColsAndTypes );
|
||||
|
@ -298,6 +301,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
case 12:
|
||||
createTable( db, TABLE_NAMES.DICTINFO, s_dictInfoColsAndTypes );
|
||||
createTable( db, TABLE_NAMES.DICTBROWSE, s_dictBrowseColsAndTypes );
|
||||
madeDITable = true;
|
||||
case 13:
|
||||
addSumColumn( db, LASTMOVE );
|
||||
case 14:
|
||||
|
@ -353,6 +357,10 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
if ( !madeSumTable ) {
|
||||
addSumColumn( db, NEXTDUPTIMER );
|
||||
}
|
||||
case 30:
|
||||
if ( !madeDITable ) {
|
||||
addColumn( db, TABLE_NAMES.DICTINFO, s_dictInfoColsAndTypes, FULLSUM );
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -2062,6 +2062,7 @@ public class DBUtils {
|
|||
String[] columns = { DBHelper.LANGCODE,
|
||||
DBHelper.WORDCOUNT,
|
||||
DBHelper.MD5SUM,
|
||||
DBHelper.FULLSUM,
|
||||
/*DBHelper.LOC*/ };
|
||||
String selection = String.format( NAME_FMT, DBHelper.DICTNAME, name );
|
||||
initDB( context );
|
||||
|
@ -2076,12 +2077,19 @@ public class DBUtils {
|
|||
cursor.getInt( cursor.getColumnIndex(DBHelper.WORDCOUNT));
|
||||
result.md5Sum =
|
||||
cursor.getString( cursor.getColumnIndex(DBHelper.MD5SUM));
|
||||
result.fullSum =
|
||||
cursor.getString( cursor.getColumnIndex(DBHelper.FULLSUM));
|
||||
// int loc = cursor.getInt(cursor.getColumnIndex(DBHelper.LOC));
|
||||
// Log.d( TAG, "dictsGetInfo(): read sum %s/loc %d for %s", result.md5Sum,
|
||||
// loc, name );
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
if ( null == result.fullSum ) { // force generation
|
||||
result = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -2095,6 +2103,7 @@ public class DBUtils {
|
|||
values.put( DBHelper.LANGCODE, info.langCode );
|
||||
values.put( DBHelper.WORDCOUNT, info.wordCount );
|
||||
values.put( DBHelper.MD5SUM, info.md5Sum );
|
||||
values.put( DBHelper.FULLSUM, info.fullSum );
|
||||
values.put( DBHelper.LOC, dal.loc.ordinal() );
|
||||
|
||||
initDB( context );
|
||||
|
|
|
@ -310,6 +310,16 @@ public class DictLangCache {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static String getDictFullSum( Context context, String dict )
|
||||
{
|
||||
String result = null;
|
||||
DictInfo info = getInfo( context, dict );
|
||||
if ( null != info ) {
|
||||
result = info.fullSum;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static long getFileLen( Context context, DictAndLoc dal )
|
||||
{
|
||||
File path = dal.getPath( context );
|
||||
|
@ -523,6 +533,9 @@ public class DictLangCache {
|
|||
DictLoc.DOWNLOAD == dal.loc );
|
||||
if ( null != info ) {
|
||||
info.name = dal.name;
|
||||
info.fullSum = Utils.getMD5SumFor( context, dal );
|
||||
Assert.assertTrueNR( null != info.fullSum );
|
||||
|
||||
DBUtils.dictsSetInfo( context, dal, info );
|
||||
} else {
|
||||
Log.i( TAG, "getInfo(): unable to open dict %s", dal.name );
|
||||
|
|
|
@ -66,6 +66,7 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
|
|||
private static final String k_LANG = "lang";
|
||||
private static final String k_LANGCODE = "lc";
|
||||
private static final String k_MD5SUM = "md5sum";
|
||||
private static final String k_FULLSUM = "fullsum";
|
||||
private static final String k_INDEX = "index";
|
||||
private static final String k_LEN = "len";
|
||||
private static final String k_URL = "url";
|
||||
|
@ -231,12 +232,15 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
|
|||
String langCode = DictLangCache.getLangCodeStr( context, lang );
|
||||
String langStr = DictLangCache.getLangName( context, lang );
|
||||
String sum = DictLangCache.getDictMD5Sum( context, dal.name );
|
||||
String fullSum = DictLangCache.getDictFullSum( context, dal.name );
|
||||
Assert.assertTrueNR( null != fullSum );
|
||||
long len = DictLangCache.getFileLen( context, dal );
|
||||
try {
|
||||
params.put( k_NAME, dal.name );
|
||||
params.put( k_LANG, langStr );
|
||||
params.put( k_LANGCODE, langCode );
|
||||
params.put( k_MD5SUM, sum );
|
||||
params.put( k_FULLSUM, fullSum );
|
||||
params.put( k_INDEX, index );
|
||||
params.put( k_LEN, len );
|
||||
} catch( org.json.JSONException jse ) {
|
||||
|
|
|
@ -64,6 +64,7 @@ import java.io.BufferedReader;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.ObjectInputStream;
|
||||
|
@ -465,6 +466,34 @@ public class Utils {
|
|||
return str;
|
||||
}
|
||||
|
||||
public static String getMD5SumFor( Context context, DictUtils.DictAndLoc dal )
|
||||
{
|
||||
String result = null;
|
||||
|
||||
if ( DictUtils.DictLoc.BUILT_IN == dal.loc ) {
|
||||
result = dal.loc.toString();
|
||||
} else {
|
||||
File file = dal.getPath( context );
|
||||
try {
|
||||
InputStream is = new FileInputStream( file );
|
||||
MessageDigest md = MessageDigest.getInstance( "MD5" );
|
||||
byte[] buf = new byte[1024*8];
|
||||
for ( ; ; ) {
|
||||
int nRead = is.read( buf );
|
||||
if ( 0 >= nRead ) {
|
||||
break;
|
||||
}
|
||||
md.update( buf, 0, nRead );
|
||||
}
|
||||
result = Utils.digestToString( md.digest() );
|
||||
} catch ( Exception ex ) {
|
||||
Log.ex( TAG, ex );
|
||||
}
|
||||
}
|
||||
// Log.d( TAG, "getMD5SumFor(%s) => %s", dal.name, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getMD5SumFor( byte[] bytes )
|
||||
{
|
||||
String result = null;
|
||||
|
|
|
@ -20,12 +20,29 @@
|
|||
|
||||
package org.eehouse.android.xw4.jni;
|
||||
|
||||
import org.eehouse.android.xw4.BuildConfig;
|
||||
|
||||
public class DictInfo {
|
||||
// set in java code
|
||||
public String name;
|
||||
public String fullSum; // md5sum of the whole file
|
||||
|
||||
// set in jni code
|
||||
public int langCode;
|
||||
public int wordCount;
|
||||
public String md5Sum;
|
||||
public String md5Sum; // internal (skipping header?)
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if ( BuildConfig.NON_RELEASE ) {
|
||||
return new StringBuilder("{")
|
||||
.append("name: ").append(name)
|
||||
.append(", md5Sum: ").append(md5Sum)
|
||||
.append(", fullSum: ").append(fullSum)
|
||||
.append("}").toString();
|
||||
} else {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue