diff --git a/src/su/xash/fwgslib/FWGSLib.java b/src/su/xash/fwgslib/FWGSLib.java index caeb1617..67c904d2 100644 --- a/src/su/xash/fwgslib/FWGSLib.java +++ b/src/su/xash/fwgslib/FWGSLib.java @@ -24,6 +24,7 @@ import android.preference.*; public class FWGSLib { private static final String TAG = "FWGSLib"; + static String externalFilesDir; public static boolean FBitSet( final int bits, final int mask ) { return ((bits & mask) == mask); @@ -110,19 +111,52 @@ public class FWGSLib return dir.getPath() + "/xash"; return "/sdcard/xash"; } - + static class GetExternalFilesDir extends Thread + { + Context ctx; + GetExternalFilesDir( Context ctx1 ) + { + ctx = ctx1; + } + @Override + public void run() + { + try + { + File f = ctx.getExternalFilesDir(null); + + f.mkdirs(); + + externalFilesDir = f.getAbsolutePath(); + Log.d(TAG, "getExternalFilesDir success"); + } + catch( Exception e ) + { + Log.e( TAG, e.toString(), e); + } + } + } public static String getExternalFilesDir( Context ctx ) { - File f = ctx.getExternalFilesDir( null ); - - if( f == null ) + if( externalFilesDir != null ) + return externalFilesDir; + try { - f = new File( getDefaultXashPath() ); + if( sdk >= 8 ) + { + Thread t = new GetExternalFilesDir(ctx); + t.start(); + t.join(2000); + } } - - f.mkdirs(); - - return f.getAbsolutePath(); + catch(Exception e) + { + Log.e( TAG, e.toString(), e); + externalFilesDir = getDefaultXashPath(); + } + if( externalFilesDir == null ) + externalFilesDir = getDefaultXashPath(); + return externalFilesDir; } public static boolean isLandscapeOrientation( Activity act )