use full sum to fix fake dict upgrade offers

Needed to be incorporating the fullfile md5sum that was added recently
This commit is contained in:
Eric House 2022-05-13 19:42:12 -07:00
parent f4c36f8c81
commit 78b5e280cd
5 changed files with 19 additions and 32 deletions

View file

@ -2032,8 +2032,8 @@ public class BoardDelegate extends DelegateBase
// different name, offer to install. // different name, offer to install.
String msg = null; String msg = null;
if ( oldName.equals( newName ) ) { if ( oldName.equals( newName ) ) {
String oldSum = DictLangCache.getDictMD5Sum( m_activity, String oldSum = DictLangCache
oldName ); .getDictMD5Sums( m_activity, oldName )[0];
if ( !oldSum.equals( newSum ) ) { if ( !oldSum.equals( newSum ) ) {
// Same dict, different versions // Same dict, different versions
msg = getString( R.string.inform_dict_diffversion_fmt, msg = getString( R.string.inform_dict_diffversion_fmt,

View file

@ -283,8 +283,8 @@ public class DictBrowseDelegate extends DelegateBase
if ( BuildConfig.NON_RELEASE ) { if ( BuildConfig.NON_RELEASE ) {
TextView tv = (TextView)findViewById( R.id.md5sum_summary ); TextView tv = (TextView)findViewById( R.id.md5sum_summary );
tv.setVisibility( View.VISIBLE ); tv.setVisibility( View.VISIBLE );
String sum = DictLangCache.getDictMD5Sum( m_activity, m_name ); String[] sums = DictLangCache.getDictMD5Sums( m_activity, m_name );
tv.setText( "md5: " + sum ); tv.setText( "md5: " + sums[0] );
} }
setShowConfig(); setShowConfig();

View file

@ -300,22 +300,13 @@ public class DictLangCache {
return s_langCodeStrs.get( code ); return s_langCodeStrs.get( code );
} }
public static String getDictMD5Sum( Context context, String dict ) public static String[] getDictMD5Sums( Context context, String dict )
{ {
String result = null; String[] result = {null, null};
DictInfo info = getInfo( context, dict ); DictInfo info = getInfo( context, dict );
if ( null != info ) { if ( null != info ) {
result = info.md5Sum; result[0] = info.md5Sum;
} result[1] = info.fullSum;
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; return result;
} }

View file

@ -1434,7 +1434,7 @@ public class DictsDelegate extends ListDelegateBase
// DictLangCache hits the DB hundreds of times below. Fix! // DictLangCache hits the DB hundreds of times below. Fix!
Log.w( TAG, "Fix me I'm stupid" ); Log.w( TAG, "Fix me I'm stupid" );
try { try {
// Log.d( TAG, "data: %s", jsonData ); // Log.d( TAG, "digestData(%s)", jsonData );
JSONObject obj = new JSONObject( jsonData ); JSONObject obj = new JSONObject( jsonData );
langs = obj.optJSONArray( "langs" ); langs = obj.optJSONArray( "langs" );
@ -1483,15 +1483,12 @@ public class DictsDelegate extends ListDelegateBase
if ( DictLangCache.haveDict( m_activity, if ( DictLangCache.haveDict( m_activity,
localLangName, name )){ localLangName, name )){
boolean matches = true; boolean matches = true;
String curSum = DictLangCache JSONArray sums = dict.getJSONArray("md5sums");
.getDictMD5Sum( m_activity, name ); if ( null != sums ) {
if ( null != curSum ) { matches = false;
JSONArray sums = String[] curSums = DictLangCache.getDictMD5Sums( m_activity, name );
dict.getJSONArray("md5sums"); for ( String curSum : curSums ) {
if ( null != sums ) { for ( int kk = 0; !matches && kk < sums.length();
matches = false;
for ( int kk = 0;
!matches && kk < sums.length();
++kk ) { ++kk ) {
String sum = sums.getString( kk ); String sum = sums.getString( kk );
matches = sum.equals( curSum ); matches = sum.equals( curSum );

View file

@ -218,16 +218,15 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
int lang = DictLangCache.getDictLangCode( context, dal ); int lang = DictLangCache.getDictLangCode( context, dal );
String langCode = DictLangCache.getLangCodeStr( context, lang ); String langCode = DictLangCache.getLangCodeStr( context, lang );
String langStr = DictLangCache.getLangName( context, lang ); String langStr = DictLangCache.getLangName( context, lang );
String sum = DictLangCache.getDictMD5Sum( context, dal.name ); String[] sums = DictLangCache.getDictMD5Sums( context, dal.name );
String fullSum = DictLangCache.getDictFullSum( context, dal.name ); Assert.assertTrueNR( null != sums[1] );
Assert.assertTrueNR( null != fullSum );
long len = DictLangCache.getFileLen( context, dal ); long len = DictLangCache.getFileLen( context, dal );
try { try {
params.put( k_NAME, dal.name ); params.put( k_NAME, dal.name );
params.put( k_LANG, langStr ); params.put( k_LANG, langStr );
params.put( k_LANGCODE, langCode ); params.put( k_LANGCODE, langCode );
params.put( k_MD5SUM, sum ); params.put( k_MD5SUM, sums[0] );
params.put( k_FULLSUM, fullSum ); params.put( k_FULLSUM, sums[1] );
params.put( k_INDEX, index ); params.put( k_INDEX, index );
params.put( k_LEN, len ); params.put( k_LEN, len );
} catch( org.json.JSONException jse ) { } catch( org.json.JSONException jse ) {