From 1ceea2cde22397fe909bdc84e1caf6b04253854b Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 26 Oct 2010 18:20:49 -0700 Subject: [PATCH] check that default dict exists and if it doesn't use same as if hadn't been specified. Catches case where dict is downloaded, made new-game default, and then deleted. --- .../src/org/eehouse/android/xw4/GameUtils.java | 16 ++++++++++++++++ .../org/eehouse/android/xw4/jni/CommonPrefs.java | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java index b6a4364db..e926c1a17 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -243,6 +243,22 @@ public class GameUtils { return al.toArray( new String[al.size()] ); } + public static boolean dictExists( Context context, String name ) + { + boolean exists = dictIsBuiltin( context, name ); + if ( !exists ) { + name = addDictExtn( name ); + try { + FileInputStream fis = context.openFileInput( name ); + fis.close(); + exists = true; + } catch ( java.io.FileNotFoundException fnf ) { + } catch ( java.io.IOException ioe ) { + } + } + return exists; + } + public static boolean dictIsBuiltin( Context context, String name ) { boolean builtin = false; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java index 0e04a7b4b..42247b460 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java @@ -206,7 +206,7 @@ public class CommonPrefs { public static String getDefaultDict( Context context ) { String value = getString( context, R.string.key_default_dict ); - if ( value.equals("") ) { + if ( value.equals("") || !GameUtils.dictExists( context, value ) ) { value = GameUtils.dictList( context )[0]; } return value;