private void copyResourcesToLocal() { String name, sFileName; InputStream content; R.raw a = new R.raw(); java.lang.reflect.Field[] t = R.raw.class.getFields(); Resources resources = getResources(); boolean succeed = true; for (int i = 0; i < t.length; i++) { try { name = resources.getText(t[i].getInt(a)).toString(); sFileName = name.substring(name.lastIndexOf('/') + 1, name.length()); content = getResources().openRawResource(t[i].getInt(a)); content.reset(); // perl project if (sFileName.endsWith(GlobalConstants.PERL_PROJECT_ZIP_NAME)) { succeed &= Utils.unzip(content, this.getFilesDir().getAbsolutePath() + "/", true); } // perl -> /data/data/com.android.perl/files/perl else if (sFileName.endsWith(GlobalConstants.PERL_ZIP_NAME)) { succeed &= Utils.unzip(content, this.getFilesDir().getAbsolutePath() + "/", true); FileUtils.chmod(new File(this.getFilesDir().getAbsolutePath() + "/perl/perl"), 0755); } // perl extras -> /sdcard/com.android.perl/perl/site-perl else if (sFileName.endsWith(GlobalConstants.PERL_EXTRAS_ZIP_NAME)) { Utils.createDirectoryOnExternalStorage(this.getPackageName() + "/" + "extras"); Utils.createDirectoryOnExternalStorage( this.getPackageName() + "/" + "extras" + "/" + "tmp"); succeed &= Utils.unzip( content, Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + this.getPackageName() + "/extras/", true); } } catch (Exception e) { Log.e(GlobalConstants.LOG_TAG, "Failed to copyResourcesToLocal", e); succeed = false; } } // end for all files in res/raw }
// Unpack and set file permission for python files located in res/raw based // off of Anthony Prieur & Daniel Oppenheim work // https://code.google.com/p/android-python27/ private void copyPythonToLocal() { String zipPath, zipName; InputStream content; R.raw a = new R.raw(); java.lang.reflect.Field[] t = R.raw.class.getFields(); Resources resources = getResources(); Log.i(Common.LOG_TAG, Common.LOG_INFO_PYTHON_UNZIP_STARTED); for (int i = 0; i < t.length; i++) { try { // Get path of zip to unpack zipPath = resources.getText(t[i].getInt(a)).toString(); // Extract the zipName from zipPath zipName = zipPath.substring(zipPath.lastIndexOf('/') + 1, zipPath.length()); content = getResources().openRawResource(t[i].getInt(a)); content.reset(); // Python_27 we unpack to -> // /data/data/com.sensibility_testbed/files/python if (zipName.endsWith(Common.PYTHON_ZIP_NAME)) { // This is the Python binary. It needs to live in /data/data/...., // as it can't be made executable on the SDcard due to VFAT. // Thus, we must not use seattleInstallDirectory for this. Utils.unzip(content, this.getFilesDir().getAbsolutePath() + "/", true); // set file permissions FileUtils.chmod( new File(this.getFilesDir().getAbsolutePath() + "/python/bin/python"), 0755); } // Python_extras_27 we unpack to -> // /sdcard/com.sensibility_testbed/extras/python else if (zipName.endsWith(Common.PYTHON_EXTRAS_ZIP_NAME)) { Utils.unzip(content, seattleInstallDirectory.getAbsolutePath() + "/extras/", true); } } catch (Exception e) { Log.e(Common.LOG_TAG, Common.LOG_EXCEPTION_PYTHON_UNZIPPING, e); } } Log.i(Common.LOG_TAG, Common.LOG_INFO_PYTHON_UNZIP_COMPLETED); }